aboutsummaryrefslogtreecommitdiff
path: root/gdb/event-top.c
diff options
context:
space:
mode:
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-04-20 14:02:29 +0200
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-05-31 17:10:08 +0200
commit68bb5386b84af4031175bf186269eb6b54b8611d (patch)
treeb3b9b003d4b9f692f2437a7afb86cd4f7efd1869 /gdb/event-top.c
parenta0486bac41d6ce47f27795a5abbca5cc53ddba00 (diff)
downloadgdb-68bb5386b84af4031175bf186269eb6b54b8611d.zip
gdb-68bb5386b84af4031175bf186269eb6b54b8611d.tar.gz
gdb-68bb5386b84af4031175bf186269eb6b54b8611d.tar.bz2
Add previous_saved_command_line to allow a command to repeat a previous command.
Currently, a previous command can be repeated when the user types an empty line. This is implemented in handle_line_of_input by returning saved_command_line in case an empty line has been input. If we want a command to repeat the previous command, we need to save the previous saved_command_line, as when a command runs, the saved_command_line already contains the current command line of the command being executed. As suggested by Tom, the previous_saved_command_line is made static. At the same time, saved_command_line is also made static. The support functions/variables for the repeat command logic are now all located inside top.c. gdb/ChangeLog 2019-05-31 Philippe Waroquiers <philippe.waroquiers@skynet.be> * top.h (saved_command_line): Remove declaration. * top.c (previous_saved_command_line, previous_repeat_arguments): New variables. (saved_command_line): Make static, define together with other 'repeat variables'. (dont_repeat): Clear repeat_arguments. (repeat_previous, get_saved_command_line, save_command_line): New functions. (gdb_init): Initialize saved_command_line and previous_saved_command_line. * main.c (captured_main_1): Remove saved_command_line initialization. * event-top.c (handle_line_of_input): Update to use the new 'repeat' related functions instead of direct access to saved_command_line. * command.h (repeat_previous, get_saved_command_line, save_command_line): New declarations. (dont_repeat): Add comment.
Diffstat (limited to 'gdb/event-top.c')
-rw-r--r--gdb/event-top.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 93b7d2d..3facb38 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -634,11 +634,10 @@ command_line_append_input_line (struct buffer *cmd_line_buffer, const char *rl)
If REPEAT, handle command repetitions:
- If the input command line is NOT empty, the command returned is
- copied into the global 'saved_command_line' var so that it can
- be repeated later.
+ saved using save_command_line () so that it can be repeated later.
- - OTOH, if the input command line IS empty, return the previously
- saved command instead of the empty input line.
+ - OTOH, if the input command line IS empty, return the saved
+ command instead of the empty input line.
*/
char *
@@ -673,7 +672,7 @@ handle_line_of_input (struct buffer *cmd_line_buffer,
server_command = startswith (cmd, SERVER_COMMAND_PREFIX);
if (server_command)
{
- /* Note that we don't set `saved_command_line'. Between this
+ /* Note that we don't call `save_command_line'. Between this
and the check in dont_repeat, this insures that repeating
will still do the right thing. */
return cmd + strlen (SERVER_COMMAND_PREFIX);
@@ -713,7 +712,7 @@ handle_line_of_input (struct buffer *cmd_line_buffer,
for (p1 = cmd; *p1 == ' ' || *p1 == '\t'; p1++)
;
if (repeat && *p1 == '\0')
- return saved_command_line;
+ return get_saved_command_line ();
/* Add command to history if appropriate. Note: lines consisting
solely of comments are also added to the command history. This
@@ -728,9 +727,8 @@ handle_line_of_input (struct buffer *cmd_line_buffer,
/* Save into global buffer if appropriate. */
if (repeat)
{
- xfree (saved_command_line);
- saved_command_line = xstrdup (cmd);
- return saved_command_line;
+ save_command_line (cmd);
+ return get_saved_command_line ();
}
else
return cmd;