From patchwork Mon Oct 16 03:07:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23591 Received: (qmail 104942 invoked by alias); 16 Oct 2017 03:07:18 -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 104931 invoked by uid 89); 16 Oct 2017 03:07:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Oct 2017 03:07:15 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id 959EA140433 for ; Sun, 15 Oct 2017 21:07:14 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id N37B1w00o2f2jeq0137Etu; Sun, 15 Oct 2017 21:07:14 -0600 X-Authority-Analysis: v=2.2 cv=H76r+6Qi c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=02M-m0pO-4AA:10 a=zstS-IiYAAAA:8 a=LPFi3g2-ST8rt2O30HEA:9 a=Fr4ObGv3v7058q_5:21 a=fy5nQYaORIPh2QkQ:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 184-96-33-178.hlrn.qwest.net ([184.96.33.178]:43440 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1e3vkF-003lUi-Bw; Sun, 15 Oct 2017 21:07:11 -0600 From: Tom Tromey To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA 7/8] Add truncate_repeat_arguments function References: <20171013205950.22943-1-tom@tromey.com> <20171013205950.22943-8-tom@tromey.com> <87vajitjuv.fsf@tromey.com> Date: Sun, 15 Oct 2017 21:07:07 -0600 In-Reply-To: <87vajitjuv.fsf@tromey.com> (Tom Tromey's message of "Fri, 13 Oct 2017 22:48:56 -0600") Message-ID: <87h8uzu6xw.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (gnu/linux) MIME-Version: 1.0 X-BWhitelist: no X-Exim-ID: 1e3vkF-003lUi-Bw X-Source-Sender: 184-96-33-178.hlrn.qwest.net (bapiya) [184.96.33.178]:43440 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes >>>>> "Tom" == Tom Tromey writes: Tom> I'm rewriting this patch to allow those uses as well... so you might as Tom> well skip this patch if you're reviewing. However, I think the other Tom> patches in the series are still ok to read. Here is a new version of this patch, that addresses the additional commands I ran across. Tom commit 323b5cdc6429d865ddf091913c8b78bb521e20f3 Author: Tom Tromey Date: Thu Oct 12 08:27:21 2017 -0600 Add set_repeat_arguments function The "x", "list", and "show commands" commands have special repetition behavior: repeating the command doesn't re-run it with the same arguments This is currently implemented by modifying the passed-in argument; but that won't work properly with const arguments (and seems pretty obscure besides). This patch adds a new "set_repeat_arguments" function and changes the relevant places to call it. ChangeLog 2017-10-15 Tom Tromey * printcmd.c (x_command): Call set_repeat_arguments. * cli/cli-cmds.c (list_command): Call set_repeat_arguments. * top.c (repeat_arguments): New global. (set_repeat_arguments): New function. (execute_command): Handle repeat_arguments. (show_commands): Calls set_repeat_arguments. * command.h (set_repeat_arguments): Declare. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 91f30ae683..15e8984544 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2017-10-15 Tom Tromey + * printcmd.c (x_command): Call set_repeat_arguments. + * cli/cli-cmds.c (list_command): Call set_repeat_arguments. + * top.c (repeat_arguments): New global. + (set_repeat_arguments): New function. + (execute_command): Handle repeat_arguments. + (show_commands): Calls set_repeat_arguments. + * command.h (set_repeat_arguments): Declare. + +2017-10-15 Tom Tromey + * stack.c (backtrace_command): Use std::string. (backtrace_command_1): Make "count_exp" const. diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index a1c308a38d..a8edb1341f 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1082,7 +1082,7 @@ list_command (char *arg, int from_tty) turn it into the no-arg variant. */ if (from_tty) - *arg = 0; + set_repeat_arguments (""); if (dummy_beg && sal_end.symtab == 0) error (_("No default source file yet. Do \"help list\".")); diff --git a/gdb/command.h b/gdb/command.h index a99544563c..63c76589c8 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -445,6 +445,11 @@ extern void dont_repeat (void); extern scoped_restore_tmpl prevent_dont_repeat (void); +/* Set the arguments that will be passed if the current command is + repeated. Note that the passed-in string must be a constant. */ + +extern void set_repeat_arguments (const char *args); + /* Used to mark commands that don't do anything. If we just leave the function field NULL, the command is interpreted as a help topic, or as a class of commands. */ diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 77a05e5d9f..343c9049c5 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1636,7 +1636,7 @@ x_command (char *exp, int from_tty) repeated with Newline. But don't clobber a user-defined command's definition. */ if (from_tty) - *exp = 0; + set_repeat_arguments (""); val = evaluate_expression (expr.get ()); if (TYPE_IS_REFERENCE (value_type (val))) val = coerce_ref (val); diff --git a/gdb/top.c b/gdb/top.c index 3b3bbee4ac..5a6f99995a 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -528,6 +528,19 @@ maybe_wait_sync_command_done (int was_sync) wait_sync_command_done (); } +/* If not NULL, the arguments that should be passed if the current + command is repeated. */ + +static const char *repeat_arguments; + +/* See command.h. */ + +void +set_repeat_arguments (const char *args) +{ + repeat_arguments = args; +} + /* Execute the line P as a command, in the current user context. Pass FROM_TTY as second argument to the defining function. */ @@ -571,6 +584,10 @@ execute_command (char *p, int from_tty) c = lookup_cmd (&cmd, cmdlist, "", 0, 1); p = (char *) cmd; + scoped_restore save_repeat_args + = make_scoped_restore (&repeat_arguments, nullptr); + char *args_pointer = p; + /* Pass null arg rather than an empty one. */ arg = *p ? p : 0; @@ -619,6 +636,11 @@ execute_command (char *p, int from_tty) /* If this command has been post-hooked, run the hook last. */ execute_cmd_post_hook (c); + if (repeat_arguments != NULL) + { + gdb_assert (strlen (args_pointer) >= strlen (repeat_arguments)); + strcpy (args_pointer, repeat_arguments); + } } check_frame_language_change (); @@ -1675,7 +1697,7 @@ dont_repeat_command (char *ignored, int from_tty) /* Number of commands to print in each call to show_commands. */ #define Hist_print 10 void -show_commands (char *args, int from_tty) +show_commands (const char *args, int from_tty) { /* Index for history commands. Relative to history_base. */ int offset; @@ -1729,10 +1751,7 @@ show_commands (char *args, int from_tty) "show commands +" does. This is unnecessary if arg is null, because "show commands +" is not useful after "show commands". */ if (from_tty && args) - { - args[0] = '+'; - args[1] = '\0'; - } + set_repeat_arguments ("+"); } /* Update the size of our command history file to HISTORY_SIZE. diff --git a/gdb/value.c b/gdb/value.c index 7d0966c8fe..6af9458f43 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -2005,10 +2005,7 @@ show_values (char *num_exp, int from_tty) "show values +". If num_exp is null, this is unnecessary, since "show values +" is not useful after "show values". */ if (from_tty && num_exp) - { - num_exp[0] = '+'; - num_exp[1] = '\0'; - } + set_repeat_arguments ("+"); } enum internalvar_kind