* [PATCH] gdb: add "-a" option for inferior commands
@ 2016-12-29 20:55 Spencer Baugh
2016-12-29 21:38 ` Andreas Schwab
0 siblings, 1 reply; 7+ messages in thread
From: Spencer Baugh @ 2016-12-29 20:55 UTC (permalink / raw)
To: gdb-patches; +Cc: Spencer Baugh
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gdb: add "-a" option for inferior commands
2016-12-29 20:55 [PATCH] gdb: add "-a" option for inferior commands Spencer Baugh
@ 2016-12-29 21:38 ` Andreas Schwab
2016-12-29 22:01 ` sbaugh
2017-02-22 4:28 ` Spencer Baugh
0 siblings, 2 replies; 7+ messages in thread
From: Andreas Schwab @ 2016-12-29 21:38 UTC (permalink / raw)
To: Spencer Baugh; +Cc: gdb-patches
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.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gdb: add "-a" option for inferior commands
2016-12-29 21:38 ` Andreas Schwab
@ 2016-12-29 22:01 ` sbaugh
2017-02-22 4:28 ` Spencer Baugh
1 sibling, 0 replies; 7+ messages in thread
From: sbaugh @ 2016-12-29 22:01 UTC (permalink / raw)
To: gdb-patches
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gdb: add "-a" option for inferior commands
2016-12-29 21:38 ` Andreas Schwab
2016-12-29 22:01 ` sbaugh
@ 2017-02-22 4:28 ` Spencer Baugh
2017-02-22 9:24 ` Andreas Schwab
1 sibling, 1 reply; 7+ messages in thread
From: Spencer Baugh @ 2017-02-22 4:28 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gdb-patches
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gdb: add "-a" option for inferior commands
2017-02-22 4:28 ` Spencer Baugh
@ 2017-02-22 9:24 ` Andreas Schwab
2017-02-22 21:06 ` Spencer Baugh
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Schwab @ 2017-02-22 9:24 UTC (permalink / raw)
To: Spencer Baugh; +Cc: gdb-patches
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.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gdb: add "-a" option for inferior commands
2017-02-22 9:24 ` Andreas Schwab
@ 2017-02-22 21:06 ` Spencer Baugh
2017-02-22 21:11 ` Simon Marchi
0 siblings, 1 reply; 7+ messages in thread
From: Spencer Baugh @ 2017-02-22 21:06 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gdb-patches
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] gdb: add "-a" option for inferior commands
2017-02-22 21:06 ` Spencer Baugh
@ 2017-02-22 21:11 ` Simon Marchi
0 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2017-02-22 21:11 UTC (permalink / raw)
To: Spencer Baugh; +Cc: Andreas Schwab, gdb-patches
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-02-22 21:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-29 20:55 [PATCH] gdb: add "-a" option for inferior commands Spencer Baugh
2016-12-29 21:38 ` Andreas Schwab
2016-12-29 22:01 ` sbaugh
2017-02-22 4:28 ` Spencer Baugh
2017-02-22 9:24 ` Andreas Schwab
2017-02-22 21:06 ` Spencer Baugh
2017-02-22 21:11 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).