Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Philippe Waroquiers <philippe.waroquiers@skynet.be>,
	gdb-patches@sourceware.org
Subject: Re: [RFAv3 1/6] Add previous_saved_command_line to allow a command to repeat a previous command.
Date: Mon, 27 May 2019 17:29:00 -0000	[thread overview]
Message-ID: <80035dbe-4682-eb51-9db2-c774e5f87a7a@redhat.com> (raw)
In-Reply-To: <20190504161753.15530-2-philippe.waroquiers@skynet.be>

On 5/4/19 5:17 PM, Philippe Waroquiers wrote:
> 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-04  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.
> ---
>  gdb/command.h   | 36 ++++++++++++++++++++++++-
>  gdb/event-top.c | 16 +++++------
>  gdb/main.c      |  2 --
>  gdb/top.c       | 70 +++++++++++++++++++++++++++++++++++++++++--------
>  gdb/top.h       |  1 -
>  5 files changed, 101 insertions(+), 24 deletions(-)
> 
> diff --git a/gdb/command.h b/gdb/command.h
> index 4a239a7196..ea3a58f81c 100644
> --- a/gdb/command.h
> +++ b/gdb/command.h
> @@ -448,7 +448,29 @@ 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);
> +
> +/* Command line saving and repetition.
> +   Each input line executed is saved for possibly be repeated either

s/saved for ... be/saved to ... be/

> +   when the user types an empty line, or be repeated by a command
> +   that wants to repeat the previously executed command.  The below
> +   functions are controlling command repetition.  */

s/are controlling/control/

> +
> +/* Commands call dont_repeat if they do not want to be repeated by null
> +   lines or by repeat_previous ().  */
> +
> +extern void dont_repeat ();
> +
> +/* Command call repeat_previous if they want to repeat the previous command.

s/Command call/Commands call/

> +   Such commands repeating the previous command must indicate

s/Such commands repeating/Such commands that repeat/

> +   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);
>  
> @@ -457,6 +479,18 @@ 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.  */
> diff --git a/gdb/event-top.c b/gdb/event-top.c
> index 3ccf136ff1..b64b7462c7 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;
> diff --git a/gdb/main.c b/gdb/main.c
> index 35df1e497f..ef9bfe8fc6 100644
> --- a/gdb/main.c
> +++ b/gdb/main.c
> @@ -499,8 +499,6 @@ captured_main_1 (struct captured_main_args *context)
>  
>    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.  */
> diff --git a/gdb/top.c b/gdb/top.c
> index bacd684dba..70f685ffad 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 want to relaunch the previously launched

s/a command want/a command wants/

> +   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,22 @@ prevent_dont_repeat (void)
>    return make_scoped_restore (&suppress_dont_repeat, 1);
>  }
>  
> +char *
> +get_saved_command_line ()

Add usual /* See foo.h  */ comment.


> +{
> +  return saved_command_line;
> +}
> +
> +void
> +save_command_line (const char *cmd)

Ditto.

> +{
> +  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.
>  
> @@ -2179,6 +2224,9 @@ The second argument is the terminal the UI runs on.\n"), &cmdlist);
>  void
>  gdb_init (char *argv0)
>  {
> +  saved_command_line = (char *) xstrdup ("");
> +  previous_saved_command_line = (char *) xstrdup ("");

Drop the unnecessary casts.

> +
>    if (pre_init_ui_hook)
>      pre_init_ui_hook ();
>  
> diff --git a/gdb/top.h b/gdb/top.h
> index 025d9389d6..aab03c13d6 100644
> --- a/gdb/top.h
> +++ b/gdb/top.h
> @@ -217,7 +217,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[];
> 
Thanks,
Pedro Alves


  reply	other threads:[~2019-05-27 17:29 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-04 16:18 [RFAv3 0/6] Implement | (pipe) command Philippe Waroquiers
2019-05-04 16:18 ` [RFAv3 4/6] " Philippe Waroquiers
2019-05-27 17:48   ` Pedro Alves
2019-05-27 17:55     ` Pedro Alves
2019-05-04 16:18 ` [RFAv3 6/6] NEWS and documentation for " Philippe Waroquiers
2019-05-04 16:26   ` Eli Zaretskii
2019-05-04 16:33     ` Eli Zaretskii
2019-05-27 17:51   ` Pedro Alves
2019-05-04 16:18 ` [RFAv3 2/6] Improve process exit status macros on MinGW Philippe Waroquiers
2019-05-27 17:33   ` Pedro Alves
2019-05-27 18:38     ` Eli Zaretskii
2019-05-29 12:38       ` Pedro Alves
2019-05-29 15:03         ` Eli Zaretskii
2019-05-30 10:26         ` Philippe Waroquiers
2019-12-17 17:00     ` Eli Zaretskii
2019-12-17 17:51       ` Pedro Alves
2019-12-18 17:08         ` Eli Zaretskii
2019-12-18 17:42           ` Pedro Alves
2019-12-18 18:33             ` Eli Zaretskii
2019-12-25 15:57               ` Eli Zaretskii
2020-01-03 19:59                 ` Pedro Alves
2020-01-03 20:08                   ` Pedro Alves
2020-01-03 20:34                   ` Eli Zaretskii
2020-01-06 11:57                     ` Pedro Alves
2020-01-06 16:17                       ` Eli Zaretskii
2020-01-06 18:51                         ` Pedro Alves
2020-01-06 19:26                           ` Eli Zaretskii
2020-01-06 18:59                   ` Hannes Domani via gdb-patches
2020-01-06 19:34                     ` Eli Zaretskii
2020-01-06 19:38                       ` Hannes Domani via gdb-patches
2020-01-06 19:55                         ` Eli Zaretskii
2020-01-03 17:04               ` Pedro Alves
2019-05-04 16:18 ` [RFAv3 5/6] Test the | (pipe) command Philippe Waroquiers
2019-05-27 17:49   ` Pedro Alves
2019-05-04 16:18 ` [RFAv3 1/6] Add previous_saved_command_line to allow a command to repeat a previous command Philippe Waroquiers
2019-05-27 17:29   ` Pedro Alves [this message]
2019-05-04 16:18 ` [RFAv3 3/6] Add function execute_command_to_ui_file Philippe Waroquiers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=80035dbe-4682-eb51-9db2-c774e5f87a7a@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=philippe.waroquiers@skynet.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox