From patchwork Thu Jun 29 15:25:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 21333 Received: (qmail 94087 invoked by alias); 29 Jun 2017 15:25:18 -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 94071 invoked by uid 89); 29 Jun 2017 15:25:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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 ESMTP; Thu, 29 Jun 2017 15:25:15 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96B5563E23; Thu, 29 Jun 2017 15:25:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 96B5563E23 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 96B5563E23 Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3669179DE; Thu, 29 Jun 2017 15:25:13 +0000 (UTC) Subject: Re: [PATCH 06/40] Expression completer should not match explicit location options To: Yao Qi References: <1496406158-12663-1-git-send-email-palves@redhat.com> <1496406158-12663-7-git-send-email-palves@redhat.com> <86h8yzdwng.fsf@gmail.com> <86vanfca07.fsf@gmail.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <97bb1780-fb0e-7959-45aa-aab85899931f@redhat.com> Date: Thu, 29 Jun 2017 16:25:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <86vanfca07.fsf@gmail.com> On 06/29/2017 12:24 PM, Yao Qi wrote: > Pedro Alves writes: > >> commands that take expressions (not linespecs/locations) as >> arguments, such as the "print" command, do _not_ understand >> the "-source", "-function" etc. switches. Instead, "-foo" is >> understood as an expression applying unary minus on a symbol >> named "foo" (think "print -1"). > > This paragraph is useful. Thanks for the explanation. Patch is good to > me. Rewrote the commit log in that direction, and pushed it in, then. From eb17d4137dc83a373b8968cd20b256fa8073a4ca Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 29 Jun 2017 15:52:38 +0100 Subject: [PATCH] Expression completer should not match explicit location options This commit fixes a mismatch between what "print" command completer thinks the command understands, and what the command actually understands. The explicit location options are understood by commands that take (linespecs and) explicit locations as argument. I.e, breakpoint commands, and "list". For example: (gdb) b -source file.c -function my_func So for those commands, it makes sense that the completer completes: "b -sour[TAB]" -> "b -source " "b -functi[TAB]" -> "b -function " etc. However, completion for commands that take expressions (not linespecs/locations) as arguments, such as the "print" command, also completes the explicit location options, even though those switches aren't really understood by these commands. Instead, "-foo" is understood as an expression applying unary minus on a symbol named "foo" (think "print -1"): (gdb) p -func[TAB] (gdb) p -function [RET] No symbol "function" in current context. The patch fixes this by having the expression_completer function bypass the function that completes explicit locations. New regression tests included. gdb/ChangeLog: 2017-06-29 Pedro Alves * completer.c (expression_completer): Call linespec_location_completer instead of location_completer. gdb/testsuite/ChangeLog: 2017-06-29 Pedro Alves * gdb.base/printcmds.exp: Add tests. --- gdb/ChangeLog | 5 +++++ gdb/testsuite/ChangeLog | 4 ++++ gdb/completer.c | 2 +- gdb/testsuite/gdb.base/printcmds.exp | 6 ++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c76158f..b47226bc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2017-06-29 Pedro Alves + * completer.c (expression_completer): Call + linespec_location_completer instead of location_completer. + +2017-06-29 Pedro Alves + * completer.c (expression_completer): Remove code that recomputes 'text' from 'word'. diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index b7462a5..41c5434 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-06-29 Pedro Alves + + * gdb.base/printcmds.exp: Add tests. + 2017-06-28 Doug Gilmore PR gdb/21337 diff --git a/gdb/completer.c b/gdb/completer.c index f152dd5..68e68eb 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -635,7 +635,7 @@ expression_completer (struct cmd_list_element *ignore, xfree (fieldname); /* Not ideal but it is what we used to do before... */ - return location_completer (ignore, text, word); + return linespec_location_completer (ignore, text, word); } /* See definition in completer.h. */ diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp index d949b30..323ca73 100644 --- a/gdb/testsuite/gdb.base/printcmds.exp +++ b/gdb/testsuite/gdb.base/printcmds.exp @@ -931,6 +931,12 @@ gdb_test "ptype \"abc\"" " = char \\\[4\\\]" gdb_test "print \$cvar = \"abc\"" " = \"abc\"" gdb_test "print sizeof (\$cvar)" " = 4" +# GDB used to complete the explicit location options even when +# printing expressions. +gdb_test_no_output "complete p -function" +gdb_test_no_output "complete p -line" +gdb_test_no_output "complete p -source" + gdb_file_cmd ${binfile} gdb_test "print \$pc" "No registers\\." "print \$pc (with file)"