From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45075 invoked by alias); 20 Apr 2019 21:22:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 45025 invoked by uid 89); 20 Apr 2019 21:22:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.1 spammy=executed, recording, *file, mainc X-HELO: mailsec111.isp.belgacom.be Received: from mailsec111.isp.belgacom.be (HELO mailsec111.isp.belgacom.be) (195.238.20.107) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 20 Apr 2019 21:22:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1555795327; x=1587331327; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tPs+v3my7AWuLP3J6IMkTRNm6Cj8zv41L8+cM2R/8+w=; b=r2MZdUwzn9JfG6mft8Ib+ms0R4KxL3ff21KWMwOfA7UuVLbIV9HBIqV0 Qb7UV3ofZdvLeS8Zy1Gck6jk1vjVIw==; Received: from unknown (HELO md.home) ([109.131.123.45]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 20 Apr 2019 23:21:59 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA 1/4] Add previous_saved_command_line to allow a command to repeat a previous command. Date: Sat, 20 Apr 2019 21:22:00 -0000 Message-Id: <20190420212153.30934-2-philippe.waroquiers@skynet.be> In-Reply-To: <20190420212153.30934-1-philippe.waroquiers@skynet.be> References: <20190420212153.30934-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-04/txt/msg00397.txt.bz2 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. gdb/ChangeLog 2019-04-20 Philippe Waroquiers * top.h (previous_saved_command_line): New declaration. * main.c (captured_main_1): Initialize previous_saved_command_line. * event-top.c (handle_line_of_input): Copy saved_command_line into previous_saved_command_line before replacing saved_command_line. * command.h (repeat_previous): New declaration. * top.c (previous_saved_command_line): New variable. (repeat_previous): New function. --- gdb/command.h | 1 + gdb/event-top.c | 3 ++- gdb/main.c | 1 + gdb/top.c | 29 ++++++++++++++++++++++++++++- gdb/top.h | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/gdb/command.h b/gdb/command.h index 4a239a7196..20a182db0c 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -449,6 +449,7 @@ extern void cmd_show_list (struct cmd_list_element *, int, const char *); extern void error_no_arg (const char *) ATTRIBUTE_NORETURN; extern void dont_repeat (void); +extern void repeat_previous (void); extern scoped_restore_tmpl prevent_dont_repeat (void); diff --git a/gdb/event-top.c b/gdb/event-top.c index cd54eb5a2c..6ff6203a0a 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -724,7 +724,8 @@ handle_line_of_input (struct buffer *cmd_line_buffer, /* Save into global buffer if appropriate. */ if (repeat) { - xfree (saved_command_line); + xfree (previous_saved_command_line); + previous_saved_command_line = saved_command_line; saved_command_line = xstrdup (cmd); return saved_command_line; } diff --git a/gdb/main.c b/gdb/main.c index e67efc7bcd..c6295ab500 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -500,6 +500,7 @@ captured_main_1 (struct captured_main_args *context) notice_open_fds (); saved_command_line = (char *) xstrdup (""); + previous_saved_command_line = (char *) xstrdup (""); #ifdef __MINGW32__ /* Ensure stderr is unbuffered. A Cygwin pty or pipe is implemented diff --git a/gdb/top.c b/gdb/top.c index 9a1c258d3f..b46330ff2c 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -134,8 +134,13 @@ show_confirm (struct ui_file *file, int from_tty, char *current_directory; /* The last command line executed on the console. Used for command - repetitions. */ + repetitions when the user enters an empty line. */ char *saved_command_line; +/* The previous last command line executed on the console. Used for command + repetitions when a command want 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; /* Nonzero if the current command is modified by "server ". This affects things like recording into the command history, commands @@ -711,6 +716,28 @@ dont_repeat (void) *saved_command_line = 0; } +/* Command call this if they want to repeat the previous command. + Such commands repeating 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 restore saved_command_line from the + previous_saved_command_line, so that the currently executing + command can repeat it by using saved_command_line. */ + +void +repeat_previous (void) +{ + char *tmp = previous_saved_command_line; + + /* 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. */ + previous_saved_command_line = saved_command_line; + saved_command_line = tmp; +} + /* Prevent dont_repeat from working, and return a cleanup that restores the previous state. */ diff --git a/gdb/top.h b/gdb/top.h index 025d9389d6..ff8cc10e55 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -218,6 +218,7 @@ extern void ui_unregister_input_event_handler (struct ui *ui); /* From top.c. */ extern char *saved_command_line; +extern char *previous_saved_command_line; extern int confirm; extern int inhibit_gdbinit; extern const char gdbinit[]; -- 2.20.1