From patchwork Thu Dec 29 20:54:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: sbaugh@catern.com X-Patchwork-Id: 18723 Received: (qmail 73521 invoked by alias); 29 Dec 2016 20:55:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 73482 invoked by uid 89); 29 Dec 2016 20:55:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=It, 2100, dots, @dots X-HELO: mail.catern.com Received: from catern.com (HELO mail.catern.com) (104.131.201.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Dec 2016 20:55:11 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.catern.com (Postfix) with ESMTPSA id 6746652972; Thu, 29 Dec 2016 20:55:09 +0000 (UTC) From: Spencer Baugh To: gdb-patches@sourceware.org Cc: Spencer Baugh Subject: [PATCH] gdb: add "-a" option for inferior commands Date: Thu, 29 Dec 2016 15:54:58 -0500 Message-Id: <20161229205458.319-1-sbaugh@catern.com> MIME-Version: 1.0 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{}. +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{}. @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{}. +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{}. @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, _("\