aboutsummaryrefslogtreecommitdiff
path: root/gdb/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/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/top.c')
-rw-r--r--gdb/top.c74
1 files changed, 63 insertions, 11 deletions
diff --git a/gdb/top.c b/gdb/top.c
index 1e17ebe..518c5eb 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -134,8 +134,26 @@ show_confirm (struct ui_file *file, int from_tty,
char *current_directory;
/* The last command line executed on the console. Used for command
- repetitions. */
-char *saved_command_line;
+ repetitions when the user enters an empty line. */
+
+static char *saved_command_line;
+
+/* If not NULL, the arguments that should be passed if
+ saved_command_line is repeated. */
+
+static const char *repeat_arguments;
+
+/* The previous last command line executed on the console. Used for command
+ repetitions when a command wants to relaunch the previously launched
+ command. We need this as when a command is running, saved_command_line
+ already contains the line of the currently executing command. */
+
+char *previous_saved_command_line;
+
+/* If not NULL, the arguments that should be passed if the
+ previous_saved_command_line is repeated. */
+
+static const char *previous_repeat_arguments;
/* Nonzero if the current command is modified by "server ". This
affects things like recording into the command history, commands
@@ -521,11 +539,6 @@ 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
@@ -695,7 +708,7 @@ execute_command_to_string (const char *p, int from_tty,
static int suppress_dont_repeat = 0;
-/* Commands call this if they do not want to be repeated by null lines. */
+/* See command.h */
void
dont_repeat (void)
@@ -709,11 +722,27 @@ dont_repeat (void)
thing read from stdin in line and don't want to delete it. Null
lines won't repeat here in any case. */
if (ui->instream == ui->stdin_stream)
- *saved_command_line = 0;
+ {
+ *saved_command_line = 0;
+ repeat_arguments = NULL;
+ }
+}
+
+/* See command.h */
+
+void
+repeat_previous ()
+{
+ /* Do not repeat this command, as this command is a repeating command. */
+ dont_repeat ();
+
+ /* We cannot free saved_command_line, as this line is being executed,
+ so swap it with previous_saved_command_line. */
+ std::swap (previous_saved_command_line, saved_command_line);
+ std::swap (previous_repeat_arguments, repeat_arguments);
}
-/* Prevent dont_repeat from working, and return a cleanup that
- restores the previous state. */
+/* See command.h. */
scoped_restore_tmpl<int>
prevent_dont_repeat (void)
@@ -721,6 +750,26 @@ prevent_dont_repeat (void)
return make_scoped_restore (&suppress_dont_repeat, 1);
}
+/* See command.h. */
+
+char *
+get_saved_command_line ()
+{
+ return saved_command_line;
+}
+
+/* See command.h. */
+
+void
+save_command_line (const char *cmd)
+{
+ xfree (previous_saved_command_line);
+ previous_saved_command_line = saved_command_line;
+ previous_repeat_arguments = repeat_arguments;
+ saved_command_line = xstrdup (cmd);
+ repeat_arguments = NULL;
+}
+
/* Read a line from the stream "instream" without command line editing.
@@ -2179,6 +2228,9 @@ The second argument is the terminal the UI runs on.\n"), &cmdlist);
void
gdb_init (char *argv0)
{
+ saved_command_line = xstrdup ("");
+ previous_saved_command_line = xstrdup ("");
+
if (pre_init_ui_hook)
pre_init_ui_hook ();