public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: fix error message for $_gdb_maint_setting
@ 2023-05-11  8:57 Andrew Burgess
  2023-05-11 17:55 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Burgess @ 2023-05-11  8:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

I spotted this behaviour:

  (gdb) p $_gdb_maint_setting("xxx")
  First argument of $_gdb_maint_setting must be a valid setting of the 'show' command.

Notice that GDB claims I need to use a setting from the 'show'
command, which isn't correct for $_gdb_maint_setting, in this case I
need to use a setting from 'maintenance show'.

This same issue is present for $_gdb_maint_setting_str.

This commit fixes this minor issue.
---
 gdb/cli/cli-cmds.c                  | 12 ++++++++++--
 gdb/testsuite/gdb.base/settings.exp | 15 +++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index d466cc6c34d..b7b65303a0b 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -2219,8 +2219,16 @@ setting_cmd (const char *fnname, struct cmd_list_element *showlist,
   cmd_list_element *cmd = lookup_cmd (&a0, showlist, "", NULL, -1, 0);
 
   if (cmd == nullptr || cmd->type != show_cmd)
-    error (_("First argument of %s must be a "
-	     "valid setting of the 'show' command."), fnname);
+    {
+      gdb_assert (showlist->prefix != nullptr);
+      std::vector<std::string> components
+	= showlist->prefix->command_components ();
+      std::string full_name = components[0];
+      for (int i = 1; i < components.size (); ++i)
+	full_name += " " + components[i];
+      error (_("First argument of %s must be a valid setting of the "
+	       "'%s' command."), fnname, full_name.c_str ());
+    }
 
   return cmd;
 }
diff --git a/gdb/testsuite/gdb.base/settings.exp b/gdb/testsuite/gdb.base/settings.exp
index eb127d246d2..6248ba3e495 100644
--- a/gdb/testsuite/gdb.base/settings.exp
+++ b/gdb/testsuite/gdb.base/settings.exp
@@ -625,6 +625,19 @@ proc test-string {variant} {
     test_gdb_complete_none "$show_cmd "
 }
 
+# Check that $_gdb_setting & co report the correct error strings.
+proc test-setting-error {} {
+    gdb_test {print $_gdb_setting("xxx")} \
+	"First argument of \\\$_gdb_setting must be a valid setting of the 'show' command\\."
+    gdb_test {print $_gdb_setting_str("xxx")} \
+	"First argument of \\\$_gdb_setting_str must be a valid setting of the 'show' command\\."
+
+    gdb_test {print $_gdb_maint_setting("xxx")} \
+	"First argument of \\\$_gdb_maint_setting must be a valid setting of the 'maintenance show' command\\."
+    gdb_test {print $_gdb_maint_setting_str("xxx")} \
+	"First argument of \\\$_gdb_maint_setting_str must be a valid setting of the 'maintenance show' command\\."
+}
+
 foreach variant {
     uinteger
     integer
@@ -651,3 +664,5 @@ foreach variant {
 	test-string $variant
     }
 }
+
+test-setting-error

base-commit: 16c8122639ca0948f56fce125b3ad46e122d1edc
-- 
2.25.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gdb: fix error message for $_gdb_maint_setting
  2023-05-11  8:57 [PATCH] gdb: fix error message for $_gdb_maint_setting Andrew Burgess
@ 2023-05-11 17:55 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2023-05-11 17:55 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 5/11/23 04:57, Andrew Burgess via Gdb-patches wrote:
> I spotted this behaviour:
> 
>   (gdb) p $_gdb_maint_setting("xxx")
>   First argument of $_gdb_maint_setting must be a valid setting of the 'show' command.
> 
> Notice that GDB claims I need to use a setting from the 'show'
> command, which isn't correct for $_gdb_maint_setting, in this case I
> need to use a setting from 'maintenance show'.
> 
> This same issue is present for $_gdb_maint_setting_str.
> 
> This commit fixes this minor issue.

LGTM, thanks:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-11 17:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-11  8:57 [PATCH] gdb: fix error message for $_gdb_maint_setting Andrew Burgess
2023-05-11 17:55 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).