From patchwork Thu Aug 6 19:18:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 8053 Received: (qmail 17602 invoked by alias); 6 Aug 2015 19:18:16 -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 17586 invoked by uid 89); 6 Aug 2015 19:18:15 -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 19:18:14 +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 (Postfix) with ESMTPS id 1B82837198E for ; Thu, 6 Aug 2015 19:18:13 +0000 (UTC) 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 t76JICWC022187 for ; Thu, 6 Aug 2015 15:18:12 -0400 Subject: [PATCH v3 09/19] Implement completion limiting for interpreter_completer. From: Keith Seitz To: gdb-patches@sourceware.org Date: Thu, 06 Aug 2015 12:18:12 -0700 Message-ID: <20150806191756.32159.49337.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 interpreter_completer.. --- This is another simple patch which converts interpreter_completer to use add_completion and adds some tests to make sure that everything is working properly. gdb/ChangeLog * interps.c (interpreter_completer): Use add_completion. gdb/testsuite/ChangeLog * gdb.base/completion.exp: Test completion limiting on interpreter name with "interpreter-exec". --- gdb/interps.c | 21 +++------------------ gdb/testsuite/gdb.base/completion.exp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/gdb/interps.c b/gdb/interps.c index 2cfe92b..9e993c8 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -448,24 +448,9 @@ interpreter_completer (struct completer_data *cdata, { if (strncmp (interp->name, text, textlen) == 0) { - char *match; - - match = (char *) xmalloc (strlen (word) + strlen (interp->name) + 1); - if (word == text) - strcpy (match, interp->name); - else if (word > text) - { - /* Return some portion of interp->name. */ - strcpy (match, interp->name + (word - text)); - } - else - { - /* Return some of text plus interp->name. */ - strncpy (match, word, text - word); - match[text - word] = '\0'; - strcat (match, interp->name); - } - VEC_safe_push (char_ptr, matches, match); + if (add_completion (cdata, &matches, interp->name, text, word) + == ADD_COMPLETION_MAX_REACHED) + break; } } diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp index 884b9f6..41323d2 100644 --- a/gdb/testsuite/gdb.base/completion.exp +++ b/gdb/testsuite/gdb.base/completion.exp @@ -1022,6 +1022,22 @@ if {$num_signals > $max_completions} { untested $msg } +# Test interpreter_completer. There are only four completions +# available for this, so temporarily set max-completions to 3. +with_test_prefix "interpreter_completer" { + set old_max $max_completions + set max_completions 3 + gdb_test_no_output "set max-completions $max_completions" +} + +test_completion_limit "interpreter-exec m" \ + "interpreter-exec mi\[1-3\]?" $max_completions + +with_test_prefix "interpreter_completer reset" { + set max_completions $old_max + gdb_test_no_output "set max-completions $max_completions" +} + # # Test TUI completions #