This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA 06/08] multi-process support: when quitting, kill or detach all inferiors


This is a minimal patch to adjust one place in the common code to
multi-process.  Currently, when the user bails out, GDB will either kill or
detach the inferior, depending on how it got control if it in the first place.
This patch extends that behaviour to multiple inferiors, so things get cleaned
up on exit.

-- 
Pedro Alves
2008-09-12  Pedro Alves  <pedro@codesourcery.com>

	* top.c (any_thread_of, kill_or_detach): New functions.
	(quit_target): Iterator over all inferiors, killing or detaching
	accordingly.

---
 gdb/top.c |   46 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 8 deletions(-)

Index: src/gdb/top.c
===================================================================
--- src.orig/gdb/top.c	2008-09-11 23:53:05.000000000 +0100
+++ src/gdb/top.c	2008-09-12 00:03:31.000000000 +0100
@@ -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 (PIDGET (thread->ptid) == pid)
+    return 1;
 
-  if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
+  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);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]