From patchwork Thu Aug 6 19:17:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 8070 Received: (qmail 111602 invoked by alias); 6 Aug 2015 22:03:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 111546 invoked by uid 89); 6 Aug 2015 22:03:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no 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; Thu, 06 Aug 2015 22:03:35 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 1ABC44C64B for ; Thu, 6 Aug 2015 22:03:32 +0000 (UTC) Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t76JH3nN011438 for ; Thu, 6 Aug 2015 15:17:03 -0400 Subject: [PATCH v3 07/19] Implement completion limiting for filename_completer. From: Keith Seitz To: gdb-patches@sourceware.org Date: Thu, 06 Aug 2015 12:17:03 -0700 Message-ID: <20150806191647.32159.95295.stgit@valrhona.uglyboxes.com> In-Reply-To: <20150806191404.32159.50755.stgit@valrhona.uglyboxes.com> References: <20150806191404.32159.50755.stgit@valrhona.uglyboxes.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes 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. --- 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)" + } + } +} + +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]} {