From: Doug Evans <xdje42@gmail.com>
To: Keith Seitz <keiths@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v3 07/19] Implement completion limiting for filename_completer.
Date: Sun, 23 Aug 2015 03:58:00 -0000 [thread overview]
Message-ID: <m337zairmv.fsf@sspiff.org> (raw)
In-Reply-To: <20150806191647.32159.95295.stgit@valrhona.uglyboxes.com> (Keith Seitz's message of "Thu, 06 Aug 2015 12:17:03 -0700")
Keith Seitz <keiths@redhat.com> writes:
> Differences in this revision:
>
> 1. Remove partial copy code from filename_completer.
>
> ---
>
> This patch converts filename_completer to using add_completion
> and adds some tests to exercise this new behavior.
>
> gdb/ChangeLog
>
> * completer.c (filename_completer): Use add_completion.
>
> gdb/testsuite/ChangeLog
>
> * gdb.base/completion.exp: Put completion truncation message
> into a variable for use by other tests. Update existing tests.
> (test_completion_limit): New procedure.
> Add tests for completion limiting on file names.
LGTM.
One comment, grep for ===
> ---
> gdb/completer.c | 25 ++----------
> gdb/testsuite/gdb.base/completion.exp | 69 +++++++++++++++++++++++++++++++--
> 2 files changed, 69 insertions(+), 25 deletions(-)
>
> diff --git a/gdb/completer.c b/gdb/completer.c
> index bf4137e..6aa8d35 100644
> --- a/gdb/completer.c
> +++ b/gdb/completer.c
> @@ -157,7 +157,7 @@ filename_completer (struct completer_data *cdata,
> subsequent_name = 0;
> while (1)
> {
> - char *p, *q;
> + char *p;
>
> p = rl_filename_completion_function (text, subsequent_name);
> if (p == NULL)
> @@ -175,26 +175,9 @@ filename_completer (struct completer_data *cdata,
> continue;
> }
>
> - if (word == text)
> - /* Return exactly p. */
> - q = p;
> - else if (word > text)
> - {
> - /* Return some portion of p. */
> - q = xmalloc (strlen (p) + 5);
> - strcpy (q, p + (word - text));
> - xfree (p);
> - }
> - else
> - {
> - /* Return some of TEXT plus p. */
> - q = xmalloc (strlen (p) + (text - word) + 5);
> - strncpy (q, word, text - word);
> - q[text - word] = '\0';
> - strcat (q, p);
> - xfree (p);
> - }
> - VEC_safe_push (char_ptr, return_val, q);
> + if (add_completion (cdata, &return_val, p, text, word)
> + == ADD_COMPLETION_MAX_REACHED)
> + break;
> }
> #if 0
> /* There is no way to do this just long enough to affect quote
> diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
> index 710aac0..f0b7f2c 100644
> --- a/gdb/testsuite/gdb.base/completion.exp
> +++ b/gdb/testsuite/gdb.base/completion.exp
> @@ -858,6 +858,10 @@ gdb_test "complete break need" "need_malloc"
> # Completion limiting.
> #
>
> +# The terminal at the end of the complete command
> +set end "\\\*\\\*\\\* List may be truncated, "
> +append end "max-completions reached\\\. \\\*\\\*\\\*"
> +
> gdb_test_no_output "set max-completions 5"
>
> set test "command-name completion limiting using tab character"
> @@ -866,7 +870,7 @@ gdb_test_multiple "" "$test" {
> -re "^p\\\x07$" {
> send_gdb "\t"
> gdb_test_multiple "" "$test" {
> - -re "List may be truncated, max-completions reached.*\r\n$gdb_prompt p$" {
> + -re "$end\r\n$gdb_prompt p$" {
> # Complete the command and ignore the output to resync
> # gdb for the next test.
> send_gdb "\n"
> @@ -898,7 +902,8 @@ gdb_test_multiple "" "$test" {
> }
> }
>
> -gdb_test_no_output "set max-completions 3"
> +set max_completions 3
> +gdb_test_no_output "set max-completions $max_completions"
>
> set test "symbol-name completion limiting using tab character"
> send_gdb "p marker\t"
> @@ -906,7 +911,7 @@ gdb_test_multiple "" "$test" {
> -re "^p marker\\\x07$" {
> send_gdb "\t"
> gdb_test_multiple "" "$test" {
> - -re "List may be truncated, max-completions reached.*\r\n$gdb_prompt p marker$" {
> + -re "$end\r\n$gdb_prompt p marker$" {
> # Complete the command and ignore the output to resync
> # gdb for the next test.
> send_gdb "\n"
> @@ -933,11 +938,67 @@ gdb_test_multiple "" "$test" {
> set test "symbol-name completion limiting using complete command"
> send_gdb "complete p mark\n"
> gdb_test_multiple "" "$test" {
> - -re "List may be truncated, max-completions reached.*\r\n$gdb_prompt $" {
> + -re "$end\r\n$gdb_prompt $" {
> pass "$test"
> }
> }
>
> +# A convenience function for testing completion limiting.
> +# CMD is a GDB command to to run with "complete".
> +# PATTERN is a regexp pattern matching the expected output
> +# of completion items "seen" in the output.
> +# NUM is the number of maximum completions expected.
> +#
> +# The test will use the test name "limit complete CMD"
> +# and will only count the number of completion items matching
> +# PATTERN. No assumptions are made on the order of the items
> +# seen in GDB's output.
> +#
> +# If NUM items are seen before the truncation message, the test
> +# passes, otherwise it fails. The test can also fail if no
> +# truncation message is seen at all, in which case the test
> +# failure message will say "(unlimited)".
> +
> +proc test_completion_limit {cmd pattern num} {
> + global gdb_prompt
> +
> + # The terminal at the end of the complete command
> + set end "\\\*\\\*\\\* List may be truncated, "
> + append end "max-completions reached\\\. \\\*\\\*\\\*"
> +
> + set cmdr [string_to_regexp $cmd]
> + set seen 0
> + gdb_test_multiple "complete $cmd" "limit complete $cmd" {
> + "complete $cmdr" { exp_continue }
> + -re "$pattern\r\n" {
> + incr seen
> + exp_continue
> + }
> + -re ".*$end\r\n$gdb_prompt $" {
> + if {$seen == $num} {
> + pass "limit complete $cmd"
> + } else {
> + fail "limit complete $cmd ($seen/$num)"
> + }
> + }
> + -re ".*$gdb_prompt $" {
> + fail "limit complete $cmd (unlimited)"
> + }
> + }
> +}
====
IWBN to combine this function with test_completion in
gdb.base/condbreak.exp, and I suppose put the function in gdb.exp.
Only if it's easy though.
> +
> +test_completion_limit "file ./gdb.base/jit-s" \
> + "file \\\./gdb\\\.base/jit-s(imple|olib|o)(\\\.c|\\\.exp)?" \
> + $max_completions
> +
> +# same as above but completing on directory names.
> +test_completion_limit "file ./gdb.a" "file \\\./gdb\\\.a(da|rch|sm)" \
> + $max_completions
> +
> +#
> +# Test TUI completions
> +#
> +
> gdb_test_no_output "set max-completions unlimited"
>
> if {![skip_tui_tests]} {
next prev parent reply other threads:[~2015-08-23 3:58 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-07 2:37 [PATCH v3 00/19] New completer API Keith Seitz
2015-08-06 19:18 ` [PATCH v3 09/19] Implement completion limiting for interpreter_completer Keith Seitz
2015-08-23 4:03 ` Doug Evans
2015-08-06 19:20 ` [PATCH v3 12/19] Implement completion limiting for sim_command_completer Keith Seitz
2015-08-23 4:11 ` Doug Evans
2015-08-06 19:58 ` [PATCH v3 02/19] Remove completion_tracker_t from the public completion API Keith Seitz
2015-08-23 1:02 ` Doug Evans
2015-08-24 16:06 ` Doug Evans
2015-08-06 19:58 ` [PATCH v3 04/19] Implement completion limiting for add_filename_to_list Keith Seitz
2015-08-23 1:07 ` Doug Evans
2015-08-06 19:58 ` [PATCH v3 19/19] Remove the vector return result from the completion API Keith Seitz
2015-08-23 18:03 ` Doug Evans
2015-08-06 19:58 ` [PATCH v3 18/19] Use the hashtable to accumulate completion results Keith Seitz
2015-08-23 17:53 ` Doug Evans
2015-08-06 19:58 ` [PATCH v3 06/19] Implement completion limiting for condition_completer Keith Seitz
2015-08-23 3:53 ` Doug Evans
2015-08-06 20:03 ` [PATCH v3 01/19] Add struct completer_data to the completion API Keith Seitz
2015-08-23 0:29 ` Doug Evans
2015-08-06 21:06 ` [PATCH v3 17/19] Make the completion API completely opaque Keith Seitz
2015-08-23 15:14 ` Doug Evans
2015-08-06 21:06 ` [PATCH v3 05/19] Implement completion limiting for ada_make_symbol_completion_list Keith Seitz
2015-08-23 3:47 ` Doug Evans
2015-08-06 22:03 ` [PATCH v3 13/19] Implement completion limiting for complete_on_enum Keith Seitz
2015-08-23 4:19 ` Doug Evans
2015-08-06 22:03 ` [PATCH v3 11/19] Implement completion limiting for reg_or_group_completer Keith Seitz
2015-08-23 4:09 ` Doug Evans
2015-08-06 22:03 ` [PATCH v3 07/19] Implement completion limiting for filename_completer Keith Seitz
2015-08-23 3:58 ` Doug Evans [this message]
2015-08-06 22:03 ` [PATCH v3 16/19] Implement completion limiting for tui_reggroup_completer Keith Seitz
2015-08-23 4:25 ` Doug Evans
2015-08-06 22:03 ` [PATCH v3 08/19] Implement completion limiting for signal_completer Keith Seitz
2015-08-23 3:59 ` Doug Evans
2015-08-06 22:12 ` [PATCH v3 14/19] Implement completion limiting in add_struct_fields Keith Seitz
2015-08-23 4:23 ` Doug Evans
2015-08-06 22:12 ` [PATCH v3 10/19] Implement completion limiting for cmdpy_completer Keith Seitz
2015-08-23 4:07 ` Doug Evans
2015-08-06 22:36 ` [PATCH v3 03/19] Implement completion-limiting for complete_on_cmdlist Keith Seitz
2015-08-23 1:05 ` Doug Evans
2015-08-07 2:37 ` [PATCH v3 15/19] Implement completion limiting for scmcmd_add_completion Keith Seitz
2015-08-23 4:24 ` Doug Evans
2015-08-07 22:57 ` [PATCH v3 00/19] New completer API Andrew Burgess
2015-08-08 0:04 ` Keith Seitz
2015-08-08 6:44 ` Andrew Burgess
2015-08-08 16:25 ` Keith Seitz
2015-08-22 22:25 ` Doug Evans
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=m337zairmv.fsf@sspiff.org \
--to=xdje42@gmail.com \
--cc=gdb-patches@sourceware.org \
--cc=keiths@redhat.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).