From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 120204 invoked by alias); 13 Apr 2015 19:23:22 -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 120159 invoked by uid 89); 13 Apr 2015 19:23:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 13 Apr 2015 19:23:20 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3DJNIib015136 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 13 Apr 2015 15:23:19 -0400 Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3DJNIYO011178 for ; Mon, 13 Apr 2015 15:23:18 -0400 Subject: [PATCH 07/18] Implement completion limiting for filename_completer. From: Keith Seitz To: gdb-patches@sourceware.org Date: Mon, 13 Apr 2015 19:23:00 -0000 Message-ID: <20150413192318.29172.43601.stgit@valrhona.uglyboxes.com> In-Reply-To: <20150413192235.29172.13097.stgit@valrhona.uglyboxes.com> References: <20150413192235.29172.13097.stgit@valrhona.uglyboxes.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00485.txt.bz2 This patch converts filename_completer to using maybe_add_completion and adds some tests to exercise this new behavior. gdb/ChangeLog * completer.c (filename_completer): Use maybe_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. --- gdb/completer.c | 18 +++++++++ gdb/testsuite/gdb.base/completion.exp | 65 +++++++++++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/gdb/completer.c b/gdb/completer.c index 6708bb1..291ba73 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -136,6 +136,7 @@ filename_completer (struct completer_data *cdata, while (1) { char *p, *q; + enum maybe_add_completion_enum add_status; p = rl_filename_completion_function (text, subsequent_name); if (p == NULL) @@ -172,7 +173,22 @@ filename_completer (struct completer_data *cdata, strcat (q, p); xfree (p); } - VEC_safe_push (char_ptr, return_val, q); + add_status = maybe_add_completion (cdata, q); + switch (add_status) + { + case MAYBE_ADD_COMPLETION_OK: + VEC_safe_push (char_ptr, return_val, q); + break; + case MAYBE_ADD_COMPLETION_OK_MAX_REACHED: + VEC_safe_push (char_ptr, return_val, q); + return return_val; + case MAYBE_ADD_COMPLETION_MAX_REACHED: + xfree (q); + return return_val; + case MAYBE_ADD_COMPLETION_DUPLICATE: + xfree (q); + 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 5afd851..78ba216 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,7 +938,59 @@ 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)" + } + } +} + +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