diff options
author | Tom Tromey <tom@tromey.com> | 2017-10-12 08:27:21 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-11-07 13:59:09 -0700 |
commit | 85c4be7c83b80acf647e6ffcaed0f0cdbcb8c3eb (patch) | |
tree | e5beb6ee1907869e987937ee92538274d0fa560d /gdb/top.c | |
parent | 022643b4456ee13752b0f3a8411238ab8c53bf6d (diff) | |
download | binutils-85c4be7c83b80acf647e6ffcaed0f0cdbcb8c3eb.zip binutils-85c4be7c83b80acf647e6ffcaed0f0cdbcb8c3eb.tar.gz binutils-85c4be7c83b80acf647e6ffcaed0f0cdbcb8c3eb.tar.bz2 |
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.
gdb/ChangeLog
2017-11-07 Tom Tromey <tom@tromey.com>
* 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.
Diffstat (limited to 'gdb/top.c')
-rw-r--r-- | gdb/top.c | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -522,6 +522,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. */ @@ -564,6 +577,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; @@ -612,6 +629,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 (); @@ -1667,7 +1689,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; @@ -1721,10 +1743,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. |