summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Prus <vladimir@codesourcery.com>2008-11-17 16:37:32 +0000
committerVladimir Prus <vladimir@codesourcery.com>2008-11-17 16:37:32 +0000
commit3b2206da375fca94003d4db0f72e1822a4e1f28e (patch)
treedd5c9bffe44148e44f99aeb038842ce4cfd80c90
parent33869c85b4b6321b1095b662a79fec48fd6fa34a (diff)
downloadgdb-3b2206da375fca94003d4db0f72e1822a4e1f28e.tar.gz
Implement '-target-detach pid'.
* infcmd.c (detach_command): Make nonstatic. * inferior.h (detach_command): Declare. * mi/mi-cmds.c (mi_cmds): Don't route -target-detach via CLI. * mi/mi-cmds.h (mi_cmd_target_detach): Declare. * mi/mi-main.c (find_thread_of_process, mi_cmd_target_detach): New.
-rw-r--r--gdb/ChangeLog10
-rw-r--r--gdb/infcmd.c4
-rw-r--r--gdb/inferior.h2
-rw-r--r--gdb/mi/mi-cmds.c2
-rw-r--r--gdb/mi/mi-cmds.h1
-rw-r--r--gdb/mi/mi-main.c36
6 files changed, 51 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b32b96ceeea..64e8eeeda50 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
2008-11-17 Vladimir Prus <vladimir@codesourcery.com>
+ Implement '-target-detach pid'.
+
+ * infcmd.c (detach_command): Make nonstatic.
+ * inferior.h (detach_command): Declare.
+ * mi/mi-cmds.c (mi_cmds): Don't route -target-detach via CLI.
+ * mi/mi-cmds.h (mi_cmd_target_detach): Declare.
+ * mi/mi-main.c (find_thread_of_process, mi_cmd_target_detach): New.
+
+2008-11-17 Vladimir Prus <vladimir@codesourcery.com>
+
Include group-id in thread-created notification.
* mi/mi-interp.c (mi_new_thread, mi_thread_exit): Include
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index b3af31fc171..810b3b706fc 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -86,8 +86,6 @@ static void unset_command (char *, int);
static void float_info (char *, int);
-static void detach_command (char *, int);
-
static void disconnect_command (char *, int);
static void unset_environment_command (char *, int);
@@ -2344,7 +2342,7 @@ attach_command (char *args, int from_tty)
* started via the normal ptrace (PTRACE_TRACEME).
*/
-static void
+void
detach_command (char *args, int from_tty)
{
dont_repeat (); /* Not for the faint of heart. */
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 1be6cc5c11a..f004d44ecf4 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -269,6 +269,8 @@ extern void interrupt_target_command (char *args, int from_tty);
extern void interrupt_target_1 (int all_threads);
+extern void detach_command (char *, int);
+
/* Address at which inferior stopped. */
extern CORE_ADDR stop_pc;
diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c
index d38de35da40..51c720e22dd 100644
--- a/gdb/mi/mi-cmds.c
+++ b/gdb/mi/mi-cmds.c
@@ -121,7 +121,7 @@ struct mi_cmd mi_cmds[] =
{ "symbol-type", { NULL, 0 }, NULL },
{ "target-attach", { "attach", 1 }, NULL },
{ "target-compare-sections", { NULL, 0 }, NULL },
- { "target-detach", { "detach", 0 }, 0 },
+ { "target-detach", { NULL, 0 }, mi_cmd_target_detach },
{ "target-disconnect", { "disconnect", 0 }, 0 },
{ "target-download", { "load", 1 }, NULL},
{ "target-exec-status", { NULL, 0 }, NULL },
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index a9bb1e0978b..a399b9e141c 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -75,6 +75,7 @@ extern mi_cmd_argv_ftype mi_cmd_stack_list_frames;
extern mi_cmd_argv_ftype mi_cmd_stack_list_locals;
extern mi_cmd_argv_ftype mi_cmd_stack_select_frame;
extern mi_cmd_argv_ftype mi_cmd_symbol_list_lines;
+extern mi_cmd_argv_ftype mi_cmd_target_detach;
extern mi_cmd_argv_ftype mi_cmd_target_file_get;
extern mi_cmd_argv_ftype mi_cmd_target_file_put;
extern mi_cmd_argv_ftype mi_cmd_target_file_delete;
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index f739bbb8533..ad4ed0c2680 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -199,6 +199,42 @@ mi_cmd_exec_interrupt (char *command, char **argv, int argc)
error ("Usage: -exec-interrupt [--all]");
}
+static int
+find_thread_of_process (struct thread_info *ti, void *p)
+{
+ int pid = *(int *)p;
+ if (PIDGET (ti->ptid) == pid && !is_exited (ti->ptid))
+ return 1;
+
+ return 0;
+}
+
+void
+mi_cmd_target_detach (char *command, char **argv, int argc)
+{
+ if (argc != 0 && argc != 1)
+ error ("Usage: -target-detach [thread-group]");
+
+ if (argc == 1)
+ {
+ struct thread_info *tp;
+ char *end = argv[0];
+ int pid = strtol (argv[0], &end, 10);
+ if (*end != '\0')
+ error (_("Cannot parse thread group id '%s'"), argv[0]);
+
+ /* Pick any thread in the desired process. Current
+ target_detach deteches from the parent of inferior_ptid. */
+ tp = iterate_over_threads (find_thread_of_process, &pid);
+ if (!tp)
+ error (_("Thread group is empty"));
+
+ switch_to_thread (tp->ptid);
+ }
+
+ detach_command (NULL, 0);
+}
+
void
mi_cmd_thread_select (char *command, char **argv, int argc)
{