Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Guinevere Larsen <guinevere@redhat.com>
To: gdb-patches@sourceware.org
Cc: Guinevere Larsen <guinevere@redhat.com>,
	Ciaran Woodward <ciaranwoodward@xmos.com>
Subject: [PATCH v5 1/2] gdb: improve help text for set commands with limited options
Date: Tue, 10 Mar 2026 11:23:23 -0300	[thread overview]
Message-ID: <20260310142323.2619350-3-guinevere@redhat.com> (raw)
In-Reply-To: <20260310142323.2619350-2-guinevere@redhat.com>

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


  reply	other threads:[~2026-03-10 14:26 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 ` Guinevere Larsen [this message]
2026-03-17 13:58   ` [PATCH v5 1/2] gdb: improve help text for set commands with limited options 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

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=20260310142323.2619350-3-guinevere@redhat.com \
    --to=guinevere@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