gdb: make use add_setshow_prefix_cmd in gnu-nat.c

Message ID 20220106130449.1066950-1-aburgess@redhat.com
State New
Headers show
Series
  • gdb: make use add_setshow_prefix_cmd in gnu-nat.c
Related show

Commit Message

Simon Marchi via Gdb-patches Jan. 6, 2022, 1:04 p.m.
In gnu-nat.c we currently implement some set/show prefix commands
"manually", that is, we call add_prefix_cmd, and assign a set and show
function to each prefix command.

These set/show functions print an error indicating that the user
didn't type a complete command.

If we instead switch to using add_setshow_prefix_cmd then we can
delete the set/show functions, GDB provides some default functions,
which give a nice help style summary that lists all of the available
sub-commands, along with a one line summary of what each does.

Though this clearly changes the existing behaviour, I think this
change is acceptable as the new behaviour is more inline with other
set/show prefix commands, and the new behaviour is more informative.

This change will conflict with Tom's change here:

  https://sourceware.org/pipermail/gdb-patches/2022-January/184724.html

Where Tom changes the set/show functions that I delete.  My suggestion
is that the set/show functions still be deleted even after Tom's
patch (or instead of Tom's patch).

For testing I've build GDB on GNU/Hurd, and manually tested these
functions.  I did a grep over the testsuite, and don't believe the
existing error messages are being checked for in any tests.
---
 gdb/gnu-nat.c | 59 ++++++++++++---------------------------------------
 1 file changed, 13 insertions(+), 46 deletions(-)

-- 
2.25.4

Comments

Tom Tromey Jan. 6, 2022, 3:33 p.m. | #1
>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:


Andrew> Though this clearly changes the existing behaviour, I think this
Andrew> change is acceptable as the new behaviour is more inline with other
Andrew> set/show prefix commands, and the new behaviour is more informative.

This looks good to me.  Thanks for doing this.

Tom
Simon Marchi via Gdb-patches Jan. 6, 2022, 3:45 p.m. | #2
* Tom Tromey <tom@tromey.com> [2022-01-06 08:33:36 -0700]:

> >>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:

> 

> Andrew> Though this clearly changes the existing behaviour, I think this

> Andrew> change is acceptable as the new behaviour is more inline with other

> Andrew> set/show prefix commands, and the new behaviour is more informative.

> 

> This looks good to me.  Thanks for doing this.


Thanks, I pushed this.

Andrew

Patch

diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index b7b486904e8..b39dfaf009c 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -2701,38 +2701,6 @@  struct cmd_list_element *show_thread_cmd_list = NULL;
 struct cmd_list_element *set_thread_default_cmd_list = NULL;
 struct cmd_list_element *show_thread_default_cmd_list = NULL;
 
-static void
-set_thread_cmd (const char *args, int from_tty)
-{
-  fprintf_filtered (gdb_stderr,
-		    "\"set thread\" must be followed by the "
-		    "name of a thread property, or \"default\".\n");
-}
-
-static void
-show_thread_cmd (const char *args, int from_tty)
-{
-  fprintf_unfiltered (gdb_stderr,
-		      "\"show thread\" must be followed by the "
-		      "name of a thread property, or \"default\".\n");
-}
-
-static void
-set_thread_default_cmd (const char *args, int from_tty)
-{
-  fprintf_unfiltered (gdb_stderr,
-		      "\"set thread default\" must be followed "
-		      "by the name of a thread property.\n");
-}
-
-static void
-show_thread_default_cmd (const char *args, int from_tty)
-{
-  fprintf_unfiltered (gdb_stderr,
-		      "\"show thread default\" must be followed "
-		      "by the name of a thread property.\n");
-}
-
 static int
 parse_int_arg (const char *args, const char *cmd_prefix)
 {
@@ -3417,20 +3385,19 @@  thread_takeover_sc_cmd (const char *args, int from_tty)
 static void
 add_thread_commands (void)
 {
-  add_prefix_cmd ("thread", no_class, set_thread_cmd,
-		  _("Command prefix for setting thread properties."),
-		  &set_thread_cmd_list, 0, &setlist);
-  add_prefix_cmd ("default", no_class, show_thread_cmd,
-		  _("Command prefix for setting default thread properties."),
-		  &set_thread_default_cmd_list, 0,
-		  &set_thread_cmd_list);
-  add_prefix_cmd ("thread", no_class, set_thread_default_cmd,
-		  _("Command prefix for showing thread properties."),
-		  &show_thread_cmd_list, 0, &showlist);
-  add_prefix_cmd ("default", no_class, show_thread_default_cmd,
-		  _("Command prefix for showing default thread properties."),
-		  &show_thread_default_cmd_list, 0,
-		  &show_thread_cmd_list);
+  add_setshow_prefix_cmd ("thread", no_class,
+			  _("Command prefix for setting thread properties."),
+			  _("Command prefix for showing thread properties."),
+			  &set_thread_cmd_list,
+			  &show_thread_cmd_list,
+			  &setlist, &showlist);
+
+  add_setshow_prefix_cmd ("default", no_class,
+			  _("Command prefix for setting default thread properties."),
+			  _("Command prefix for showing default thread properties."),
+			  &set_thread_default_cmd_list,
+			  &show_thread_default_cmd_list,
+			  &set_thread_cmd_list, &show_thread_cmd_list);
 
   add_cmd ("pause", class_run, set_thread_pause_cmd, _("\
 Set whether the current thread is suspended while gdb has control.\n\