From patchwork Thu Aug 6 19:18:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 8071 Received: (qmail 10920 invoked by alias); 6 Aug 2015 22:12:20 -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 10888 invoked by uid 89); 6 Aug 2015 22:12:18 -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:12:18 +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 04B9C4C643 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 t76JIaaK011864 for ; Thu, 6 Aug 2015 15:18:36 -0400 Subject: [PATCH v3 10/19] Implement completion limiting for cmdpy_completer. From: Keith Seitz To: gdb-patches@sourceware.org Date: Thu, 06 Aug 2015 12:18:36 -0700 Message-ID: <20150806191815.32159.84277.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. Free string memory after passing to add_completion. --- This patch converts cmdpy_completer, used by commands written in python. It also adds tests for some untested python functionality related to completion. gdb/ChangeLog * python/py-cmd.c (cmdpy_completer) Use add_completion. Free memory associated with `item'. gdb/testsuite/ChangeLog * gdb.python/py-completion.exp: Test completion functions, with and without completion limiting. --- gdb/python/py-cmd.c | 9 +++++- gdb/testsuite/gdb.python/py-completion.exp | 45 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c index 21d842e..36e352e 100644 --- a/gdb/python/py-cmd.c +++ b/gdb/python/py-cmd.c @@ -392,7 +392,14 @@ cmdpy_completer (struct completer_data *cdata, PyErr_Clear (); continue; } - VEC_safe_push (char_ptr, result, item); + + if (add_completion (cdata, &result, item, NULL, NULL) + == ADD_COMPLETION_MAX_REACHED) + { + xfree (item); + break; + } + xfree (item); } Py_DECREF (iter); diff --git a/gdb/testsuite/gdb.python/py-completion.exp b/gdb/testsuite/gdb.python/py-completion.exp index 5e45087..f7f23a3 100644 --- a/gdb/testsuite/gdb.python/py-completion.exp +++ b/gdb/testsuite/gdb.python/py-completion.exp @@ -128,3 +128,48 @@ if {[readline_is_used]} { "completelimit2 cl29" } } + +# The terminal at the end of the complete command +set end "\\\*\\\*\\\* List may be truncated, " +append end "max-completions reached\\\. \\\*\\\*\\\*" + +set max_completions 3 +gdb_test_no_output "set max-completions $max_completions" +set seen 0 + +set testname "limit completions of 'complete completel'" +gdb_test_multiple "complete completel" $testname { + "complete completel" { exp_continue } + + -re "completelimit\[1-9\]+\r\n" { + incr seen + exp_continue + } + + -re "completel $end\r\n$gdb_prompt $" { + if {$seen == $max_completions} { + pass $testname + } else { + fail "$testname ($seen/$max_completions)" + } + } +} + +set testname "limit completions of 'complete completelimit1 c'" +set seen 0 +gdb_test_multiple "complete completelimit1 c" $testname { + "complete completelimit1 c" { exp_continue } + + -re "completelimit1 cl1\[1-9\]+\r\n" { + incr seen + exp_continue + } + + -re "completelimit1 c $end\r\n$gdb_prompt $" { + if {$seen == $max_completions} { + pass $testname + } else { + fail "$testname ($seen/$max_completions)" + } + } +}