From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 120859 invoked by alias); 13 Apr 2015 19:23:26 -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 120817 invoked by uid 89); 13 Apr 2015 19:23:26 -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:25 +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 (8.14.4/8.14.4) with ESMTP id t3DJNOVU015149 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 13 Apr 2015 15:23:24 -0400 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 t3DJNN49030955 for ; Mon, 13 Apr 2015 15:23:23 -0400 Subject: [PATCH 09/18] Implement completion limiting for interpreter_completer. From: Keith Seitz To: gdb-patches@sourceware.org Date: Mon, 13 Apr 2015 19:23:00 -0000 Message-ID: <20150413192323.29172.67305.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/msg00491.txt.bz2 This is another simple patch which converts interpreter_completer to use maybe_add_completion and adds some tests to make sure that everything is working properly. gdb/ChangeLog * interps.c (interpreter_completer): Use maybe_add_completion. gdb/testsuite/ChangeLog * gdb.base/completion.exp: Test completion limiting on interpreter name with "interpreter-exec". --- gdb/interps.c | 19 ++++++++++++++++++- gdb/testsuite/gdb.base/completion.exp | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/gdb/interps.c b/gdb/interps.c index ac1b512..085cac5 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -451,6 +451,7 @@ interpreter_completer (struct completer_data *cdata, if (strncmp (interp->name, text, textlen) == 0) { char *match; + enum maybe_add_completion_enum add_status; match = (char *) xmalloc (strlen (word) + strlen (interp->name) + 1); if (word == text) @@ -467,7 +468,23 @@ interpreter_completer (struct completer_data *cdata, match[text - word] = '\0'; strcat (match, interp->name); } - VEC_safe_push (char_ptr, matches, match); + + add_status = maybe_add_completion (cdata, match); + switch (add_status) + { + case MAYBE_ADD_COMPLETION_OK: + VEC_safe_push (char_ptr, matches, match); + break; + case MAYBE_ADD_COMPLETION_OK_MAX_REACHED: + VEC_safe_push (char_ptr, matches, match); + return matches; + case MAYBE_ADD_COMPLETION_MAX_REACHED: + xfree (match); + return matches; + case MAYBE_ADD_COMPLETION_DUPLICATE: + xfree (match); + break; + } } } diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp index 90cdb36..d07ca86 100644 --- a/gdb/testsuite/gdb.base/completion.exp +++ b/gdb/testsuite/gdb.base/completion.exp @@ -1021,3 +1021,19 @@ if {$num_signals > $max_completions} { append msg "limiting in signal_handler ($num_signals)" 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" +}