* [PATCH v5 0/2] Add warning if the native target is not supported
@ 2026-03-10 14:23 Guinevere Larsen
2026-03-10 14:23 ` [PATCH v5 1/2] gdb: improve help text for set commands with limited options Guinevere Larsen
2026-03-10 14:23 ` [PATCH v5 2/2] gdb: Improve warning when no native target is available Guinevere Larsen
0 siblings, 2 replies; 6+ messages in thread
From: Guinevere Larsen @ 2026-03-10 14:23 UTC (permalink / raw)
To: gdb-patches; +Cc: Guinevere Larsen
Recently I was trying to conduct a new-user test, to figure out what
things were stumbling blocks, and one of the users had a macbook. The
user on their own would not have been able to understand what was the
reason that they couldn't execute the inferior to debug it.
This series aims to make it a little more obvious, by making the warning
about not being able to "run" more self-explanatory, and instructs the user
on how to get a list of supported architectures, to know what they'll be
able to remotely debug.
For v5, some tests were updated as Linaro CI correctly pointed out that
they were failing. The updates were just to expected output, no real
logic change was required.
v4 has minor cosmetic changes and a test for the help text changes.
For v3, the warning is now only emitted if the user tries to do
something that requires the native target, such as trying to run. And
the help text now emits a comma separated list instead of 1 item per
line.
For v2, instead of adding a new command, this series changes the help
command, to make it print all available options if a command only
accepts specific options.
Guinevere Larsen (2):
gdb: improve help text for set commands with limited options
gdb: Improve warning when no native target is available
gdb/cli/cli-decode.c | 12 ++++++++++++
gdb/inf-child.c | 7 ++++++-
gdb/target.c | 5 ++++-
.../gdb.base/auto-connect-native-target.exp | 6 ++++--
gdb/testsuite/gdb.base/help.exp | 9 +++++++++
gdb/testsuite/gdb.python/py-doc-reformat.exp | 2 +-
gdb/testsuite/gdb.python/py-parameter.exp | 17 +++++++++++++----
7 files changed, 49 insertions(+), 9 deletions(-)
base-commit: 1add703e09f0f8d073cde4af9d11cd59996e9763
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 1/2] gdb: improve help text for set commands with limited options
2026-03-10 14:23 [PATCH v5 0/2] Add warning if the native target is not supported Guinevere Larsen
@ 2026-03-10 14:23 ` Guinevere Larsen
2026-03-17 13:58 ` Andrew Burgess
2026-03-10 14:23 ` [PATCH v5 2/2] gdb: Improve warning when no native target is available Guinevere Larsen
1 sibling, 1 reply; 6+ messages in thread
From: Guinevere Larsen @ 2026-03-10 14:23 UTC (permalink / raw)
To: gdb-patches; +Cc: Guinevere Larsen, Ciaran Woodward
Some "set" commands only allow a select few options, such as the "set
architecture" command, however, there is no way for a user to know which
options are allowed without trying to set something and getting an
error. This commit improves the situation by making the help command list
all the available options.
Reviewed-By: Ciaran Woodward <ciaranwoodward@xmos.com>
---
gdb/cli/cli-decode.c | 12 ++++++++++++
gdb/testsuite/gdb.base/help.exp | 9 +++++++++
gdb/testsuite/gdb.python/py-doc-reformat.exp | 2 +-
gdb/testsuite/gdb.python/py-parameter.exp | 17 +++++++++++++----
4 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 285f5f1f0c4..5a580387fee 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1876,6 +1876,18 @@ help_cmd (const char *command, struct ui_file *stream)
/* Be sure to expand TABs in the documentation. */
tab_expansion_file expander (stream);
gdb_puts (c->doc, &expander);
+ if (c->enums != nullptr)
+ {
+ gdb_puts ("\nAvailable options are:\n", &expander);
+ const char * const *opt = c->enums;
+ gdb_printf (&expander, " ");
+ while (opt != nullptr && *opt != nullptr)
+ {
+ expander.wrap_here (2);
+ gdb_printf (&expander, "%s, ", *opt);
+ opt++;
+ }
+ }
}
else
{
diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp
index a8c55721ef2..fca8522faa0 100644
--- a/gdb/testsuite/gdb.base/help.exp
+++ b/gdb/testsuite/gdb.base/help.exp
@@ -174,3 +174,12 @@ gdb_test "help mybt" " alias mybt = backtrace \[\r\n\]+An alias of command backt
# Check pre-defined aliases cannot be documented.
gdb_test "document where" "Alias \"where\" is built-in.*" \
"documenting builtin where alias disallowed"
+
+# Check help of a command with limited options lists all the options
+# as expected. The command "set breakpoint condition-evaluation" was
+# chosen because it has few options and isn't dependent on configure
+# options.
+gdb_test "help set breakpoint condition-evaluation" \
+ [multi_line ".*" \
+ "Available options are:" \
+ " auto, host, target, "]
diff --git a/gdb/testsuite/gdb.python/py-doc-reformat.exp b/gdb/testsuite/gdb.python/py-doc-reformat.exp
index 8b0a27f4937..a3c0b85c9e8 100644
--- a/gdb/testsuite/gdb.python/py-doc-reformat.exp
+++ b/gdb/testsuite/gdb.python/py-doc-reformat.exp
@@ -126,7 +126,7 @@ proc test { input_docs expected_output } {
-re "^This is the set doc line\r\n" {
exp_continue
}
- -re "^$expected_output\r\n$::gdb_prompt $" {
+ -re "^$expected_output\r\nAvailable options are:\r\n on, off, \r\n$::gdb_prompt $" {
pass $gdb_test_name
}
}
diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp
index e8b0ef24efb..aec00d527b2 100644
--- a/gdb/testsuite/gdb.python/py-parameter.exp
+++ b/gdb/testsuite/gdb.python/py-parameter.exp
@@ -367,7 +367,10 @@ proc_with_prefix test_empty_doc_parameter {} {
# Setting the __doc__ string to empty means GDB will completely
# elide it from the output.
gdb_test "help set print test-empty-doc-param" \
- "^Set the current value of 'print test-empty-doc-param'\\."
+ [multi_line \
+ "^Set the current value of 'print test-empty-doc-param'\\." \
+ "Available options are:" \
+ " on, off, "]
gdb_test_multiline "None __doc__ parameter" \
"python" "" \
@@ -384,7 +387,9 @@ proc_with_prefix test_empty_doc_parameter {} {
gdb_test "help set print test-none-doc-param" \
[multi_line \
"^Set the current value of 'print test-none-doc-param'\\." \
- "This command is not documented\\."]
+ "This command is not documented\\." \
+ "Available options are:" \
+ " on, off, "]
}
# Test a parameter in which the set_doc/show_doc strings are either
@@ -406,7 +411,9 @@ proc_with_prefix test_empty_set_show_doc_parameter {} {
gdb_test "help set print test-empty-set-show-param" \
[multi_line \
"^Set the current value of 'print test-empty-set-show-param'\\." \
- "This command is not documented\\."]
+ "This command is not documented\\." \
+ "Available options are:" \
+ " on, off, "]
gdb_test "help show print test-empty-set-show-param" \
[multi_line \
@@ -429,7 +436,9 @@ proc_with_prefix test_empty_set_show_doc_parameter {} {
gdb_test "help set print test-none-set-show-param" \
[multi_line \
"^Set the current value of 'print test-none-set-show-param'\\." \
- "This command is not documented\\."]
+ "This command is not documented\\." \
+ "Available options are:" \
+ " on, off, "]
gdb_test "help show print test-none-set-show-param" \
[multi_line \
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 2/2] gdb: Improve warning when no native target is available
2026-03-10 14:23 [PATCH v5 0/2] Add warning if the native target is not supported Guinevere Larsen
2026-03-10 14:23 ` [PATCH v5 1/2] gdb: improve help text for set commands with limited options Guinevere Larsen
@ 2026-03-10 14:23 ` Guinevere Larsen
2026-03-17 11:29 ` Andrew Burgess
1 sibling, 1 reply; 6+ messages in thread
From: Guinevere Larsen @ 2026-03-10 14:23 UTC (permalink / raw)
To: gdb-patches; +Cc: Guinevere Larsen, Ciaran Woodward, Tom Tromey
Currently, if a user attempts to debug a program without access to a
native debugger, the error message will just be:
Don't know how to <command>. try "help target"
This message is too generic, and doesn't help a user without internal
knowledge of GDB.
The present commit changes that message to be more informative for a
user who is unfamiliar with GDB and installed it in an unsupported
system, such as in a mac with M-series chips.
Reviewed-By: Ciaran Woodward <ciaranwoodward@xmos.com>
Approved-By: Tom Tromey <tom@tromey.com>
---
gdb/inf-child.c | 7 ++++++-
gdb/target.c | 5 ++++-
gdb/testsuite/gdb.base/auto-connect-native-target.exp | 6 ++++--
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index 7983ecb0d92..ae2cadc5e2b 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -42,7 +42,12 @@
static const target_info inf_child_target_info = {
"native",
N_("Native process"),
- N_("Native process (started by the \"run\" command).")
+ N_("Native process.\n\
+\n\
+This gives GDB the ability to control the execution of binaries in the\n\
+current CPU architecture. It is installed automatically when you attempt\n\
+to \"run\" or \"start\" a program, if the CPU architecure is supported by\n\
+GDB.")
};
const target_info &
diff --git a/gdb/target.c b/gdb/target.c
index 77a562aa919..6fc1872685f 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -2899,7 +2899,10 @@ find_default_run_target (const char *do_mesg)
return the_native_target;
if (do_mesg != NULL)
- error (_("Don't know how to %s. Try \"help target\"."), do_mesg);
+ error (_("\
+No native target available, unable to %s. Try \"help target native\".\n\
+This may be because your CPU architecture is not supported, use\n\
+\"help set architecture\" for a list of supported architectures."), do_mesg);
return NULL;
}
diff --git a/gdb/testsuite/gdb.base/auto-connect-native-target.exp b/gdb/testsuite/gdb.base/auto-connect-native-target.exp
index 26434396cc6..65696f0167c 100644
--- a/gdb/testsuite/gdb.base/auto-connect-native-target.exp
+++ b/gdb/testsuite/gdb.base/auto-connect-native-target.exp
@@ -105,7 +105,8 @@ kill_program "kill"
gdb_test_no_output "set auto-connect-native-target off"
# Commands that rely on the native target auto-connecting should no longer work.
-gdb_test "start" "Don't know how to run.*" "start no longer works"
+gdb_test "start" "No native target available, unable to run.*" \
+ "start no longer works"
# Explicitly connect to the native target.
gdb_test "target native" \
@@ -181,7 +182,8 @@ with_test_prefix "disconnect" {
fail $test
}
- gdb_test "start" "Don't know how to run.*" "start no longer works"
+ gdb_test "start" "No native target available, unable to run.*" \
+ "start no longer works"
}
# Reenable auto-connecting to the native target. Plain "start" should
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 2/2] gdb: Improve warning when no native target is available
2026-03-10 14:23 ` [PATCH v5 2/2] gdb: Improve warning when no native target is available Guinevere Larsen
@ 2026-03-17 11:29 ` Andrew Burgess
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Burgess @ 2026-03-17 11:29 UTC (permalink / raw)
To: Guinevere Larsen, gdb-patches
Cc: Guinevere Larsen, Ciaran Woodward, Tom Tromey
I see you already go an approval for this patch, so take all of the
below with a huge pinch of salt. I really don't want to spend forever
painting the bike shed. Given the niche that this patch is addressing I
don't really care if it goes in or not. That said...
Guinevere Larsen <guinevere@redhat.com> writes:
> Currently, if a user attempts to debug a program without access to a
> native debugger, the error message will just be:
>
> Don't know how to <command>. try "help target"
I think you must have written this by hand, it would actually be:
Don't know how to <command>. Try "help target".
>
> This message is too generic, and doesn't help a user without internal
> knowledge of GDB.
Disagree with this assessment. I don't see what internal knowledge is
required to grok this error message. I'd rewrite the second sentence so
we had:
Don't know how to <command>. Use "help target" for more details.
Or some such. But this is clear, and gives guidance on what to do next
to resolve the issue (run the help command).
> The present commit changes that message to be more informative for a
> user who is unfamiliar with GDB and installed it in an unsupported
> system, such as in a mac with M-series chips.
When making a change like this I usually include my improved output in
the commit message.
>
> Reviewed-By: Ciaran Woodward <ciaranwoodward@xmos.com>
> Approved-By: Tom Tromey <tom@tromey.com>
> ---
> gdb/inf-child.c | 7 ++++++-
> gdb/target.c | 5 ++++-
> gdb/testsuite/gdb.base/auto-connect-native-target.exp | 6 ++++--
> 3 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/gdb/inf-child.c b/gdb/inf-child.c
> index 7983ecb0d92..ae2cadc5e2b 100644
> --- a/gdb/inf-child.c
> +++ b/gdb/inf-child.c
> @@ -42,7 +42,12 @@
> static const target_info inf_child_target_info = {
> "native",
> N_("Native process"),
> - N_("Native process (started by the \"run\" command).")
> + N_("Native process.\n\
> +\n\
> +This gives GDB the ability to control the execution of binaries in the\n\
> +current CPU architecture. It is installed automatically when you attempt\n\
> +to \"run\" or \"start\" a program, if the CPU architecure is supported by\n\
> +GDB.")
The second sentence isn't totally correct here. At least, if I
understand things correctly. The native target is automatically
selected when the user tries to start an inferior that has no other
target selected. Using 'target remote ...' is going to prevent 'run' or
'start' from working as that target doesn't support these commands. Or
'target extended-remote' or 'target sim' that do support 'run' and
'start' are going to service these commands themselves.
Maybe this is all being too picky, but this text isn't part of an error
message that needs to be kept short. This is the "help target native"
text, so I'm inclined to think that we should favour correctness over
simplicity.
Also, by reducing the first line of the help from "Native process
(started by the \"run\" command)." to just "Native process." this
reduces what is show for 'help target'. I agree with the idea of
dropping the mention of 'run' here, but what about something like
"Control native processes of this computer."? I worried about the work
"computer" here, my first instinct was to write "host", but I worried
that might not be super clear.
> };
>
> const target_info &
> diff --git a/gdb/target.c b/gdb/target.c
> index 77a562aa919..6fc1872685f 100644
> --- a/gdb/target.c
> +++ b/gdb/target.c
> @@ -2899,7 +2899,10 @@ find_default_run_target (const char *do_mesg)
> return the_native_target;
>
> if (do_mesg != NULL)
> - error (_("Don't know how to %s. Try \"help target\"."), do_mesg);
> + error (_("\
> +No native target available, unable to %s. Try \"help target native\".\n\
> +This may be because your CPU architecture is not supported, use\n\
> +\"help set architecture\" for a list of supported architectures."), do_mesg);
If you rebuild GDB without a native target then 'help target native'
will print:
(gdb) help target native
Undefined target command: "native". Try "help target".
Which I guess does redirect the user, but isn't ideal. You probably
need to stick to suggesting 'help target' here.
I feel like I might have said this on an earlier revision of the patch,
but I guess it wasn't the direction you wanted to go. I'll say it again
anyway, because every time I look at this patch I have the exact same
though: I think the original error message is fine, it's short and to
the point. I think that improving the help text for _both_ 'help
target' and 'help target native' would be a better solution to the
problem you have. If a user sees this error and _doesn't_ immediately
try 'help target' then I have very limited sympathy for their confusion,
assuming of course, that 'help target' actually explains what they need
to know. Which is probably doesn't right now.
Another thought that this change inspires, but definitely not something
for you to do here is this: I've long thought we should make our error
objects better, allowing for two strings to be carried around. A single
line ( < 80 characters ) short summary of the error. Then an optional,
multi-line help text style description of the error and how it could be
resolved. Obviously not every (or many) errors will actually need the
second string, but errors like this, that are triggered directly, or
almost directly, from user input, often benefit from an extended, "this
is what you did wrong, and this is how you should fix it" text. The
problem this solves (I think) is that multi-line error messages just
don't format that well. But this is a future problem I think.
Thanks,
Andrew
> return NULL;
> }
>
> diff --git a/gdb/testsuite/gdb.base/auto-connect-native-target.exp b/gdb/testsuite/gdb.base/auto-connect-native-target.exp
> index 26434396cc6..65696f0167c 100644
> --- a/gdb/testsuite/gdb.base/auto-connect-native-target.exp
> +++ b/gdb/testsuite/gdb.base/auto-connect-native-target.exp
> @@ -105,7 +105,8 @@ kill_program "kill"
> gdb_test_no_output "set auto-connect-native-target off"
>
> # Commands that rely on the native target auto-connecting should no longer work.
> -gdb_test "start" "Don't know how to run.*" "start no longer works"
> +gdb_test "start" "No native target available, unable to run.*" \
> + "start no longer works"
>
> # Explicitly connect to the native target.
> gdb_test "target native" \
> @@ -181,7 +182,8 @@ with_test_prefix "disconnect" {
> fail $test
> }
>
> - gdb_test "start" "Don't know how to run.*" "start no longer works"
> + gdb_test "start" "No native target available, unable to run.*" \
> + "start no longer works"
> }
>
> # Reenable auto-connecting to the native target. Plain "start" should
> --
> 2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 1/2] gdb: improve help text for set commands with limited options
2026-03-10 14:23 ` [PATCH v5 1/2] gdb: improve help text for set commands with limited options Guinevere Larsen
@ 2026-03-17 13:58 ` Andrew Burgess
2026-04-16 18:17 ` Guinevere Larsen
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Burgess @ 2026-03-17 13:58 UTC (permalink / raw)
To: Guinevere Larsen, gdb-patches; +Cc: Guinevere Larsen, Ciaran Woodward
Guinevere Larsen <guinevere@redhat.com> writes:
> Some "set" commands only allow a select few options, such as the "set
> architecture" command, however, there is no way for a user to know which
> options are allowed without trying to set something and getting an
> error. This commit improves the situation by making the help command list
> all the available options.
I was experimenting with this patch looking at how other enum set
commands, checking that their output also looks good with this new
feature, and I ran into 'help set demangle-style'. It's output (before
this patch) is:
(gdb) help set demangle-style
Set the current C++ demangling style.
Use `set demangle-style' without arguments for a list of demangling styles.
And indeed:
(gdb) set demangle-style
Requires an argument. Valid arguments are none, auto, gnu-v3, java, gnat, dlang, rust.
And:
(gdb) set architecture
Requires an argument. Valid arguments are ARC600, A6, ARC601, ARC700, A7, ... etc ...
So there is an existing way to get an option list. Maybe what's missing
here is that most enum command help texts don't reference this mechanism.
What if, instead of listing all the options, which can get pretty long,
you auto-added a sentence similar to the one seen in the demangle-style
output? E.g. "Use `set <command>` without arguments for a list of
available options." This would keep the help text less cluttered, but
would give clear guidance on how to get the option list.
Just my thoughts.
Thanks,
Andrew
>
> Reviewed-By: Ciaran Woodward <ciaranwoodward@xmos.com>
> ---
> gdb/cli/cli-decode.c | 12 ++++++++++++
> gdb/testsuite/gdb.base/help.exp | 9 +++++++++
> gdb/testsuite/gdb.python/py-doc-reformat.exp | 2 +-
> gdb/testsuite/gdb.python/py-parameter.exp | 17 +++++++++++++----
> 4 files changed, 35 insertions(+), 5 deletions(-)
>
> diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
> index 285f5f1f0c4..5a580387fee 100644
> --- a/gdb/cli/cli-decode.c
> +++ b/gdb/cli/cli-decode.c
> @@ -1876,6 +1876,18 @@ help_cmd (const char *command, struct ui_file *stream)
> /* Be sure to expand TABs in the documentation. */
> tab_expansion_file expander (stream);
> gdb_puts (c->doc, &expander);
> + if (c->enums != nullptr)
> + {
> + gdb_puts ("\nAvailable options are:\n", &expander);
> + const char * const *opt = c->enums;
> + gdb_printf (&expander, " ");
> + while (opt != nullptr && *opt != nullptr)
The 'opt != nullptr' check here seems redundant. We already check
'c->enums != nullptr' before entering this block, and I think if 'opt++'
causes us to reach nullptr then things have probably gone seriously
wrong.
You could fold the setup of 'opt', the condition check, and the
increment into a for loop like:
for (const char * const *opt = c->enums;
*opt != nullptr;
opt++)
{ ... }
> + {
> + expander.wrap_here (2);
> + gdb_printf (&expander, "%s, ", *opt);
> + opt++;
Given the simplified loop condition check, you could solve the trailing
', ' like:
{
expander.wrap_here (2);
const char *suffix = (*(opt + 1) == nullptr) ? "." : ", ";
gdb_printf (&expander, "%s%s", *opt, suffix);
}
> + }
> + }
> }
> else
> {
> diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp
> index a8c55721ef2..fca8522faa0 100644
> --- a/gdb/testsuite/gdb.base/help.exp
> +++ b/gdb/testsuite/gdb.base/help.exp
> @@ -174,3 +174,12 @@ gdb_test "help mybt" " alias mybt = backtrace \[\r\n\]+An alias of command backt
> # Check pre-defined aliases cannot be documented.
> gdb_test "document where" "Alias \"where\" is built-in.*" \
> "documenting builtin where alias disallowed"
> +
> +# Check help of a command with limited options lists all the options
> +# as expected. The command "set breakpoint condition-evaluation" was
> +# chosen because it has few options and isn't dependent on configure
> +# options.
> +gdb_test "help set breakpoint condition-evaluation" \
> + [multi_line ".*" \
> + "Available options are:" \
> + " auto, host, target, "]
> diff --git a/gdb/testsuite/gdb.python/py-doc-reformat.exp b/gdb/testsuite/gdb.python/py-doc-reformat.exp
> index 8b0a27f4937..a3c0b85c9e8 100644
> --- a/gdb/testsuite/gdb.python/py-doc-reformat.exp
> +++ b/gdb/testsuite/gdb.python/py-doc-reformat.exp
> @@ -126,7 +126,7 @@ proc test { input_docs expected_output } {
> -re "^This is the set doc line\r\n" {
> exp_continue
> }
> - -re "^$expected_output\r\n$::gdb_prompt $" {
> + -re "^$expected_output\r\nAvailable options are:\r\n on, off, \r\n$::gdb_prompt $" {
> pass $gdb_test_name
> }
> }
> diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp
> index e8b0ef24efb..aec00d527b2 100644
> --- a/gdb/testsuite/gdb.python/py-parameter.exp
> +++ b/gdb/testsuite/gdb.python/py-parameter.exp
> @@ -367,7 +367,10 @@ proc_with_prefix test_empty_doc_parameter {} {
> # Setting the __doc__ string to empty means GDB will completely
> # elide it from the output.
> gdb_test "help set print test-empty-doc-param" \
> - "^Set the current value of 'print test-empty-doc-param'\\."
> + [multi_line \
> + "^Set the current value of 'print test-empty-doc-param'\\." \
> + "Available options are:" \
> + " on, off, "]
>
> gdb_test_multiline "None __doc__ parameter" \
> "python" "" \
> @@ -384,7 +387,9 @@ proc_with_prefix test_empty_doc_parameter {} {
> gdb_test "help set print test-none-doc-param" \
> [multi_line \
> "^Set the current value of 'print test-none-doc-param'\\." \
> - "This command is not documented\\."]
> + "This command is not documented\\." \
> + "Available options are:" \
> + " on, off, "]
> }
>
> # Test a parameter in which the set_doc/show_doc strings are either
> @@ -406,7 +411,9 @@ proc_with_prefix test_empty_set_show_doc_parameter {} {
> gdb_test "help set print test-empty-set-show-param" \
> [multi_line \
> "^Set the current value of 'print test-empty-set-show-param'\\." \
> - "This command is not documented\\."]
> + "This command is not documented\\." \
> + "Available options are:" \
> + " on, off, "]
>
> gdb_test "help show print test-empty-set-show-param" \
> [multi_line \
> @@ -429,7 +436,9 @@ proc_with_prefix test_empty_set_show_doc_parameter {} {
> gdb_test "help set print test-none-set-show-param" \
> [multi_line \
> "^Set the current value of 'print test-none-set-show-param'\\." \
> - "This command is not documented\\."]
> + "This command is not documented\\." \
> + "Available options are:" \
> + " on, off, "]
>
> gdb_test "help show print test-none-set-show-param" \
> [multi_line \
> --
> 2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 1/2] gdb: improve help text for set commands with limited options
2026-03-17 13:58 ` Andrew Burgess
@ 2026-04-16 18:17 ` Guinevere Larsen
0 siblings, 0 replies; 6+ messages in thread
From: Guinevere Larsen @ 2026-04-16 18:17 UTC (permalink / raw)
To: Andrew Burgess, gdb-patches; +Cc: Ciaran Woodward
On 3/17/26 10:58 AM, Andrew Burgess wrote:
> Guinevere Larsen <guinevere@redhat.com> writes:
>
>> Some "set" commands only allow a select few options, such as the "set
>> architecture" command, however, there is no way for a user to know which
>> options are allowed without trying to set something and getting an
>> error. This commit improves the situation by making the help command list
>> all the available options.
> I was experimenting with this patch looking at how other enum set
> commands, checking that their output also looks good with this new
> feature, and I ran into 'help set demangle-style'. It's output (before
> this patch) is:
>
> (gdb) help set demangle-style
> Set the current C++ demangling style.
> Use `set demangle-style' without arguments for a list of demangling styles.
>
> And indeed:
>
> (gdb) set demangle-style
> Requires an argument. Valid arguments are none, auto, gnu-v3, java, gnat, dlang, rust.
>
> And:
>
> (gdb) set architecture
> Requires an argument. Valid arguments are ARC600, A6, ARC601, ARC700, A7, ... etc ...
>
> So there is an existing way to get an option list. Maybe what's missing
> here is that most enum command help texts don't reference this mechanism.
>
> What if, instead of listing all the options, which can get pretty long,
> you auto-added a sentence similar to the one seen in the demangle-style
> output? E.g. "Use `set <command>` without arguments for a list of
> available options." This would keep the help text less cluttered, but
> would give clear guidance on how to get the option list.
My issue with this approach is that this is an error message. Meaning
that in most terminals the output will actually be:
❌️ Requires an argument. Valid arguments are none, auto, gnu-v3, java,
gnat, dlang, rust.
Notice the ❌️ emoji, making it clear this is an error. My view is that
instructing the user to run a command that returns an error is not great
UX, and that not having the available options in the help text is pretty
unintuitive. I knew of this option from the first iteration of adding
this to the help text, but I just think it is much more intuitive to
explain everything in the help.
>
> Just my thoughts.
>
> Thanks,
> Andrew
>
>
>> Reviewed-By: Ciaran Woodward <ciaranwoodward@xmos.com>
>> ---
>> gdb/cli/cli-decode.c | 12 ++++++++++++
>> gdb/testsuite/gdb.base/help.exp | 9 +++++++++
>> gdb/testsuite/gdb.python/py-doc-reformat.exp | 2 +-
>> gdb/testsuite/gdb.python/py-parameter.exp | 17 +++++++++++++----
>> 4 files changed, 35 insertions(+), 5 deletions(-)
>>
>> diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
>> index 285f5f1f0c4..5a580387fee 100644
>> --- a/gdb/cli/cli-decode.c
>> +++ b/gdb/cli/cli-decode.c
>> @@ -1876,6 +1876,18 @@ help_cmd (const char *command, struct ui_file *stream)
>> /* Be sure to expand TABs in the documentation. */
>> tab_expansion_file expander (stream);
>> gdb_puts (c->doc, &expander);
>> + if (c->enums != nullptr)
>> + {
>> + gdb_puts ("\nAvailable options are:\n", &expander);
>> + const char * const *opt = c->enums;
>> + gdb_printf (&expander, " ");
>> + while (opt != nullptr && *opt != nullptr)
> The 'opt != nullptr' check here seems redundant. We already check
> 'c->enums != nullptr' before entering this block, and I think if 'opt++'
> causes us to reach nullptr then things have probably gone seriously
> wrong.
>
> You could fold the setup of 'opt', the condition check, and the
> increment into a for loop like:
>
> for (const char * const *opt = c->enums;
> *opt != nullptr;
> opt++)
> { ... }
Good point, I'll do this
>
>> + {
>> + expander.wrap_here (2);
>> + gdb_printf (&expander, "%s, ", *opt);
>> + opt++;
> Given the simplified loop condition check, you could solve the trailing
> ', ' like:
and this.
--
Cheers,
Guinevere Larsen
It/she
>
> {
> expander.wrap_here (2);
> const char *suffix = (*(opt + 1) == nullptr) ? "." : ", ";
> gdb_printf (&expander, "%s%s", *opt, suffix);
> }
>
>> + }
>> + }
>> }
>> else
>> {
>> diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp
>> index a8c55721ef2..fca8522faa0 100644
>> --- a/gdb/testsuite/gdb.base/help.exp
>> +++ b/gdb/testsuite/gdb.base/help.exp
>> @@ -174,3 +174,12 @@ gdb_test "help mybt" " alias mybt = backtrace \[\r\n\]+An alias of command backt
>> # Check pre-defined aliases cannot be documented.
>> gdb_test "document where" "Alias \"where\" is built-in.*" \
>> "documenting builtin where alias disallowed"
>> +
>> +# Check help of a command with limited options lists all the options
>> +# as expected. The command "set breakpoint condition-evaluation" was
>> +# chosen because it has few options and isn't dependent on configure
>> +# options.
>> +gdb_test "help set breakpoint condition-evaluation" \
>> + [multi_line ".*" \
>> + "Available options are:" \
>> + " auto, host, target, "]
>> diff --git a/gdb/testsuite/gdb.python/py-doc-reformat.exp b/gdb/testsuite/gdb.python/py-doc-reformat.exp
>> index 8b0a27f4937..a3c0b85c9e8 100644
>> --- a/gdb/testsuite/gdb.python/py-doc-reformat.exp
>> +++ b/gdb/testsuite/gdb.python/py-doc-reformat.exp
>> @@ -126,7 +126,7 @@ proc test { input_docs expected_output } {
>> -re "^This is the set doc line\r\n" {
>> exp_continue
>> }
>> - -re "^$expected_output\r\n$::gdb_prompt $" {
>> + -re "^$expected_output\r\nAvailable options are:\r\n on, off, \r\n$::gdb_prompt $" {
>> pass $gdb_test_name
>> }
>> }
>> diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp
>> index e8b0ef24efb..aec00d527b2 100644
>> --- a/gdb/testsuite/gdb.python/py-parameter.exp
>> +++ b/gdb/testsuite/gdb.python/py-parameter.exp
>> @@ -367,7 +367,10 @@ proc_with_prefix test_empty_doc_parameter {} {
>> # Setting the __doc__ string to empty means GDB will completely
>> # elide it from the output.
>> gdb_test "help set print test-empty-doc-param" \
>> - "^Set the current value of 'print test-empty-doc-param'\\."
>> + [multi_line \
>> + "^Set the current value of 'print test-empty-doc-param'\\." \
>> + "Available options are:" \
>> + " on, off, "]
>>
>> gdb_test_multiline "None __doc__ parameter" \
>> "python" "" \
>> @@ -384,7 +387,9 @@ proc_with_prefix test_empty_doc_parameter {} {
>> gdb_test "help set print test-none-doc-param" \
>> [multi_line \
>> "^Set the current value of 'print test-none-doc-param'\\." \
>> - "This command is not documented\\."]
>> + "This command is not documented\\." \
>> + "Available options are:" \
>> + " on, off, "]
>> }
>>
>> # Test a parameter in which the set_doc/show_doc strings are either
>> @@ -406,7 +411,9 @@ proc_with_prefix test_empty_set_show_doc_parameter {} {
>> gdb_test "help set print test-empty-set-show-param" \
>> [multi_line \
>> "^Set the current value of 'print test-empty-set-show-param'\\." \
>> - "This command is not documented\\."]
>> + "This command is not documented\\." \
>> + "Available options are:" \
>> + " on, off, "]
>>
>> gdb_test "help show print test-empty-set-show-param" \
>> [multi_line \
>> @@ -429,7 +436,9 @@ proc_with_prefix test_empty_set_show_doc_parameter {} {
>> gdb_test "help set print test-none-set-show-param" \
>> [multi_line \
>> "^Set the current value of 'print test-none-set-show-param'\\." \
>> - "This command is not documented\\."]
>> + "This command is not documented\\." \
>> + "Available options are:" \
>> + " on, off, "]
>>
>> gdb_test "help show print test-none-set-show-param" \
>> [multi_line \
>> --
>> 2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-04-16 18:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-10 14:23 [PATCH v5 0/2] Add warning if the native target is not supported Guinevere Larsen
2026-03-10 14:23 ` [PATCH v5 1/2] gdb: improve help text for set commands with limited options Guinevere Larsen
2026-03-17 13:58 ` Andrew Burgess
2026-04-16 18:17 ` Guinevere Larsen
2026-03-10 14:23 ` [PATCH v5 2/2] gdb: Improve warning when no native target is available Guinevere Larsen
2026-03-17 11:29 ` Andrew Burgess
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox