This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3 09/19] Implement completion limiting for interpreter_completer.


Keith Seitz <keiths@redhat.com> writes:
> Differences in this revision:
>
> 1. Remove partial copy code from interpreter_completer..
>
> ---
>
> This is another simple patch which converts interpreter_completer
> to use add_completion and adds some tests to make sure that everything
> is working properly.
>
> gdb/ChangeLog
>
> 	* interps.c (interpreter_completer): Use add_completion.
>
> gdb/testsuite/ChangeLog
>
> 	* gdb.base/completion.exp: Test completion limiting on
> 	interpreter name with "interpreter-exec".

LGTM with one nit below fixed.

I'm really liking all this removal of duplicate code.
Thanks!

> ---
>  gdb/interps.c                         |   21 +++------------------
>  gdb/testsuite/gdb.base/completion.exp |   16 ++++++++++++++++
>  2 files changed, 19 insertions(+), 18 deletions(-)
>
> diff --git a/gdb/interps.c b/gdb/interps.c
> index 2cfe92b..9e993c8 100644
> --- a/gdb/interps.c
> +++ b/gdb/interps.c
> @@ -448,24 +448,9 @@ interpreter_completer (struct completer_data *cdata,
>      {
>        if (strncmp (interp->name, text, textlen) == 0)
>  	{
> -	  char *match;
> -
> -	  match = (char *) xmalloc (strlen (word) + strlen (interp->name) + 1);
> -	  if (word == text)
> -	    strcpy (match, interp->name);
> -	  else if (word > text)
> -	    {
> -	      /* Return some portion of interp->name.  */
> -	      strcpy (match, interp->name + (word - text));
> -	    }
> -	  else
> -	    {
> -	      /* Return some of text plus interp->name.  */
> -	      strncpy (match, word, text - word);
> -	      match[text - word] = '\0';
> -	      strcat (match, interp->name);
> -	    }
> -	  VEC_safe_push (char_ptr, matches, match);
> +	  if (add_completion (cdata, &matches, interp->name, text, word)
> +	      == ADD_COMPLETION_MAX_REACHED)
> +	    break;
>  	}
>      }
>  
> diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
> index 884b9f6..41323d2 100644
> --- a/gdb/testsuite/gdb.base/completion.exp
> +++ b/gdb/testsuite/gdb.base/completion.exp
> @@ -1022,6 +1022,22 @@ if {$num_signals > $max_completions} {
>      untested $msg
>  }
>  
> +# Test interpreter_completer.  There are only four completions
> +# available for this, so temporarily set max-completions to 3.
> +with_test_prefix "interpreter_completer" {
> +    set old_max $max_completions

====
There is save_vars now to handle restoring variables
to their previous values.

save_vars { max_completions } {
    ...
}

> +    set max_completions 3
> +    gdb_test_no_output "set max-completions $max_completions"
> +}
> +
> +test_completion_limit "interpreter-exec m" \
> +    "interpreter-exec mi\[1-3\]?" $max_completions
> +
> +with_test_prefix "interpreter_completer reset" {
> +    set max_completions $old_max
> +    gdb_test_no_output "set max-completions $max_completions"
> +}
> +
>  #
>  # Test TUI completions
>  #


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]