[v6,2/3] gdb: Tab complete internalvars in expressions
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
Commit Message
For example, 'print $f<tab>' or 'print $fo<tab>+$foo' after running
'set $foo=0' now tab completes.
'print $_siginf<tab>' also now tab completes.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7353
---
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(-)
Comments
> Date: Sun, 06 Apr 2025 01:39:04 +0000
> From: Antonio Rische <nt8r@protonmail.com>
> Cc: Antonio Rische <nt8r@protonmail.com>
>
> For example, 'print $f<tab>' or 'print $fo<tab>+$foo' after running
> 'set $foo=0' now tab completes.
>
> 'print $_siginf<tab>' also now tab completes.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=7353
> ---
> 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(-)
Thanks the documentation parts are okay.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Hi,
Thank you for the updated patch!
On 4/5/25 6:39 PM, Antonio Rische wrote:
> 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"
> + }
I have to admit, I am still disappointed that these do not contain the
leading '$', but I can certainly see the pain involved with making this
work, so I'm going to just leave this be. It's still much better than
we have today.
> +
> +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.
"non-existing" -- no need to repost, just change your local copy.
> +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"
Reviewed-By: Keith Seitz <keiths@redhat.com>
Keith
@@ -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
@@ -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);
}
@@ -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
@@ -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"