From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 121191 invoked by alias); 13 Apr 2015 19:23:30 -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 121167 invoked by uid 89); 13 Apr 2015 19:23:29 -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:28 +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 t3DJNQ0G030708 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 13 Apr 2015 15:23:27 -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 t3DJNQqg011227 for ; Mon, 13 Apr 2015 15:23:26 -0400 Subject: [PATCH 10/18] Implement completion limiting for cmdpy_completer. From: Keith Seitz To: gdb-patches@sourceware.org Date: Mon, 13 Apr 2015 19:23:00 -0000 Message-ID: <20150413192326.29172.56677.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/msg00487.txt.bz2 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 maybe_add_completion. gdb/testsuite/ChangeLog * gdb.python/py-completion.exp: Test completion functions, with and without completion limiting. --- gdb/python/py-cmd.c | 24 ++++++++++++++- gdb/testsuite/gdb.python/py-completion.exp | 45 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c index 21d842e..ed97ce5 100644 --- a/gdb/python/py-cmd.c +++ b/gdb/python/py-cmd.c @@ -370,13 +370,15 @@ cmdpy_completer (struct completer_data *cdata, { PyObject *iter = PyObject_GetIter (resultobj); PyObject *elt; + int stop = 0; if (iter == NULL) goto done; - while ((elt = PyIter_Next (iter)) != NULL) + while (!stop && (elt = PyIter_Next (iter)) != NULL) { char *item; + enum maybe_add_completion_enum add_status; if (! gdbpy_is_string (elt)) { @@ -392,7 +394,25 @@ cmdpy_completer (struct completer_data *cdata, PyErr_Clear (); continue; } - VEC_safe_push (char_ptr, result, item); + + add_status = maybe_add_completion (cdata, item); + switch (add_status) + { + case MAYBE_ADD_COMPLETION_OK: + VEC_safe_push (char_ptr, result, item); + break; + case MAYBE_ADD_COMPLETION_OK_MAX_REACHED: + VEC_safe_push (char_ptr, result, item); + stop = 1; + break; + case MAYBE_ADD_COMPLETION_MAX_REACHED: + xfree (item); + stop = 1; + break; + case MAYBE_ADD_COMPLETION_DUPLICATE: + xfree (item); + break; + } } 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)" + } + } +}