From patchwork Sun Apr 6 01:39:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Rische X-Patchwork-Id: 109920 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 74F27385B52C for ; Sun, 6 Apr 2025 01:48:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74F27385B52C Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, secure) header.d=protonmail.com header.i=@protonmail.com header.a=rsa-sha256 header.s=protonmail3 header.b=kj0JRK8A X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-106103.protonmail.ch (mail-106103.protonmail.ch [79.135.106.103]) by sourceware.org (Postfix) with ESMTPS id BF2E4385B524 for ; Sun, 6 Apr 2025 01:39:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF2E4385B524 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=protonmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BF2E4385B524 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=79.135.106.103 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743903550; cv=none; b=AnzCjmdMgNyQYosu20UKTq4XCRfVEggoFQxtuKyGXAx9wuXwxTlVNr6zbgY3tvezBY66FaV2VQAC7fSWzZSEjgyE5M8GugTn/oCoDDdpftWVmjv8+n2Gc2uFQSynCoiSvbnd/Q7njfPnLmtlZxiq9Ji/pTFdr5JGxbjCJg5ykhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743903550; c=relaxed/simple; bh=JIaMl6vXTu4+qtzFg2KYiQ5Lgr+UAtIPC294f65BQwE=; h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version; b=qVwWrjCLh9oVehhJ34aCTcn7/V0ycrfaGdzmo/fCaYdkf12d8/E98NbepUW/iajXQp81TQzsMDhqGC+BDGyeLa4y6R7/RD7XchS99x63XEJpHkoj3Bb77KJ4KRxTzQ/2Ja2x+PMoA8Z36qlPNnOEmnQbzRXAXj+B8Z7NU341Sk8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF2E4385B524 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1743903547; x=1744162747; bh=Byftgs3powyizJYdUCqynmUb8rcatZiFe1mIEade7EI=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=kj0JRK8AbjpyfAHsLqlLDrt0Pf5MDyboObEWax1HkCgqWsqFRDrawO1SCtH48LhNM Gi1paUXbqb7jVLBJeiyhVYu4X3GGEe5kRXzLe4zk2Edff0qIMbwjyTF0J3LOrhaEZm tJiIgNP5xufQR5pfVuT/cBb9Rau1OdJ1WvGF6dD206kUzTOGYUOEjxHQL2owlKxBGg SRsHcfSLKc4Rg1bIcdd8rUMHU7ZtpTyncIhwHoKyIyv0LFzbzSs7MH5IdXgcGlIFLa 1iqRbj53L4aSJoyyLFA2W9PVV58zUTvhnRsro3NP1ndXHiJL5ded7Lz961zPs6hQNE T1OPksszKUtyw== Date: Sun, 06 Apr 2025 01:39:04 +0000 To: gdb-patches@sourceware.org From: Antonio Rische Cc: Antonio Rische Subject: [PATCH v6 2/3] gdb: Tab complete internalvars in expressions Message-ID: <20250406013809.230156-3-nt8r@protonmail.com> In-Reply-To: <20250406013809.230156-1-nt8r@protonmail.com> References: <20250406013809.230156-1-nt8r@protonmail.com> Feedback-ID: 21706885:user:proton X-Pm-Message-ID: d8254d02470641cf8221837255b1e119980e453d MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org For example, 'print $f' or 'print $fo+$foo' after running 'set $foo=0' now tab completes. 'print $_siginf' also now tab completes. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7353 Reviewed-By: Eli Zaretskii Reviewed-By: Keith Seitz --- gdb/NEWS | 3 +++ gdb/completer.c | 9 ++++++++ gdb/doc/gdb.texinfo | 4 ++-- gdb/testsuite/gdb.base/completion.exp | 33 +++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 07c1193d8..7069f3b4b 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -121,6 +121,9 @@ qXfer:threads:read previously treated variables set to void as having never been set (see the $_isvoid convenience function for this behavior). +* Tab completion now suggests convenience variables when tab completing after + the '$' symbol in expressions. + *** Changes in GDB 16 * Support for Nios II targets has been removed as this architecture diff --git a/gdb/completer.c b/gdb/completer.c index 0a8409b44..f94d467ee 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -1497,6 +1497,15 @@ complete_expression (completion_tracker &tracker, && expr_completer->complete (exp.get (), tracker)) return; + /* If the text is non-empty, see if the word is preceded by '$'. */ + if (text[0] != '\0' && text[strlen (text) - strlen (word) - 1] == '$') + { + /* We don't support completion of history indices. */ + if (!isdigit (word[0])) + complete_internalvar (tracker, word); + return; + } + complete_files_symbols (tracker, text, word); } diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index e034ac532..f18fe049b 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -1908,8 +1908,8 @@ limit of 10 elements to print for arrays and strings. @value{GDBN} can fill in the rest of a word in a command for you, if there is only one possibility; it can also show you what the valid possibilities are for the next word in a command, at any time. This works for @value{GDBN} -commands, @value{GDBN} subcommands, command options, and the names of symbols -in your program. +commands, @value{GDBN} subcommands, command options, convenience variables, and +the names of symbols in your program. Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest of a word. If there is only one possibility, @value{GDBN} fills in the diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp index 571d714b7..5b04b62ed 100644 --- a/gdb/testsuite/gdb.base/completion.exp +++ b/gdb/testsuite/gdb.base/completion.exp @@ -1005,3 +1005,36 @@ foreach_with_prefix spc { " " "" } { } } } + +# Test command completion with convenience variables. +test_gdb_complete_unique \ + "print \$_sigin" \ + "print \$_siginfo" + +test_gdb_complete_unique \ + "print \$_siginfo" \ + "print \$_siginfo" + +test_gdb_complete_unique \ + "print \$_gdb_maj" \ + "print \$_gdb_major" + +test_gdb_complete_unique "print \$_gdb_maint_setting_str" "print \$_gdb_maint_setting_str" + +test_gdb_complete_tab_multiple "print \$_gdb_mai" "nt_setting" { + "_gdb_maint_setting" + "_gdb_maint_setting_str" + } + +test_gdb_complete_cmd_multiple "" "print \$_gdb_maint_setting" { + "print \$_gdb_maint_setting" + "print \$_gdb_maint_setting_str" + } + +# Check that a nonexisting convenience variable is not completed. +test_gdb_complete_none "print \$unique_variable_1234567" +test_gdb_complete_none "set \$unique_variable_1234567" + +# Check that after defining the convenience variable it is completed. +gdb_test_no_output "set \$unique_variable_1234567=4" +test_gdb_complete_unique "print \$unique_variable_123456" "print \$unique_variable_1234567"