+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.
+
2019-05-30 Tom Tromey <tromey@adacore.com>
* gdbtypes.h (struct range_bounds) <flag_upper_bound_is_count>:
extern void error_no_arg (const char *) ATTRIBUTE_NORETURN;
-extern void dont_repeat (void);
+
+/* Command line saving and repetition.
+ Each input line executed is saved to possibly be repeated either
+ when the user types an empty line, or be repeated by a command
+ that wants to repeat the previously executed command. The below
+ functions control command repetition. */
+
+/* Commands call dont_repeat if they do not want to be repeated by null
+ lines or by repeat_previous (). */
+
+extern void dont_repeat ();
+
+/* Commands call repeat_previous if they want to repeat the previous command.
+ Such commands that repeat the previous command must indicate
+ to not repeat themselves, to avoid recursive repeat.
+ repeat_previous will mark the current command as not repeating,
+ and will ensure get_saved_command_line returns the previous command,
+ so that the currently executing command can repeat it. */
+
+extern void repeat_previous ();
+
+/* Prevent dont_repeat from working, and return a cleanup that
+ restores the previous state. */
extern scoped_restore_tmpl<int> prevent_dont_repeat (void);
extern void set_repeat_arguments (const char *args);
+/* Returns the saved command line to repeat.
+ When a command is being executed, this is the currently executing
+ command line, unless the currently executing command has called
+ repeat_previous (): in this case, get_saved_command_line returns
+ the previously saved command line. */
+
+extern char *get_saved_command_line ();
+
+/* Takes a copy of CMD, for possible repetition. */
+
+extern void save_command_line (const char *cmd);
+
/* 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. */
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 *
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);
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
/* 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;
notice_open_fds ();
- 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. */
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
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
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)
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)
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;
+}
+
\f
/* Read a line from the stream "instream" without command line editing.
void
gdb_init (char *argv0)
{
+ saved_command_line = xstrdup ("");
+ previous_saved_command_line = xstrdup ("");
+
if (pre_init_ui_hook)
pre_init_ui_hook ();
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[];