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]

[PATCH] gdb: add "-a" option for inferior commands


kill inferior, detach inferior, and remove-inferiors now all support a
"-a" option; when passed, they will operate on all inferiors instead of
the inferiors listed in their other arguments. (In the case of
remove-inferiors, the current inferior is excluded since it can't be
removed.)

gdb/ChangeLog entry:
	* inferior.c (remove_inferior_command): Support "-a" flag.
	(kill_inferior_command): Support "-a" flag.
	(detach_inferior_command): Support "-a" flag.
	The "-a" flag causes the command to operate on all inferiors.
gdb/doc/ChangeLog entry:
	* gdb.texinfo (Inferiors and Programs): Describe -a option for
	inferior commands.

---
 gdb/doc/gdb.texinfo | 23 +++++++++++---------
 gdb/inferior.c      | 62 ++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 67 insertions(+), 18 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 8e29eca..01be75a 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -2706,8 +2706,9 @@ Added inferior 2.
 You can now simply switch focus to inferior 2 and run it.
 
 @kindex remove-inferiors
-@item remove-inferiors @var{infno}@dots{}
-Removes the inferior or inferiors @var{infno}@dots{}.  It is not
+@item remove-inferiors [ -a ] @var{infno}@dots{}
+Removes the inferior or inferiors @var{infno}@dots{}.  With @code{-a},
+this will remove all inferiors besides the current inferior.  �It is not
 possible to remove an inferior that is running with this command.  For
 those, use the @code{kill} or @code{detach} command first.
 
@@ -2720,18 +2721,20 @@ using the @w{@code{kill inferiors}} command:
 
 @table @code
 @kindex detach inferiors @var{infno}@dots{}
-@item detach inferior @var{infno}@dots{}
+@item detach inferior [ -a ] @var{infno}@dots{}
 Detach from the inferior or inferiors identified by @value{GDBN}
-inferior number(s) @var{infno}@dots{}.  Note that the inferior's entry
-still stays on the list of inferiors shown by @code{info inferiors},
-but its Description will show @samp{<null>}.
+inferior number(s) @var{infno}@dots{}.  With @code{-a}, this will detach
+from all inferiors.  Note that the inferior's entry still stays on the
+list of inferiors shown by @code{info inferiors}, but its Description
+will show @samp{<null>}.
 
 @kindex kill inferiors @var{infno}@dots{}
-@item kill inferiors @var{infno}@dots{}
+@item kill inferiors [ -a ] @var{infno}@dots{}
 Kill the inferior or inferiors identified by @value{GDBN} inferior
-number(s) @var{infno}@dots{}.  Note that the inferior's entry still
-stays on the list of inferiors shown by @code{info inferiors}, but its
-Description will show @samp{<null>}.
+number(s) @var{infno}@dots{}. With @code{-a}, this will kill all
+inferiors.  Note that the inferior's entry still stays on the list of
+inferiors shown by @code{info inferiors}, but its Description will show
+@samp{<null>}.
 @end table
 
 After the successful completion of a command such as @code{detach},
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 32b6db2..6dadb62 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -653,7 +653,23 @@ detach_inferior_command (char *args, int from_tty)
   struct thread_info *tp;
 
   if (!args || !*args)
-    error (_("Requires argument (inferior id(s) to detach)"));
+    error (_("Requires argument (inferior id(s) to detach or -a)"));
+
+  if (startswith (args, "-a"))
+    {
+      struct inferior *inf;
+      ALL_INFERIORS(inf)
+	{
+	  int pid = inf->pid;
+	  if (pid == 0)
+	    continue;
+	  tp = any_thread_of_process (pid);
+	  switch_to_thread (tp->ptid);
+
+	  detach_command (NULL, from_tty);
+        }
+      return;
+    }
 
   number_or_range_parser parser (args);
   while (!parser.finished ())
@@ -692,7 +708,24 @@ kill_inferior_command (char *args, int from_tty)
   struct thread_info *tp;
 
   if (!args || !*args)
-    error (_("Requires argument (inferior id(s) to kill)"));
+    error (_("Requires argument (inferior id(s) to kill or -a)"));
+
+  if (startswith (args, "-a"))
+    {
+      struct inferior *inf;
+      ALL_INFERIORS(inf)
+	{
+	  int pid = inf->pid;
+	  if (pid == 0)
+	    continue;
+	  tp = any_thread_of_process (pid);
+	  switch_to_thread (tp->ptid);
+
+	  target_kill ();
+        }
+      bfd_cache_close_all ();
+      return;
+    }
 
   number_or_range_parser parser (args);
   while (!parser.finished ())
@@ -775,13 +808,26 @@ info_inferiors_command (char *args, int from_tty)
   print_inferior (current_uiout, args);
 }
 
-/* remove-inferior ID */
+/* remove-inferior [-a] ID */
 
 static void
 remove_inferior_command (char *args, int from_tty)
 {
   if (args == NULL || *args == '\0')
-    error (_("Requires an argument (inferior id(s) to remove)"));
+    error (_("Requires an argument (inferior id(s) to remove or -a)"));
+
+  if (startswith (args, "-a"))
+    {
+      struct inferior *inf, *cur, *infnext;
+      cur = current_inferior();
+      for (inf = inferior_list; inf; inf = infnext)
+	{
+	  infnext = inf->next;
+	  if (inf != cur)
+	    delete_inferior (inf);
+        }
+      return;
+    }
 
   number_or_range_parser parser (args);
   while (!parser.finished ())
@@ -1055,8 +1101,8 @@ as main program."));
   set_cmd_completer (c, filename_completer);
 
   add_com ("remove-inferiors", no_class, remove_inferior_command, _("\
-Remove inferior ID (or list of IDs).\n\
-Usage: remove-inferiors ID..."));
+Remove inferior ID (or list of IDs, or all inferiors with -a).\n\
+Usage: remove-inferiors [-a] ID..."));
 
   add_com ("clone-inferior", no_class, clone_inferior_command, _("\
 Clone inferior ID.\n\
@@ -1067,11 +1113,11 @@ adds 1 copy.  If ID is not specified, it is the current inferior\n\
 that is cloned."));
 
   add_cmd ("inferiors", class_run, detach_inferior_command, _("\
-Detach from inferior ID (or list of IDS)."),
+Detach from inferior ID (or list of IDS, or all inferiors with -a)."),
 	   &detachlist);
 
   add_cmd ("inferiors", class_run, kill_inferior_command, _("\
-Kill inferior ID (or list of IDs)."),
+Kill inferior ID (or list of IDs, or all inferiors with -a)."),
 	   &killlist);
 
   add_cmd ("inferior", class_run, inferior_command, _("\
-- 
2.10.0


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