[PATCH v5 1/2] gdb: improve help text for set commands with limited options

Guinevere Larsen
2026-03-10T14:26:12Z

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