From: Guinevere Larsen <guinevere@redhat.com>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Cc: Ciaran Woodward <ciaranwoodward@xmos.com>
Subject: Re: [PATCH v5 1/2] gdb: improve help text for set commands with limited options
Date: Thu, 16 Apr 2026 15:17:27 -0300 [thread overview]
Message-ID: <956dbb06-de36-411d-8f34-7582d12d4e3b@redhat.com> (raw)
In-Reply-To: <87bjgm7e1x.fsf@redhat.com>
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
next prev parent reply other threads:[~2026-04-16 18:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=956dbb06-de36-411d-8f34-7582d12d4e3b@redhat.com \
--to=guinevere@redhat.com \
--cc=aburgess@redhat.com \
--cc=ciaranwoodward@xmos.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox