From bd16eda92db4feede9ad58421672a691b850e418 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 7 Nov 2017 12:09:06 +0000 Subject: saved_command_line --- gdb/event-top.c | 18 +++++++++--------- gdb/main.c | 2 -- gdb/top.c | 13 +++++++------ gdb/top.h | 5 ++++- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 7377189..1e84fdf 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -634,8 +634,8 @@ command_line_append_input_line (struct buffer *cmd_line_buffer, 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. + copied into the 'ui->saved_command_line' var 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. @@ -671,9 +671,9 @@ handle_line_of_input (struct buffer *cmd_line_buffer, #define SERVER_COMMAND_PREFIX "server " if (startswith (cmd, SERVER_COMMAND_PREFIX)) { - /* Note that we don't set `saved_command_line'. Between this - and the check in dont_repeat, this insures that repeating - will still do the right thing. */ + /* Note that we don't set `ui->saved_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 +713,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 ui->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 +728,9 @@ 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; + xfree (ui->saved_command_line); + ui->saved_command_line = xstrdup (cmd); + return ui->saved_command_line; } else return cmd; diff --git a/gdb/main.c b/gdb/main.c index 835ae24..8fae552 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -522,8 +522,6 @@ captured_main_1 (struct captured_main_args *context) notice_open_fds (); save_original_signals_state (); - saved_command_line = (char *) xstrdup (""); - #ifdef __MINGW32__ /* Ensure stderr is unbuffered. A Cygwin pty or pipe is implemented as a Windows pipe, and Windows buffers on pipes. */ diff --git a/gdb/top.c b/gdb/top.c index f006c66..a7d7062 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -132,10 +132,6 @@ 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; - /* Nonzero if the current command is modified by "server ". This affects things like recording into the command history, commands repeating on RETURN, etc. This is so a user interface (emacs, GUI, @@ -251,6 +247,7 @@ static int highest_ui_num; ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_) : next (nullptr), num (++highest_ui_num), + saved_command_line (xstrdup ("")), call_readline (nullptr), input_handler (nullptr), command_editing (0), @@ -675,7 +672,10 @@ 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; + { + xfree (ui->saved_command_line); + ui->saved_command_line = NULL; + } } /* Prevent dont_repeat from working, and return a cleanup that @@ -1659,7 +1659,8 @@ dont_repeat_command (char *ignored, int from_tty) { /* Can't call dont_repeat here because we're not necessarily reading from stdin. */ - *saved_command_line = 0; + xfree (current_ui->saved_command_line); + current_ui->saved_command_line = NULL; } /* Functions to manipulate command line editing control variables. */ diff --git a/gdb/top.h b/gdb/top.h index ab65ddb..d0f0e1f 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -71,6 +71,10 @@ struct ui input until we have a whole command line. */ struct buffer line_buffer; + /* The last command line executed on the console. Used for command + repetitions. */ + char *saved_command_line; + /* The callback used by the event loop whenever an event is detected on the UI's input file descriptor. This function incrementally builds a buffer where it accumulates the line read up to the @@ -217,7 +221,6 @@ extern void ui_register_input_event_handler (struct ui *ui); extern void ui_unregister_input_event_handler (struct ui *ui); /* From top.c. */ -extern char *saved_command_line; extern int confirm; extern int inhibit_gdbinit; extern const char gdbinit[]; -- cgit v1.1