From patchwork Mon May 4 19:18:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 6560 Received: (qmail 96422 invoked by alias); 4 May 2015 19:18:48 -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 96157 invoked by uid 89); 4 May 2015 19:18:47 -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, 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, 04 May 2015 19:18:46 +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 t44JIigg006600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 4 May 2015 15:18:45 -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 t44JIiuP003851 for ; Mon, 4 May 2015 15:18:44 -0400 Subject: [PATCH v2 15/18] Implement completion limiting for scmcmd_add_completion. From: Keith Seitz To: gdb-patches@sourceware.org Date: Mon, 04 May 2015 12:18:44 -0700 Message-ID: <20150504191844.20434.56171.stgit@valrhona.uglyboxes.com> In-Reply-To: <20150504191734.20434.68053.stgit@valrhona.uglyboxes.com> References: <20150504191734.20434.68053.stgit@valrhona.uglyboxes.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes This patch converts scmcmd_add_completion to use add_completion and adds some tests for this new behavior. gdb/ChangeLog * guile/scm-cmd.c (cmdscm_add_completion): Add completer_data argument. All callers updated. Use add_completion. gdb/testsuite/ChangeLog * gdb.guile/scm-cmd.exp: Add completion limiting tests. --- gdb/guile/scm-cmd.c | 10 +++++----- gdb/testsuite/gdb.guile/scm-cmd.exp | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c index 2c57d17..e5bd78b 100644 --- a/gdb/guile/scm-cmd.c +++ b/gdb/guile/scm-cmd.c @@ -348,7 +348,8 @@ cmdscm_bad_completion_result (const char *msg, SCM completion) The result is a boolean indicating success. */ static int -cmdscm_add_completion (SCM completion, VEC (char_ptr) **result) +cmdscm_add_completion (SCM completion, struct completer_data *cdata, + VEC (char_ptr) **result) { char *item; SCM except_scm; @@ -370,8 +371,7 @@ cmdscm_add_completion (SCM completion, VEC (char_ptr) **result) return 0; } - VEC_safe_push (char_ptr, *result, item); - + (void) add_completion (cdata, result, item); return 1; } @@ -418,7 +418,7 @@ cmdscm_completer (struct completer_data *cdata, { SCM next = scm_car (list); - if (!cmdscm_add_completion (next, &result)) + if (!cmdscm_add_completion (next, cdata, &result)) { VEC_free (char_ptr, result); goto done; @@ -442,7 +442,7 @@ cmdscm_completer (struct completer_data *cdata, goto done; } - if (!cmdscm_add_completion (next, &result)) + if (!cmdscm_add_completion (next, cdata, &result)) { VEC_free (char_ptr, result); goto done; diff --git a/gdb/testsuite/gdb.guile/scm-cmd.exp b/gdb/testsuite/gdb.guile/scm-cmd.exp index 53c0fdf..ac721c3 100644 --- a/gdb/testsuite/gdb.guile/scm-cmd.exp +++ b/gdb/testsuite/gdb.guile/scm-cmd.exp @@ -196,6 +196,30 @@ gdb_test "test-scheme-error-cmd ugh" \ "Error occurred in Scheme-implemented GDB command." \ "call scheme-error command" +# Test completion limiting. +set max_completions 2 +gdb_test_no_output "set max-completions $max_completions" +set end "\\\*\\\*\\\* List may be truncated, " +append end "max-completions reached\\\. \\\*\\\*\\\*" +set test "limit complete completer-as-function 42\." +gdb_test_multiple "complete completer-as-function 42\." $test { + "complete completer-as-function 42\\\." { exp_continue } + -re "completer-as-function 42\\\.\[1-3\]\r\n" { + incr seen + exp_continue + } + -re ".*$end\r\n$gdb_prompt $" { + if {$seen == $max_completions} { + pass $test + } else { + fail "$test ($seen/$max_completions)" + } + } + -re ".*$gdb_prompt $" { + fail "$test (unlimited)" + } +} + # If there is a problem with object management, this can often trigger it. # It is useful to do this last, after we've created a bunch of command objects.