From: Spencer Baugh <sbaugh@catern.com>
To: gdb-patches@sourceware.org
Cc: Spencer Baugh <sbaugh@catern.com>
Subject: [PATCH] gdb: add "-a" option for inferior commands
Date: Thu, 29 Dec 2016 20:55:00 -0000 [thread overview]
Message-ID: <20161229205458.319-1-sbaugh@catern.com> (raw)
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
next reply other threads:[~2016-12-29 20:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-29 20:55 Spencer Baugh [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161229205458.319-1-sbaugh@catern.com \
--to=sbaugh@catern.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox