From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 100759 invoked by alias); 23 Aug 2015 03:58:28 -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 100686 invoked by uid 89); 23 Aug 2015 03:58:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f182.google.com Received: from mail-pd0-f182.google.com (HELO mail-pd0-f182.google.com) (209.85.192.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 23 Aug 2015 03:58:14 +0000 Received: by pdrh1 with SMTP id h1so41180915pdr.0 for ; Sat, 22 Aug 2015 20:58:12 -0700 (PDT) X-Received: by 10.70.137.37 with SMTP id qf5mr33170333pdb.12.1440302292506; Sat, 22 Aug 2015 20:58:12 -0700 (PDT) Received: from seba.sebabeach.org.gmail.com (173-13-178-53-sfba.hfc.comcastbusiness.net. [173.13.178.53]) by smtp.gmail.com with ESMTPSA id fl6sm12698461pab.12.2015.08.22.20.58.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Aug 2015 20:58:11 -0700 (PDT) From: Doug Evans To: Keith Seitz Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v3 07/19] Implement completion limiting for filename_completer. References: <20150806191404.32159.50755.stgit@valrhona.uglyboxes.com> <20150806191647.32159.95295.stgit@valrhona.uglyboxes.com> Date: Sun, 23 Aug 2015 03:58:00 -0000 In-Reply-To: <20150806191647.32159.95295.stgit@valrhona.uglyboxes.com> (Keith Seitz's message of "Thu, 06 Aug 2015 12:17:03 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2015-08/txt/msg00646.txt.bz2 Keith Seitz 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]} {