From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70945 invoked by alias); 23 Aug 2015 03:53:15 -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 70869 invoked by uid 89); 23 Aug 2015 03:53:03 -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-pa0-f46.google.com Received: from mail-pa0-f46.google.com (HELO mail-pa0-f46.google.com) (209.85.220.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 23 Aug 2015 03:53:02 +0000 Received: by pawq9 with SMTP id q9so79791752paw.3 for ; Sat, 22 Aug 2015 20:53:00 -0700 (PDT) X-Received: by 10.68.253.65 with SMTP id zy1mr32894118pbc.159.1440301980730; Sat, 22 Aug 2015 20:53:00 -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 q5sm12658734pdc.65.2015.08.22.20.53.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Aug 2015 20:53:00 -0700 (PDT) From: Doug Evans To: Keith Seitz Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v3 06/19] Implement completion limiting for condition_completer. References: <20150806191404.32159.50755.stgit@valrhona.uglyboxes.com> <20150806191624.32159.8524.stgit@valrhona.uglyboxes.com> Date: Sun, 23 Aug 2015 03:53:00 -0000 In-Reply-To: <20150806191624.32159.8524.stgit@valrhona.uglyboxes.com> (Keith Seitz's message of "Thu, 06 Aug 2015 12:16:45 -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/msg00645.txt.bz2 Keith Seitz writes: > There are no changes from the last revision. > > -- > > This patch converts the condition completer to use add_completion. > A side-effect of this is the similar conversion of complete_internalvar. > > Tests have been added to exercise this new behavior. > > gdb/ChangeLog > > * breakpoint.c (condition_completer): Pass completer_data to > complete_internalvar. > Use add_completion. > * value.c: Include completer.h. > (complete_internalvar): Add completer_data argument. > Use add_completion. > * value.h (complete_internalvar): Add completer_data argument. > > gdb/testsuite/ChangeLog > > * gdb.base/condbreak.exp (test_completion): New procedure. > Add more completion tests, with and without limiting. ==== One nit. Ok with that fixed. > --- > gdb/breakpoint.c | 8 +++- > gdb/testsuite/gdb.base/condbreak.exp | 70 ++++++++++++++++++++++++++++++++++ > gdb/value.c | 9 ++-- > gdb/value.h | 3 + > 4 files changed, 83 insertions(+), 7 deletions(-) > > diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c > index 70569df..24243c4 100644 > --- a/gdb/breakpoint.c > +++ b/gdb/breakpoint.c > @@ -1052,7 +1052,7 @@ condition_completer (struct completer_data *cdata, > /* We don't support completion of history indices. */ > if (isdigit (text[1])) > return NULL; > - return complete_internalvar (&text[1]); > + return complete_internalvar (cdata, &text[1]); > } > > /* We're completing the breakpoint number. */ > @@ -1065,7 +1065,11 @@ condition_completer (struct completer_data *cdata, > xsnprintf (number, sizeof (number), "%d", b->number); > > if (strncmp (number, text, len) == 0) > - VEC_safe_push (char_ptr, result, xstrdup (number)); > + { > + if (add_completion (cdata, &result, number, NULL, NULL) > + == ADD_COMPLETION_MAX_REACHED) > + break; > + } > } > > return result; > diff --git a/gdb/testsuite/gdb.base/condbreak.exp b/gdb/testsuite/gdb.base/condbreak.exp > index fa40a5f..5630ede 100644 > --- a/gdb/testsuite/gdb.base/condbreak.exp > +++ b/gdb/testsuite/gdb.base/condbreak.exp > @@ -246,3 +246,73 @@ gdb_test "complete cond 1" "cond 1" > gdb_test "set variable \$var = 1" > gdb_test "complete cond \$v" "cond \\\$var" > gdb_test "complete cond 1 values\[0\].a" "cond 1 values.0..a_field" > + > +# Test non-trivial completion and completion-limiting > + > +# Delete all breakpoints and create a bunch of new ones. > +delete_breakpoints > +for {set i 0} {$i < 20} {incr i} { > + with_test_prefix "set breakpoint $i" { > + gdb_breakpoint "factorial" > + } > +} > + > +# While the completer function does traverse breakpoints in the order > +# they were created, don't assume that is required for the test. > +# We only count the number of completions found. In this case, > +# this test will create breakpoints 9-19, giving "complete cond 1" > +# ten total completion possibilities. > + > +# A convenience procedure to automate test completion lists. > +proc test_completion {cmd exp total {limit 0}} { > + global gdb_prompt > + > + if {$limit} { > + set end "\\\*\\\*\\\* List may be truncated, " > + append end "max-completions reached\\\. \\\*\\\*\\\*\r\n" > + set testname "limit '$cmd'" > + } else { > + set end "" > + set testname $cmd > + } > + > + set seen 0 > + gdb_test_multiple $cmd $testname { > + "$cmd\r\n" { exp_continue } > + > + -re "cond $exp\[0-9\]+\r\n" { > + incr seen > + exp_continue > + } > + > + -re ".*$end$gdb_prompt $" { > + if {$seen == $total} { > + pass $testname > + } else { > + fail "$testname ($seen/$total)" > + } > + } > + } > +} ==== Nice test. > + > +# Test completion of breakpoint number. > +with_test_prefix "completion test:" { > + test_completion "complete cond 1" "1" 10 > +} > + > +# Test completion of breakpoint number using internal variable. > +for {set i 0} {$i < 10} {incr i} { > + gdb_test_no_output "set variable \$var_bp_$i = $i" > +} > + > +test_completion "complete cond \$var_bp" "\\\$var_bp_" 10 > + > +# Run the above tests with completion limiting. > +set max_completions 4 > +gdb_test_no_output "set max-completions $max_completions" > + > +with_test_prefix "completion test:" { > + test_completion "complete cond 1" "1" $max_completions 1 > +} > + > +test_completion "complete cond \$var_bp" "\\\$var_bp_" $max_completions 1 > diff --git a/gdb/value.c b/gdb/value.c > index 63ee94d..22d392a 100644 > --- a/gdb/value.c > +++ b/gdb/value.c > @@ -40,6 +40,7 @@ > #include "tracepoint.h" > #include "cp-abi.h" > #include "user-regs.h" > +#include "completer.h" > > /* Prototypes for exported functions. */ > > @@ -2062,7 +2063,7 @@ lookup_only_internalvar (const char *name) > were found. */ > > VEC (char_ptr) * > -complete_internalvar (const char *name) > +complete_internalvar (struct completer_data *cdata, const char *name) > { > VEC (char_ptr) *result = NULL; > struct internalvar *var; > @@ -2073,9 +2074,9 @@ complete_internalvar (const char *name) > for (var = internalvars; var; var = var->next) > if (strncmp (var->name, name, len) == 0) > { > - char *r = xstrdup (var->name); > - > - VEC_safe_push (char_ptr, result, r); > + if (add_completion (cdata, &result, var->name, NULL, NULL) > + == ADD_COMPLETION_MAX_REACHED) > + break; > } > > return result; > diff --git a/gdb/value.h b/gdb/value.h > index 82deaf2..03df1b7 100644 > --- a/gdb/value.h > +++ b/gdb/value.h > @@ -876,7 +876,8 @@ extern struct internalvar *lookup_only_internalvar (const char *name); > > extern struct internalvar *create_internalvar (const char *name); > > -extern VEC (char_ptr) *complete_internalvar (const char *name); > +extern VEC (char_ptr) *complete_internalvar (struct completer_data *cdata, > + const char *name); ==== Add a forward decl for struct completer_cdata. > > /* An internalvar can be dynamically computed by supplying a vector of > function pointers to perform various operations. */