aboutsummaryrefslogtreecommitdiff
path: root/gdb/top.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2008-09-22 15:24:51 +0000
committerPedro Alves <palves@redhat.com>2008-09-22 15:24:51 +0000
commit54a012c9c70e6016dc5d0a0e227264f12138c57e (patch)
tree7a124271ab2b5832826e753acbd78ee85ea757f3 /gdb/top.c
parent181e7f9393edb01de72d25e208a6ef4f069fb36f (diff)
downloadgdb-54a012c9c70e6016dc5d0a0e227264f12138c57e.zip
gdb-54a012c9c70e6016dc5d0a0e227264f12138c57e.tar.gz
gdb-54a012c9c70e6016dc5d0a0e227264f12138c57e.tar.bz2
* top.c (any_thread_of, kill_or_detach): New functions.
(quit_target): Iterate over all inferiors, killing or detaching accordingly.
Diffstat (limited to 'gdb/top.c')
-rw-r--r--gdb/top.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/gdb/top.c b/gdb/top.c
index 76e8cb8..d0ba466 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1204,28 +1204,58 @@ quit_confirm (void)
return 1;
}
-/* Helper routine for quit_force that requires error handling. */
-
struct qt_args
{
char *args;
int from_tty;
};
+/* Callback for iterate_over_threads. Finds any thread of inferior
+ given by ARG (really an int*). */
+
static int
-quit_target (void *arg)
+any_thread_of (struct thread_info *thread, void *arg)
{
- struct qt_args *qt = (struct qt_args *)arg;
+ int pid = * (int *)arg;
- if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
+ if (PIDGET (thread->ptid) == pid)
+ return 1;
+
+ return 0;
+}
+
+/* Callback for iterate_over_inferiors. Kills or detaches the given
+ inferior, depending on how we originally gained control of it. */
+
+static int
+kill_or_detach (struct inferior *inf, void *args)
+{
+ struct qt_args *qt = args;
+ struct thread_info *thread;
+
+ thread = iterate_over_threads (any_thread_of, &inf->pid);
+ if (thread)
{
- struct inferior *inf = current_inferior ();
+ switch_to_thread (thread->ptid);
if (inf->attach_flag)
- target_detach (qt->args, qt->from_tty);
+ target_detach (qt->args, qt->from_tty);
else
- target_kill ();
+ target_kill ();
}
+ return 0;
+}
+
+/* Helper routine for quit_force that requires error handling. */
+
+static int
+quit_target (void *arg)
+{
+ struct qt_args *qt = (struct qt_args *)arg;
+
+ /* Kill or detach all inferiors. */
+ iterate_over_inferiors (kill_or_detach, qt);
+
/* Give all pushed targets a chance to do minimal cleanup, and pop
them all out. */
pop_all_targets (1);