diff mbox

gdb: add "-a" option for inferior commands

Message ID 20161229205458.319-1-sbaugh@catern.com
State New
Headers show

Commit Message

sbaugh@catern.com Dec. 29, 2016, 8:54 p.m. UTC
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(-)

Comments

Andreas Schwab Dec. 29, 2016, 9:37 p.m. UTC | #1
On Dez 29 2016, Spencer Baugh <sbaugh@catern.com> wrote:

> @@ -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..."));

What is the meaning of ID if -a is present?

Andreas.
sbaugh@catern.com Dec. 29, 2016, 10 p.m. UTC | #2
Andreas Schwab <schwab@linux-m68k.org> writes:
> What is the meaning of ID if -a is present?

If -a is present, any IDs are ignored.
sbaugh@catern.com Feb. 22, 2017, 4:28 a.m. UTC | #3
Andreas Schwab <schwab@linux-m68k.org> writes:
> On Dez 29 2016, Spencer Baugh <sbaugh@catern.com> wrote:
>
>> @@ -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..."));
>
> What is the meaning of ID if -a is present?

ID is ignored if -a is present.
Andreas Schwab Feb. 22, 2017, 9:24 a.m. UTC | #4
On Feb 21 2017, Spencer Baugh <sbaugh@catern.com> wrote:

> Andreas Schwab <schwab@linux-m68k.org> writes:
>> On Dez 29 2016, Spencer Baugh <sbaugh@catern.com> wrote:
>>
>>> @@ -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..."));
>>
>> What is the meaning of ID if -a is present?
>
> ID is ignored if -a is present.

Shouldn't ID be optional then?

Andreas.
sbaugh@catern.com Feb. 22, 2017, 9:06 p.m. UTC | #5
Andreas Schwab <schwab@linux-m68k.org> writes:
> On Feb 21 2017, Spencer Baugh <sbaugh@catern.com> wrote:
>
>> Andreas Schwab <schwab@linux-m68k.org> writes:
>>> On Dez 29 2016, Spencer Baugh <sbaugh@catern.com> wrote:
>>>
>>>> @@ -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..."));
>>>
>>> What is the meaning of ID if -a is present?
>>
>> ID is ignored if -a is present.
>
> Shouldn't ID be optional then?

Like this then?

Usage: remove-inferiors [-a] [ID...]

I was just concerned that that doesn't indicate that one of them must be
present. Not sure what the convention is to indicate that.
Simon Marchi Feb. 22, 2017, 9:11 p.m. UTC | #6
On 2017-02-22 16:06, Spencer Baugh wrote:
> Andreas Schwab <schwab@linux-m68k.org> writes:
>> On Feb 21 2017, Spencer Baugh <sbaugh@catern.com> wrote:
>> 
>>> Andreas Schwab <schwab@linux-m68k.org> writes:
>>>> On Dez 29 2016, Spencer Baugh <sbaugh@catern.com> wrote:
>>>> 
>>>>> @@ -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..."));
>>>> 
>>>> What is the meaning of ID if -a is present?
>>> 
>>> ID is ignored if -a is present.
>> 
>> Shouldn't ID be optional then?
> 
> Like this then?
> 
> Usage: remove-inferiors [-a] [ID...]
> 
> I was just concerned that that doesn't indicate that one of them must 
> be
> present. Not sure what the convention is to indicate that.

An option would be to have multiple lines.  Not sure how to format it, 
but something like:

   (gdb) help remove-inferiors
   Remove inferior ID (or list of IDS)
   Usage: remove-inferiors ID...

   Remove all inferiors
   Usage: remove-inferiors -a

It would be nice to decide on a standard format for help messages, kind 
of like man pages always have the same format.

Simon
diff mbox

Patch

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, _("\