public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/3] gdb: add add_setshow_prefix_cmd
@ 2021-09-23 13:56 Simon Marchi
  2021-09-23 13:56 ` [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options Simon Marchi
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Simon Marchi @ 2021-09-23 13:56 UTC (permalink / raw)
  To: gdb-patches

From: Simon Marchi <simon.marchi@polymtl.ca>

There's a common pattern to call add_basic_prefix_cmd and
add_show_prefix_cmd to add matching set and show commands.  Add the
add_setshow_prefix_cmd function to factor that out and use it at a few
places.

Change-Id: I6e9e90a30e9efb7b255bf839cac27b85d7069cfd
---
 gdb/ada-lang.c            | 27 +++++++++------------
 gdb/arm-tdep.c            | 13 ++++-------
 gdb/breakpoint.c          | 11 ++++-----
 gdb/btrace.c              | 34 ++++++++++++---------------
 gdb/cli/cli-cmds.c        | 23 ++++++++----------
 gdb/cli/cli-decode.c      | 22 ++++++++++++++++++
 gdb/cli/cli-logging.c     | 12 +++++-----
 gdb/cli/cli-style.c       | 16 ++++++-------
 gdb/command.h             | 25 ++++++++++++++------
 gdb/dcache.c              | 11 ++++-----
 gdb/dwarf2/read.c         | 12 ++++------
 gdb/f-lang.c              | 13 +++++------
 gdb/frame.c               | 11 ++++-----
 gdb/guile/guile.c         | 22 +++++++++---------
 gdb/i386-tdep.c           | 18 +++++---------
 gdb/language.c            | 23 ++++++++----------
 gdb/maint-test-settings.c | 17 +++++---------
 gdb/memattr.c             | 13 ++++-------
 gdb/mips-tdep.c           | 12 ++++------
 gdb/python/python.c       | 12 ++++------
 gdb/ravenscar-thread.c    | 13 +++++------
 gdb/record-btrace.c       | 49 ++++++++++++++++-----------------------
 gdb/record-full.c         | 14 +++++------
 gdb/record.c              | 21 ++++++++---------
 gdb/riscv-tdep.c          | 26 ++++++++-------------
 gdb/rs6000-tdep.c         | 12 ++++------
 gdb/ser-tcp.c             | 11 ++++-----
 gdb/serial.c              | 16 ++++---------
 gdb/sh-tdep.c             |  9 +++----
 gdb/target-descriptions.c | 14 +++++------
 gdb/tui/tui-win.c         | 11 ++++-----
 gdb/typeprint.c           | 11 ++++-----
 gdb/utils.c               | 10 +++-----
 gdb/valprint.c            | 45 +++++++++++++++--------------------
 34 files changed, 280 insertions(+), 329 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 487d92be5c9..535e9c7c9f5 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13530,13 +13530,12 @@ _initialize_ada_language ()
 {
   initialize_ada_catchpoint_ops ();
 
-  add_basic_prefix_cmd ("ada", no_class,
-			_("Prefix command for changing Ada-specific settings."),
-			&set_ada_list, 0, &setlist);
-
-  add_show_prefix_cmd ("ada", no_class,
-		       _("Generic command for showing Ada-specific settings."),
-		       &show_ada_list, 0, &showlist);
+  add_setshow_prefix_cmd
+    ("ada", no_class,
+     _("Prefix command for changing Ada-specific settings."),
+     _("Generic command for showing Ada-specific settings."),
+     &set_ada_list, &show_ada_list,
+     &setlist, &showlist);
 
   add_setshow_boolean_cmd ("trust-PAD-over-XVS", class_obscure,
 			   &trust_pad_over_xvs, _("\
@@ -13613,15 +13612,11 @@ Usage: info exceptions [REGEXP]\n\
 If a regular expression is passed as an argument, only those matching\n\
 the regular expression are listed."));
 
-  add_basic_prefix_cmd ("ada", class_maintenance,
-			_("Set Ada maintenance-related variables."),
-			&maint_set_ada_cmdlist,
-			0/*allow-unknown*/, &maintenance_set_cmdlist);
-
-  add_show_prefix_cmd ("ada", class_maintenance,
-		       _("Show Ada maintenance-related variables."),
-		       &maint_show_ada_cmdlist,
-		       0/*allow-unknown*/, &maintenance_show_cmdlist);
+  add_setshow_prefix_cmd ("ada", class_maintenance,
+			  _("Set Ada maintenance-related variables."),
+			  _("Show Ada maintenance-related variables."),
+			  &maint_set_ada_cmdlist, &maint_show_ada_cmdlist,
+			  &maintenance_set_cmdlist, &maintenance_show_cmdlist);
 
   add_setshow_boolean_cmd
     ("ignore-descriptive-types", class_maintenance,
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index ab6999ae209..8b020190c59 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9564,14 +9564,11 @@ _initialize_arm_tdep ()
 				  arm_elf_osabi_sniffer);
 
   /* Add root prefix command for all "set arm"/"show arm" commands.  */
-  add_basic_prefix_cmd ("arm", no_class,
-			_("Various ARM-specific commands."),
-			&setarmcmdlist, 0, &setlist);
-
-  add_show_prefix_cmd ("arm", no_class,
-		       _("Various ARM-specific commands."),
-		       &showarmcmdlist, 0, &showlist);
-
+  add_setshow_prefix_cmd ("arm", no_class,
+			  _("Various ARM-specific commands."),
+			  _("Various ARM-specific commands."),
+			  &setarmcmdlist, &showarmcmdlist,
+			  &setlist, &showlist);
 
   arm_disassembler_options = xstrdup ("reg-names-std");
   const disasm_options_t *disasm_options
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 10b28c97be7..1eb6d499b5c 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -15908,18 +15908,17 @@ Use the 'source' command in another debug session to restore them."),
   c = add_com_alias ("save-tracepoints", save_tracepoints_cmd, class_trace, 0);
   deprecate_cmd (c, "save tracepoints");
 
-  add_basic_prefix_cmd ("breakpoint", class_maintenance, _("\
+  add_setshow_prefix_cmd ("breakpoint", class_maintenance,
+			  _("\
 Breakpoint specific settings.\n\
 Configure various breakpoint-specific variables such as\n\
 pending breakpoint behavior."),
-			&breakpoint_set_cmdlist,
-			0/*allow-unknown*/, &setlist);
-  add_show_prefix_cmd ("breakpoint", class_maintenance, _("\
+			  _("\
 Breakpoint specific settings.\n\
 Configure various breakpoint-specific variables such as\n\
 pending breakpoint behavior."),
-		       &breakpoint_show_cmdlist,
-		       0/*allow-unknown*/, &showlist);
+			  &breakpoint_set_cmdlist, &breakpoint_show_cmdlist,
+			  &setlist, &showlist);
 
   add_setshow_auto_boolean_cmd ("pending", no_class,
 				&pending_break_support, _("\
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 6a7b4cfcfc0..f12b1554d65 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -3455,25 +3455,21 @@ _initialize_btrace ()
 			_("Branch tracing maintenance commands."),
 			&maint_btrace_cmdlist, 0, &maintenancelist);
 
-  add_basic_prefix_cmd ("btrace", class_maintenance, _("\
-Set branch tracing specific variables."),
-			&maint_btrace_set_cmdlist,
-			0, &maintenance_set_cmdlist);
-
-  add_basic_prefix_cmd ("pt", class_maintenance, _("\
-Set Intel Processor Trace specific variables."),
-			&maint_btrace_pt_set_cmdlist,
-			0, &maint_btrace_set_cmdlist);
-
-  add_show_prefix_cmd ("btrace", class_maintenance, _("\
-Show branch tracing specific variables."),
-		       &maint_btrace_show_cmdlist,
-		       0, &maintenance_show_cmdlist);
-
-  add_show_prefix_cmd ("pt", class_maintenance, _("\
-Show Intel Processor Trace specific variables."),
-		       &maint_btrace_pt_show_cmdlist,
-		       0, &maint_btrace_show_cmdlist);
+  add_setshow_prefix_cmd ("btrace", class_maintenance,
+			  _("Set branch tracing specific variables."),
+			  _("Show branch tracing specific variables."),
+			  &maint_btrace_set_cmdlist,
+			  &maint_btrace_show_cmdlist,
+			  &maintenance_set_cmdlist,
+			  &maintenance_show_cmdlist);
+
+  add_setshow_prefix_cmd ("pt", class_maintenance,
+			  _("Set Intel Processor Trace specific variables."),
+			  _("Show Intel Processor Trace specific variables."),
+			  &maint_btrace_pt_set_cmdlist,
+			  &maint_btrace_pt_show_cmdlist,
+			  &maint_btrace_set_cmdlist,
+			  &maint_btrace_show_cmdlist);
 
   add_setshow_boolean_cmd ("skip-pad", class_maintenance,
 			   &maint_btrace_pt_skip_pad, _("\
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 5ff0b77eb68..91bad78d40c 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -2352,12 +2352,11 @@ Show verbosity."), NULL,
 			   show_info_verbose,
 			   &setlist, &showlist);
 
-  add_basic_prefix_cmd ("history", class_support, _("\
-Generic command for setting command history parameters."),
-			&sethistlist, 0, &setlist);
-  add_show_prefix_cmd ("history", class_support, _("\
-Generic command for showing command history parameters."),
-		       &showhistlist, 0, &showlist);
+  add_setshow_prefix_cmd
+    ("history", class_support,
+     _("Generic command for setting command history parameters."),
+     _("Generic command for showing command history parameters."),
+     &sethistlist, &showhistlist, &setlist, &showlist);
 
   add_setshow_boolean_cmd ("expansion", no_class, &history_expansion_p, _("\
 Set history expansion on command input."), _("\
@@ -2451,13 +2450,11 @@ the previous command number shown."),
   add_cmd ("configuration", no_set_class, show_configuration,
 	   _("Show how GDB was configured at build time."), &showlist);
 
-  add_basic_prefix_cmd ("debug", no_class,
-			_("Generic command for setting gdb debugging flags."),
-			&setdebuglist, 0, &setlist);
-
-  add_show_prefix_cmd ("debug", no_class,
-		       _("Generic command for showing gdb debugging flags."),
-		       &showdebuglist, 0, &showlist);
+  add_setshow_prefix_cmd ("debug", no_class,
+			  _("Generic command for setting gdb debugging flags."),
+			  _("Generic command for showing gdb debugging flags."),
+			  &setdebuglist, &showdebuglist,
+			  &setlist, &showlist);
 
   cmd_list_element *shell_cmd
     = add_com ("shell", class_support, shell_command, _("\
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 06f3de0f038..0d51dfdeaa9 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -407,6 +407,28 @@ add_show_prefix_cmd (const char *name, enum command_class theclass,
   return cmd;
 }
 
+/* See command.h.  */
+
+set_show_commands
+add_setshow_prefix_cmd (const char *name, command_class theclass,
+			const char *set_doc, const char *show_doc,
+			cmd_list_element **set_subcommands_list,
+			cmd_list_element **show_subcommands_list,
+			cmd_list_element **set_list,
+			cmd_list_element **show_list)
+{
+  set_show_commands cmds;
+
+  cmds.set = add_basic_prefix_cmd (name, theclass, set_doc,
+				   set_subcommands_list, 0,
+				   set_list);
+  cmds.show = add_show_prefix_cmd (name, theclass, show_doc,
+				   show_subcommands_list, 0,
+				   show_list);
+
+  return cmds;
+}
+
 /* Like ADD_PREFIX_CMD but sets the suppress_notification pointer on the
    new command list element.  */
 
diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c
index dfedd7599a2..c14c53a5d5b 100644
--- a/gdb/cli/cli-logging.c
+++ b/gdb/cli/cli-logging.c
@@ -171,12 +171,12 @@ _initialize_cli_logging ()
 {
   static struct cmd_list_element *set_logging_cmdlist, *show_logging_cmdlist;
 
-  add_basic_prefix_cmd ("logging", class_support,
-			_("Set logging options."), &set_logging_cmdlist,
-			0, &setlist);
-  add_show_prefix_cmd ("logging", class_support,
-		       _("Show logging options."), &show_logging_cmdlist,
-		       0, &showlist);
+  add_setshow_prefix_cmd ("logging", class_support,
+			  _("Set logging options."),
+			  _("Show logging options."),
+			  &set_logging_cmdlist, &show_logging_cmdlist,
+			  &setlist, &showlist);
+
   add_setshow_boolean_cmd ("overwrite", class_support, &logging_overwrite, _("\
 Set whether logging overwrites or appends to the log file."), _("\
 Show whether logging overwrites or appends to the log file."), _("\
diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c
index aca19c51b84..f7e1a844ec0 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -226,10 +226,9 @@ cli_style_option::add_setshow_commands (enum command_class theclass,
 					struct cmd_list_element **show_list,
 					bool skip_intensity)
 {
-  add_basic_prefix_cmd (m_name, no_class, prefix_doc, &m_set_list,
-			0, set_list);
-  add_show_prefix_cmd (m_name, no_class, prefix_doc, &m_show_list,
-		       0, show_list);
+  add_setshow_prefix_cmd (m_name, theclass, prefix_doc, prefix_doc,
+			  &m_set_list, &m_show_list, set_list, show_list);
+
   set_show_commands commands;
 
   commands = add_setshow_enum_cmd
@@ -306,14 +305,15 @@ void _initialize_cli_style ();
 void
 _initialize_cli_style ()
 {
-  add_basic_prefix_cmd ("style", no_class, _("\
+  add_setshow_prefix_cmd ("style", no_class,
+			  _("\
 Style-specific settings.\n\
 Configure various style-related variables, such as colors"),
-		  &style_set_list, 0, &setlist);
-  add_show_prefix_cmd ("style", no_class, _("\
+			  _("\
 Style-specific settings.\n\
 Configure various style-related variables, such as colors"),
-		  &style_show_list, 0, &showlist);
+			  &style_set_list, &style_show_list,
+			  &setlist, &showlist);
 
   add_setshow_boolean_cmd ("enabled", no_class, &cli_styling, _("\
 Set whether CLI styling is enabled."), _("\
diff --git a/gdb/command.h b/gdb/command.h
index baf34401a07..acd4b0d3c9c 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -158,6 +158,13 @@ extern bool valid_user_defined_cmd_name_p (const char *name);
 
 extern bool valid_cmd_char_p (int c);
 
+/* Return value type for the add_setshow_* functions.  */
+
+struct set_show_commands
+{
+  cmd_list_element *set, *show;
+};
+
 /* Const-correct variant of the above.  */
 
 extern struct cmd_list_element *add_cmd (const char *, enum command_class,
@@ -204,6 +211,17 @@ extern struct cmd_list_element *add_show_prefix_cmd
   (const char *, enum command_class, const char *, struct cmd_list_element **,
    int, struct cmd_list_element **);
 
+/* Add matching set and show commands using add_basic_prefix_cmd and
+   add_show_prefix_cmd.  */
+
+extern set_show_commands add_setshow_prefix_cmd
+  (const char *name, command_class theclass, const char *set_doc,
+   const char *show_doc,
+   cmd_list_element **set_subcommands_list,
+   cmd_list_element **show_subcommands_list,
+   cmd_list_element **set_list,
+   cmd_list_element **show_list);
+
 extern struct cmd_list_element *add_prefix_cmd_suppress_notification
 			(const char *name, enum command_class theclass,
 			 cmd_simple_func_ftype *fun,
@@ -392,13 +410,6 @@ typedef void (show_value_ftype) (struct ui_file *file,
    instead print the value out directly.  */
 extern show_value_ftype deprecated_show_value_hack;
 
-/* Return value type for the add_setshow_* functions.  */
-
-struct set_show_commands
-{
-  cmd_list_element *set, *show;
-};
-
 extern set_show_commands add_setshow_enum_cmd
   (const char *name, command_class theclass, const char *const *enumlist,
    const char **var, const char *set_doc, const char *show_doc,
diff --git a/gdb/dcache.c b/gdb/dcache.c
index 50b3854fe69..189f3872e9c 100644
--- a/gdb/dcache.c
+++ b/gdb/dcache.c
@@ -694,13 +694,12 @@ With no arguments, this command prints the cache configuration and a\n\
 summary of each line in the cache.  With an argument, dump\"\n\
 the contents of the given line."));
 
-  add_basic_prefix_cmd ("dcache", class_obscure, _("\
+  add_setshow_prefix_cmd ("dcache", class_obscure,
+			  _("\
 Use this command to set number of lines in dcache and line-size."),
-			&dcache_set_list, /*allow_unknown*/0, &setlist);
-  add_show_prefix_cmd ("dcache", class_obscure, _("\
-Show dcachesettings."),
-		       &dcache_show_list, /*allow_unknown*/0,
-		       &showlist);
+			  ("Show dcache settings."),
+			  &dcache_set_list, &dcache_show_list,
+			  &setlist, &showlist);
 
   add_setshow_zuinteger_cmd ("line-size", class_obscure,
 			     &dcache_line_size, _("\
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 3c81ac6b7b5..e61e2ef46f0 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -24879,17 +24879,15 @@ void _initialize_dwarf2_read ();
 void
 _initialize_dwarf2_read ()
 {
-  add_basic_prefix_cmd ("dwarf", class_maintenance, _("\
+  add_setshow_prefix_cmd ("dwarf", class_maintenance,
+			  _("\
 Set DWARF specific variables.\n\
 Configure DWARF variables such as the cache size."),
-			&set_dwarf_cmdlist,
-			0/*allow-unknown*/, &maintenance_set_cmdlist);
-
-  add_show_prefix_cmd ("dwarf", class_maintenance, _("\
+			  _("\
 Show DWARF specific variables.\n\
 Show DWARF variables such as the cache size."),
-		       &show_dwarf_cmdlist,
-		       0/*allow-unknown*/, &maintenance_show_cmdlist);
+			  &set_dwarf_cmdlist, &show_dwarf_cmdlist,
+			  &maintenance_set_cmdlist, &maintenance_show_cmdlist);
 
   add_setshow_zinteger_cmd ("max-cache-age", class_obscure,
 			    &dwarf_max_cache_age, _("\
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 16ec9e04044..904c805abbc 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1683,13 +1683,12 @@ _initialize_f_language ()
 {
   f_type_data = gdbarch_data_register_post_init (build_fortran_types);
 
-  add_basic_prefix_cmd ("fortran", no_class,
-			_("Prefix command for changing Fortran-specific settings."),
-			&set_fortran_list, 0, &setlist);
-
-  add_show_prefix_cmd ("fortran", no_class,
-		       _("Generic command for showing Fortran-specific settings."),
-		       &show_fortran_list, 0, &showlist);
+  add_setshow_prefix_cmd
+    ("fortran", no_class,
+     _("Prefix command for changing Fortran-specific settings."),
+     _("Generic command for showing Fortran-specific settings."),
+     &set_fortran_list, &show_fortran_list,
+     &setlist, &showlist);
 
   add_setshow_boolean_cmd ("repack-array-slices", class_vars,
 			   &repack_array_slices, _("\
diff --git a/gdb/frame.c b/gdb/frame.c
index d28944075ed..256a30cb49c 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -3082,16 +3082,15 @@ _initialize_frame ()
   gdb::observers::target_changed.attach (frame_observer_target_changed,
 					 "frame");
 
-  add_basic_prefix_cmd ("backtrace", class_maintenance, _("\
+  add_setshow_prefix_cmd ("backtrace", class_maintenance,
+			  _("\
 Set backtrace specific variables.\n\
 Configure backtrace variables such as the backtrace limit"),
-			&set_backtrace_cmdlist,
-			0/*allow-unknown*/, &setlist);
-  add_show_prefix_cmd ("backtrace", class_maintenance, _("\
+			  _("\
 Show backtrace specific variables.\n\
 Show backtrace variables such as the backtrace limit."),
-		       &show_backtrace_cmdlist,
-		       0/*allow-unknown*/, &showlist);
+			  &set_backtrace_cmdlist, &show_backtrace_cmdlist,
+			  &setlist, &showlist);
 
   add_setshow_uinteger_cmd ("limit", class_obscure,
 			    &user_set_backtrace_options.backtrace_limit, _("\
diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c
index a28dee37ed8..9b44e546da1 100644
--- a/gdb/guile/guile.c
+++ b/gdb/guile/guile.c
@@ -780,17 +780,17 @@ This command is only a placeholder.")
 	   );
   add_com_alias ("gu", guile_cmd_element, class_obscure, 1);
 
-  cmd_list_element *set_guile_cmd
-    = add_basic_prefix_cmd ("guile", class_obscure,
-			    _("Prefix command for Guile preference settings."),
-			    &set_guile_list, 0, &setlist);
-  add_alias_cmd ("gu", set_guile_cmd, class_obscure, 1, &setlist);
-
-  cmd_list_element *show_guile_cmd
-    = add_show_prefix_cmd ("guile", class_obscure,
-			   _("Prefix command for Guile preference settings."),
-			   &show_guile_list, 0, &showlist);
-  add_alias_cmd ("gu", show_guile_cmd, class_obscure, 1, &showlist);
+  set_show_commands setshow_guile_cmds
+    = add_setshow_prefix_cmd ("guile", class_obscure,
+			      _("\
+Prefix command for Guile preference settings."),
+			      _("\
+Prefix command for Guile preference settings."),
+			      &set_guile_list, &show_guile_list,
+			      &setlist, &showlist);
+
+  add_alias_cmd ("gu", setshow_guile_cmds.set, class_obscure, 1, &setlist);
+  add_alias_cmd ("gu", setshow_guile_cmds.show, class_obscure, 1, &showlist);
 
   cmd_list_element *info_guile_cmd
     = add_basic_prefix_cmd ("guile", class_obscure,
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index a9c42928195..f6e3b0d0804 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -9042,19 +9042,13 @@ is \"default\"."),
 			NULL, /* FIXME: i18n: */
 			&setlist, &showlist);
 
-  /* Add "mpx" prefix for the set commands.  */
+  /* Add "mpx" prefix for the set and show commands.  */
 
-  add_basic_prefix_cmd ("mpx", class_support, _("\
-Set Intel Memory Protection Extensions specific variables."),
-			&mpx_set_cmdlist,
-			0 /* allow-unknown */, &setlist);
-
-  /* Add "mpx" prefix for the show commands.  */
-
-  add_show_prefix_cmd ("mpx", class_support, _("\
-Show Intel Memory Protection Extensions specific variables."),
-		       &mpx_show_cmdlist,
-		       0 /* allow-unknown */, &showlist);
+  add_setshow_prefix_cmd
+    ("mpx", class_support,
+     _("Set Intel Memory Protection Extensions specific variables."),
+     _("Show Intel Memory Protection Extensions specific variables."),
+     &mpx_set_cmdlist, &mpx_show_cmdlist, &setlist, &showlist);
 
   /* Add "bound" command for the show mpx commands list.  */
 
diff --git a/gdb/language.c b/gdb/language.c
index 45ce2ebcc92..73adbac853c 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -1164,19 +1164,16 @@ _initialize_language ()
 
   /* GDB commands for language specific stuff.  */
 
-  cmd_list_element *set_check_cmd
-    = add_basic_prefix_cmd ("check", no_class,
-			    _("Set the status of the type/range checker."),
-			    &setchecklist, 0, &setlist);
-  add_alias_cmd ("c", set_check_cmd, no_class, 1, &setlist);
-  add_alias_cmd ("ch", set_check_cmd, no_class, 1, &setlist);
-
-  cmd_list_element *show_check_cmd
-    = add_show_prefix_cmd ("check", no_class,
-			 _("Show the status of the type/range checker."),
-			 &showchecklist, 0, &showlist);
-  add_alias_cmd ("c", show_check_cmd, no_class, 1, &showlist);
-  add_alias_cmd ("ch", show_check_cmd, no_class, 1, &showlist);
+  set_show_commands setshow_check_cmds
+    = add_setshow_prefix_cmd ("check", no_class,
+			      _("Set the status of the type/range checker."),
+			      _("Show the status of the type/range checker."),
+			      &setchecklist, &showchecklist,
+			      &setlist, &showlist);
+  add_alias_cmd ("c", setshow_check_cmds.set, no_class, 1, &setlist);
+  add_alias_cmd ("ch", setshow_check_cmds.set, no_class, 1, &setlist);
+  add_alias_cmd ("c", setshow_check_cmds.show, no_class, 1, &showlist);
+  add_alias_cmd ("ch", setshow_check_cmds.show, no_class, 1, &showlist);
 
   add_setshow_enum_cmd ("range", class_support, type_or_range_names,
 			&range,
diff --git a/gdb/maint-test-settings.c b/gdb/maint-test-settings.c
index 0ce88905518..5e4f0691de1 100644
--- a/gdb/maint-test-settings.c
+++ b/gdb/maint-test-settings.c
@@ -85,19 +85,14 @@ _initialize_maint_test_settings ()
 {
   maintenance_test_settings_filename = xstrdup ("/foo/bar");
 
-  add_basic_prefix_cmd ("test-settings", class_maintenance,
-			_("\
+  add_setshow_prefix_cmd ("test-settings", class_maintenance,
+			  _("\
 Set GDB internal variables used for set/show command infrastructure testing."),
-			&maintenance_set_test_settings_list,
-			0/*allow-unknown*/,
-			&maintenance_set_cmdlist);
-
-  add_show_prefix_cmd ("test-settings", class_maintenance,
-		       _("\
+			  _("\
 Show GDB internal variables used for set/show command infrastructure testing."),
-		       &maintenance_show_test_settings_list,
-		       0/*allow-unknown*/,
-		       &maintenance_show_cmdlist);
+			  &maintenance_set_test_settings_list,
+			  &maintenance_show_test_settings_list,
+			  &maintenance_set_cmdlist, &maintenance_show_cmdlist);
 
   add_setshow_boolean_cmd ("boolean", class_maintenance,
 			   &maintenance_test_settings_boolean, _("\
diff --git a/gdb/memattr.c b/gdb/memattr.c
index e1c3931c262..c163ac07ebe 100644
--- a/gdb/memattr.c
+++ b/gdb/memattr.c
@@ -623,14 +623,11 @@ Do \"info mem\" to see current list of IDs."), &deletelist);
   add_info ("mem", info_mem_command,
 	    _("Memory region attributes."));
 
-  add_basic_prefix_cmd ("mem", class_vars, _("\
-Memory regions settings."),
-			&mem_set_cmdlist,
-			0/* allow-unknown */, &setlist);
-  add_show_prefix_cmd ("mem", class_vars, _("\
-Memory regions settings."),
-		       &mem_show_cmdlist,
-		       0/* allow-unknown */, &showlist);
+  add_setshow_prefix_cmd ("mem", class_vars,
+			  _("Memory regions settings."),
+			  _("Memory regions settings."),
+			  &mem_set_cmdlist, &mem_show_cmdlist,
+			  &setlist, &showlist);
 
   add_setshow_boolean_cmd ("inaccessible-by-default", no_class,
 				  &inaccessible_by_default, _("\
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index f16cdaa14cc..ef5e7fa92a3 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -8942,13 +8942,11 @@ _initialize_mips_tdep ()
   set_tdesc_property (mips_tdesc_gp64, PROPERTY_GP64, "");
 
   /* Add root prefix command for all "set mips"/"show mips" commands.  */
-  add_basic_prefix_cmd ("mips", no_class,
-			_("Various MIPS specific commands."),
-			&setmipscmdlist, 0, &setlist);
-
-  add_show_prefix_cmd ("mips", no_class,
-		       _("Various MIPS specific commands."),
-		       &showmipscmdlist, 0, &showlist);
+  add_setshow_prefix_cmd ("mips", no_class,
+			  _("Various MIPS specific commands."),
+			  _("Various MIPS specific commands."),
+			  &setmipscmdlist, &showmipscmdlist,
+			  &setlist, &showlist);
 
   /* Allow the user to override the ABI.  */
   add_setshow_enum_cmd ("abi", class_obscure, mips_abi_strings,
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 37eacefd8fc..981fdc3d800 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1977,13 +1977,11 @@ This command is only a placeholder.")
   add_com_alias ("py", python_cmd_element, class_obscure, 1);
 
   /* Add set/show python print-stack.  */
-  add_basic_prefix_cmd ("python", no_class,
-			_("Prefix command for python preference settings."),
-			&user_show_python_list, 0, &showlist);
-
-  add_show_prefix_cmd ("python", no_class,
-		       _("Prefix command for python preference settings."),
-		       &user_set_python_list, 0, &setlist);
+  add_setshow_prefix_cmd ("python", no_class,
+			  _("Prefix command for python preference settings."),
+			  _("Prefix command for python preference settings."),
+			  &user_set_python_list, &user_show_python_list,
+			  &setlist, &showlist);
 
   add_setshow_enum_cmd ("print-stack", no_class, python_excp_enums,
 			&gdbpy_should_print_stack, _("\
diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c
index 490af3a0bb4..ae5308b831b 100644
--- a/gdb/ravenscar-thread.c
+++ b/gdb/ravenscar-thread.c
@@ -717,13 +717,12 @@ _initialize_ravenscar ()
   gdb::observers::inferior_created.attach (ravenscar_inferior_created,
 					   "ravenscar-thread");
 
-  add_basic_prefix_cmd ("ravenscar", no_class,
-			_("Prefix command for changing Ravenscar-specific settings."),
-			&set_ravenscar_list, 0, &setlist);
-
-  add_show_prefix_cmd ("ravenscar", no_class,
-		       _("Prefix command for showing Ravenscar-specific settings."),
-		       &show_ravenscar_list, 0, &showlist);
+  add_setshow_prefix_cmd
+    ("ravenscar", no_class,
+     _("Prefix command for changing Ravenscar-specific settings."),
+     _("Prefix command for showing Ravenscar-specific settings."),
+     &set_ravenscar_list, &show_ravenscar_list,
+     &setlist, &showlist);
 
   add_setshow_boolean_cmd ("task-switching", class_obscure,
 			   &ravenscar_task_support, _("\
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index e2b9866d68a..f326ca41a51 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -3134,13 +3134,12 @@ This format may not be available on all processors."),
 	     &record_btrace_cmdlist);
   add_alias_cmd ("pt", record_btrace_pt_cmd, class_obscure, 1, &record_cmdlist);
 
-  add_basic_prefix_cmd ("btrace", class_support,
-			_("Set record options."), &set_record_btrace_cmdlist,
-			0, &set_record_cmdlist);
-
-  add_show_prefix_cmd ("btrace", class_support,
-		       _("Show record options."), &show_record_btrace_cmdlist,
-		       0, &show_record_cmdlist);
+  add_setshow_prefix_cmd ("btrace", class_support,
+			  _("Set record options."),
+			  _("Show record options."),
+			  &set_record_btrace_cmdlist,
+			  &show_record_btrace_cmdlist,
+			  &set_record_cmdlist, &show_record_cmdlist);
 
   add_setshow_enum_cmd ("replay-memory-access", no_class,
 			replay_memory_access_types, &replay_memory_access, _("\
@@ -3183,17 +3182,13 @@ Do not enable errata workarounds for trace decode."),
 Show the cpu to be used for trace decode."),
 	   &show_record_btrace_cmdlist);
 
-  add_basic_prefix_cmd ("bts", class_support,
-			_("Set record btrace bts options."),
-			&set_record_btrace_bts_cmdlist,
-			0,
-			&set_record_btrace_cmdlist);
-
-  add_show_prefix_cmd ("bts", class_support,
-		       _("Show record btrace bts options."),
-		       &show_record_btrace_bts_cmdlist,
-		       0,
-		       &show_record_btrace_cmdlist);
+  add_setshow_prefix_cmd ("bts", class_support,
+			  _("Set record btrace bts options."),
+			  _("Show record btrace bts options."),
+			  &set_record_btrace_bts_cmdlist,
+			  &show_record_btrace_bts_cmdlist,
+			  &set_record_btrace_cmdlist,
+			  &show_record_btrace_cmdlist);
 
   add_setshow_uinteger_cmd ("buffer-size", no_class,
 			    &record_btrace_conf.bts.size,
@@ -3209,17 +3204,13 @@ The trace buffer size may not be changed while recording."), NULL,
 			    &set_record_btrace_bts_cmdlist,
 			    &show_record_btrace_bts_cmdlist);
 
-  add_basic_prefix_cmd ("pt", class_support,
-			_("Set record btrace pt options."),
-			&set_record_btrace_pt_cmdlist,
-			0,
-			&set_record_btrace_cmdlist);
-
-  add_show_prefix_cmd ("pt", class_support,
-		       _("Show record btrace pt options."),
-		       &show_record_btrace_pt_cmdlist,
-		       0,
-		       &show_record_btrace_cmdlist);
+  add_setshow_prefix_cmd ("pt", class_support,
+			  _("Set record btrace pt options."),
+			  _("Show record btrace pt options."),
+			  &set_record_btrace_pt_cmdlist,
+			  &show_record_btrace_pt_cmdlist,
+			  &set_record_btrace_cmdlist,
+			  &show_record_btrace_cmdlist);
 
   add_setshow_uinteger_cmd ("buffer-size", no_class,
 			    &record_btrace_conf.pt.size,
diff --git a/gdb/record-full.c b/gdb/record-full.c
index f5c4244f0ed..dad2e1d2a55 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2802,13 +2802,13 @@ Argument is filename.  File must be created with 'record save'."),
   set_cmd_completer (c, filename_completer);
   deprecate_cmd (c, "record full restore");
 
-  add_basic_prefix_cmd ("full", class_support,
-			_("Set record options."), &set_record_full_cmdlist,
-			0, &set_record_cmdlist);
-
-  add_show_prefix_cmd ("full", class_support,
-		       _("Show record options."), &show_record_full_cmdlist,
-		       0, &show_record_cmdlist);
+  add_setshow_prefix_cmd ("full", class_support,
+			  _("Set record options."),
+			  _("Show record options."),
+			  &set_record_full_cmdlist,
+			  &show_record_full_cmdlist,
+			  &set_record_cmdlist,
+			  &show_record_cmdlist);
 
   /* Record instructions number limit command.  */
   set_show_commands set_record_full_stop_at_limit_cmds
diff --git a/gdb/record.c b/gdb/record.c
index 6968c30d930..37619780d37 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -793,17 +793,16 @@ A size of \"unlimited\" means unlimited lines.  The default is 10."),
 
   add_com_alias ("rec", record_cmd, class_obscure, 1);
 
-  cmd_list_element *set_record_cmd
-    = add_basic_prefix_cmd ("record", class_support,
-			    _("Set record options."), &set_record_cmdlist,
-			    0, &setlist);
-  add_alias_cmd ("rec", set_record_cmd, class_obscure, 1, &setlist);
-
-  cmd_list_element *show_record_cmd
-    = add_show_prefix_cmd ("record", class_support,
-			   _("Show record options."), &show_record_cmdlist,
-			   0, &showlist);
-  add_alias_cmd ("rec", show_record_cmd, class_obscure, 1, &showlist);
+  set_show_commands setshow_record_cmds
+    = add_setshow_prefix_cmd ("record", class_support,
+			      _("Set record options."),
+			      _("Show record options."),
+			      &set_record_cmdlist, &show_record_cmdlist,
+			      &setlist, &showlist);
+
+
+  add_alias_cmd ("rec", setshow_record_cmds.set, class_obscure, 1, &setlist);
+  add_alias_cmd ("rec", setshow_record_cmds.show, class_obscure, 1, &showlist);
 
   cmd_list_element *info_record_cmd
     = add_prefix_cmd ("record", class_support, info_record_command,
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 8b55bc33ded..58fc0a77b48 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -4007,15 +4007,11 @@ _initialize_riscv_tdep ()
 
   /* Add root prefix command for all "set debug riscv" and "show debug
      riscv" commands.  */
-  add_basic_prefix_cmd ("riscv", no_class,
-			_("RISC-V specific debug commands."),
-			&setdebugriscvcmdlist, 0,
-			&setdebuglist);
-
-  add_show_prefix_cmd ("riscv", no_class,
-		       _("RISC-V specific debug commands."),
-		       &showdebugriscvcmdlist, 0,
-		       &showdebuglist);
+  add_setshow_prefix_cmd ("riscv", no_class,
+			  _("RISC-V specific debug commands."),
+			  _("RISC-V specific debug commands."),
+			  &setdebugriscvcmdlist, &showdebugriscvcmdlist,
+			  &setdebuglist, &showdebuglist);
 
   add_setshow_zuinteger_cmd ("breakpoints", class_maintenance,
 			     &riscv_debug_breakpoints,  _("\
@@ -4058,13 +4054,11 @@ initialisation process."),
 			     &setdebugriscvcmdlist, &showdebugriscvcmdlist);
 
   /* Add root prefix command for all "set riscv" and "show riscv" commands.  */
-  add_basic_prefix_cmd ("riscv", no_class,
-			_("RISC-V specific commands."),
-			&setriscvcmdlist, 0, &setlist);
-
-  add_show_prefix_cmd ("riscv", no_class,
-		       _("RISC-V specific commands."),
-		       &showriscvcmdlist, 0, &showlist);
+  add_setshow_prefix_cmd ("riscv", no_class,
+			  _("RISC-V specific commands."),
+			  _("RISC-V specific commands."),
+			  &setriscvcmdlist, &showriscvcmdlist,
+			  &setlist, &showlist);
 
 
   use_compressed_breakpoints = AUTO_BOOLEAN_AUTO;
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 826f0266ed8..de483a93f21 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -7411,13 +7411,11 @@ _initialize_rs6000_tdep ()
 
   /* Add root prefix command for all "set powerpc"/"show powerpc"
      commands.  */
-  add_basic_prefix_cmd ("powerpc", no_class,
-			_("Various PowerPC-specific commands."),
-			&setpowerpccmdlist, 0, &setlist);
-
-  add_show_prefix_cmd ("powerpc", no_class,
-		       _("Various PowerPC-specific commands."),
-		       &showpowerpccmdlist, 0, &showlist);
+  add_setshow_prefix_cmd ("powerpc", no_class,
+			  _("Various PowerPC-specific commands."),
+			  _("Various PowerPC-specific commands."),
+			  &setpowerpccmdlist, &showpowerpccmdlist,
+			  &setlist, &showlist);
 
   /* Add a command to allow the user to force the ABI.  */
   add_setshow_auto_boolean_cmd ("soft-float", class_support,
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index 2519caa505c..7ed61db5774 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -466,16 +466,15 @@ _initialize_ser_tcp ()
   serial_add_interface (&tcp_ops);
 #endif /* USE_WIN32API */
 
-  add_basic_prefix_cmd ("tcp", class_maintenance, _("\
+  add_setshow_prefix_cmd ("tcp", class_maintenance,
+			  _("\
 TCP protocol specific variables.\n\
 Configure variables specific to remote TCP connections."),
-			&tcp_set_cmdlist,
-			0 /* allow-unknown */, &setlist);
-  add_show_prefix_cmd ("tcp", class_maintenance, _("\
+			  _("\
 TCP protocol specific variables.\n\
 Configure variables specific to remote TCP connections."),
-		       &tcp_show_cmdlist,
-		       0 /* allow-unknown */, &showlist);
+			  &tcp_set_cmdlist, &tcp_show_cmdlist,
+			  &setlist, &showlist);
 
   add_setshow_boolean_cmd ("auto-retry", class_obscure,
 			   &tcp_auto_retry, _("\
diff --git a/gdb/serial.c b/gdb/serial.c
index 7d1bc535ed9..042ca4761c1 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -669,17 +669,11 @@ Connect the terminal directly up to the command monitor.\n\
 Use <CR>~. or <CR>~^D to break out."));
 #endif /* 0 */
 
-  add_basic_prefix_cmd ("serial", class_maintenance, _("\
-Set default serial/parallel port configuration."),
-			&serial_set_cmdlist,
-			0/*allow-unknown*/,
-			&setlist);
-
-  add_show_prefix_cmd ("serial", class_maintenance, _("\
-Show default serial/parallel port configuration."),
-		       &serial_show_cmdlist,
-		       0/*allow-unknown*/,
-		       &showlist);
+  add_setshow_prefix_cmd ("serial", class_maintenance,
+			  _("Set default serial/parallel port configuration."),
+			  _("Show default serial/parallel port configuration."),
+			  &serial_set_cmdlist, &serial_show_cmdlist,
+			  &setlist, &showlist);
 
   /* If target is open when baud changes, it doesn't take effect until
      the next open (I think, not sure).  */
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index bfb220adf79..efe8bfdb527 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -2416,10 +2416,11 @@ _initialize_sh_tdep ()
 {
   gdbarch_register (bfd_arch_sh, sh_gdbarch_init, NULL);
 
-  add_basic_prefix_cmd ("sh", no_class, "SH specific commands.",
-			&setshcmdlist, 0, &setlist);
-  add_show_prefix_cmd ("sh", no_class, "SH specific commands.",
-		       &showshcmdlist, 0, &showlist);
+  add_setshow_prefix_cmd ("sh", no_class,
+			  _("SH specific commands."),
+			  _("SH specific commands."),
+			  &setshcmdlist, &showshcmdlist,
+			  &setlist, &showlist);
   
   add_setshow_enum_cmd ("calling-convention", class_vars, sh_cc_enum,
 			&sh_active_calling_convention,
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index f94ace756d4..30ecef360d9 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -1962,14 +1962,12 @@ _initialize_target_descriptions ()
 
   tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init);
 
-  add_basic_prefix_cmd ("tdesc", class_maintenance, _("\
-Set target description specific variables."),
-			&tdesc_set_cmdlist,
-			0 /* allow-unknown */, &setlist);
-  add_show_prefix_cmd ("tdesc", class_maintenance, _("\
-Show target description specific variables."),
-		       &tdesc_show_cmdlist,
-		       0 /* allow-unknown */, &showlist);
+  add_setshow_prefix_cmd ("tdesc", class_maintenance,
+			  _("Set target description specific variables."),
+			  _("Show target description specific variables."),
+			  &tdesc_set_cmdlist, &tdesc_show_cmdlist,
+			  &setlist, &showlist);
+
   add_basic_prefix_cmd ("tdesc", class_maintenance, _("\
 Unset target description specific variables."),
 			&tdesc_unset_cmdlist,
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index a51e7b9f6da..8462d1eb1da 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -987,12 +987,11 @@ _initialize_tui_win ()
 
   /* Define the classes of commands.
      They will appear in the help list in the reverse of this order.  */
-  add_basic_prefix_cmd ("tui", class_tui,
-			_("TUI configuration variables."),
-			&tui_setlist, 0 /* allow-unknown */, &setlist);
-  add_show_prefix_cmd ("tui", class_tui,
-		       _("TUI configuration variables."),
-		       &tui_showlist, 0 /* allow-unknown */, &showlist);
+  add_setshow_prefix_cmd ("tui", class_tui,
+			  _("TUI configuration variables."),
+			  _("TUI configuration variables."),
+			  &tui_setlist, &tui_showlist,
+			  &setlist, &showlist);
 
   add_com ("refresh", class_tui, tui_refresh_all_command,
 	   _("Refresh the terminal display."));
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 0776f634215..9d9bec5cd5e 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -845,12 +845,11 @@ Available FLAGS are:\n\
 Only one level of typedefs is unrolled.  See also \"ptype\"."));
   set_cmd_completer (c, expression_completer);
 
-  add_show_prefix_cmd ("type", no_class,
-		       _("Generic command for showing type-printing settings."),
-		       &showprinttypelist, 0, &showprintlist);
-  add_basic_prefix_cmd ("type", no_class,
-			_("Generic command for setting how types print."),
-			&setprinttypelist, 0, &setprintlist);
+  add_setshow_prefix_cmd ("type", no_class,
+			  _("Generic command for showing type-printing settings."),
+			  _("Generic command for setting how types print."),
+			  &setprinttypelist, &showprinttypelist,
+			  &setprintlist, &showprintlist);
 
   add_setshow_boolean_cmd ("methods", no_class, &print_methods,
 			   _("\
diff --git a/gdb/utils.c b/gdb/utils.c
index 0a7c270b40d..804cc4e6501 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -524,13 +524,9 @@ add_internal_problem_command (struct internal_problem *problem)
     = xstrprintf (_("Show what GDB does when %s is detected."),
 		  problem->name);
 
-  add_basic_prefix_cmd (problem->name, class_maintenance, set_doc,
-			set_cmd_list,
-			0/*allow-unknown*/, &maintenance_set_cmdlist);
-
-  add_show_prefix_cmd (problem->name, class_maintenance, show_doc,
-		       show_cmd_list,
-		       0/*allow-unknown*/, &maintenance_show_cmdlist);
+  add_setshow_prefix_cmd (problem->name, class_maintenance,
+			  set_doc, show_doc, set_cmd_list, show_cmd_list,
+			  &maintenance_set_cmdlist, &maintenance_show_cmdlist);
 
   if (problem->user_settable_should_quit)
     {
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 324055da93f..2fb308f30c7 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -3173,33 +3173,26 @@ _initialize_valprint ()
   selftests::register_test_foreach_arch ("print-flags", test_print_flags);
 #endif
 
-  cmd_list_element *cmd;
-
-  cmd_list_element *set_print_cmd
-    = add_basic_prefix_cmd ("print", no_class,
-			    _("Generic command for setting how things print."),
-			    &setprintlist, 0, &setlist);
-  add_alias_cmd ("p", set_print_cmd, no_class, 1, &setlist);
+  set_show_commands setshow_print_cmds
+    = add_setshow_prefix_cmd ("print", no_class,
+			      _("Generic command for setting how things print."),
+			      _("Generic command for showing print settings."),
+			      &setprintlist, &showprintlist,
+			      &setlist, &showlist);
+  add_alias_cmd ("p", setshow_print_cmds.set, no_class, 1, &setlist);
   /* Prefer set print to set prompt.  */
-  add_alias_cmd ("pr", set_print_cmd, no_class, 1, &setlist);
-
-  cmd_list_element *show_print_cmd
-    = add_show_prefix_cmd ("print", no_class,
-			   _("Generic command for showing print settings."),
-			   &showprintlist, 0, &showlist);
-  add_alias_cmd ("p", show_print_cmd, no_class, 1, &showlist);
-  add_alias_cmd ("pr", show_print_cmd, no_class, 1, &showlist);
-
-  cmd = add_basic_prefix_cmd ("raw", no_class,
-			      _("\
-Generic command for setting what things to print in \"raw\" mode."),
-			      &setprintrawlist, 0, &setprintlist);
-  deprecate_cmd (cmd, nullptr);
-
-  cmd = add_show_prefix_cmd ("raw", no_class,
-			     _("Generic command for showing \"print raw\" settings."),
-			     &showprintrawlist, 0, &showprintlist);
-  deprecate_cmd (cmd, nullptr);
+  add_alias_cmd ("pr", setshow_print_cmds.set, no_class, 1, &setlist);
+  add_alias_cmd ("p", setshow_print_cmds.show, no_class, 1, &showlist);
+  add_alias_cmd ("pr", setshow_print_cmds.show, no_class, 1, &showlist);
+
+  set_show_commands setshow_print_raw_cmds
+    = add_setshow_prefix_cmd
+	("raw", no_class,
+	 _("Generic command for setting what things to print in \"raw\" mode."),
+	 _("Generic command for showing \"print raw\" settings."),
+	 &setprintrawlist, &showprintrawlist, &setprintlist, &showprintlist);
+  deprecate_cmd (setshow_print_raw_cmds.set, nullptr);
+  deprecate_cmd (setshow_print_raw_cmds.show, nullptr);
 
   gdb::option::add_setshow_cmds_for_options
     (class_support, &user_print_options, value_print_option_defs,
-- 
2.33.0


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

* [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options
  2021-09-23 13:56 [PATCH 1/3] gdb: add add_setshow_prefix_cmd Simon Marchi
@ 2021-09-23 13:56 ` Simon Marchi
  2021-09-23 15:45   ` Eli Zaretskii
                     ` (2 more replies)
  2021-09-23 13:56 ` [PATCH 3/3] gdb: add selftest name completion Simon Marchi
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 17+ messages in thread
From: Simon Marchi @ 2021-09-23 13:56 UTC (permalink / raw)
  To: gdb-patches

From: Simon Marchi <simon.marchi@polymtl.ca>

I saw the new -verbose switch to "maint selftests" and thought it would
be nice for it to use the option framework.  For example, that makes
having completion easy.  It's not that high value, given this is a
maintenance command, but I had never used the framework myself, so it
was a good way to practice.

This patch also adds the "maint set/show selftest verbose" setting.  It
would be possible to use option framework without adding the setting,
but using the framework makes adding the option almost trivial, so I
thought why not.

Change-Id: I6687faa0713ff3da60b398253211777100094144
---
 gdb/doc/gdb.texinfo |  7 +++++
 gdb/maint.c         | 74 ++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 76 insertions(+), 5 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index bf731a1feb5..c7a11394863 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -39440,6 +39440,13 @@ If a @var{filter} is passed, only the tests with @var{filter} in their
 name will be ran.  If @code{-verbose} is passed, the self tests can be
 more verbose.
 
+@kindex maint set selftest verbose
+@kindex maint show selftest verbose
+@cindex self tests
+@item maint set selftest verbose
+@item maint show selftest verbose
+Control whether self tests are run verbosely or not.
+
 @kindex maint info selftests
 @cindex self tests
 @item maint info selftests
diff --git a/gdb/maint.c b/gdb/maint.c
index c6d13a3a732..a3777474846 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -1119,7 +1119,34 @@ set_per_command_cmd (const char *args, int from_tty)
       }
 }
 
-\f
+/* Options affecting the "maintenance selftest" command.  */
+
+struct maintenance_selftest_options
+{
+  bool verbose = false;
+} user_maintenance_selftest_options;
+
+static const gdb::option::option_def maintenance_selftest_option_defs[] = {
+  gdb::option::boolean_option_def<maintenance_selftest_options> {
+    "verbose",
+    [] (maintenance_selftest_options *opt) { return &opt->verbose; },
+    nullptr,
+    N_("Set whether selftests run in verbose mode."),
+    N_("Show whether selftests run in verbose mode."),
+    N_("\
+When on, selftests may print verbose information."),
+  },
+};
+
+/* Make option groups for the "maintenance selftest" command.  */
+
+static std::array<gdb::option::option_def_group, 1>
+make_maintenance_selftest_option_group (maintenance_selftest_options *opts)
+{
+  return {{
+    {{maintenance_selftest_option_defs}, opts},
+  }};
+}
 
 /* The "maintenance selftest" command.  */
 
@@ -1127,15 +1154,32 @@ static void
 maintenance_selftest (const char *args, int from_tty)
 {
 #if GDB_SELF_TEST
-  bool verbose = args != nullptr && check_for_argument (&args, "-verbose");
+  maintenance_selftest_options opts = user_maintenance_selftest_options;
+  auto grp = make_maintenance_selftest_option_group (&opts);
+  gdb::option::process_options
+    (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp);
   gdb_argv argv (args);
-  selftests::run_tests (argv.as_array_view (), verbose);
+  selftests::run_tests (argv.as_array_view (), opts.verbose);
 #else
   printf_filtered (_("\
 Selftests have been disabled for this build.\n"));
 #endif
 }
 
+/* Completer for the "maintenance selftest" command.  */
+
+static void
+maintenance_selftest_completer (cmd_list_element *cmd,
+				completion_tracker &tracker,
+				const char *text,
+				const char *word)
+{
+  auto grp = make_maintenance_selftest_option_group (nullptr);
+
+  gdb::option::complete_options
+    (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp);
+}
+
 static void
 maintenance_info_selftests (const char *arg, int from_tty)
 {
@@ -1369,12 +1413,15 @@ This is used by the testsuite to check the command deprecator.\n\
 You probably shouldn't use this."),
 	   &maintenancelist);
 
-  add_cmd ("selftest", class_maintenance, maintenance_selftest, _("\
+  cmd_list_element *maintenance_selftest_cmd
+    = add_cmd ("selftest", class_maintenance, maintenance_selftest, _("\
 Run gdb's unit tests.\n\
 Usage: maintenance selftest [FILTER]\n\
 This will run any unit tests that were built in to gdb.\n\
 If a filter is given, only the tests with that value in their name will ran."),
-	   &maintenancelist);
+	       &maintenancelist);
+  set_cmd_completer_handle_brkchars (maintenance_selftest_cmd,
+				     maintenance_selftest_completer);
 
   add_cmd ("selftests", class_maintenance, maintenance_info_selftests,
 	 _("List the registered selftests."), &maintenanceinfolist);
@@ -1401,5 +1448,22 @@ such as demangling symbol names."),
 				       &maintenance_set_cmdlist,
 				       &maintenance_show_cmdlist);
 
+  /* Add the "maint set/show selftest" commands.  */
+  static cmd_list_element *set_selftest_cmdlist = nullptr;
+  static cmd_list_element *show_selftest_cmdlist = nullptr;
+
+  add_setshow_prefix_cmd ("selftest", class_maintenance,
+			  _("Self tests-related settings."),
+			  _("Self tests-related settings."),
+			  &set_selftest_cmdlist, &show_selftest_cmdlist,
+			  &maintenance_set_cmdlist, &maintenance_show_cmdlist);
+
+  /* Add setting commands matching "maintenance selftest" options.  */
+  gdb::option::add_setshow_cmds_for_options (class_maintenance,
+					     &user_maintenance_selftest_options,
+					     maintenance_selftest_option_defs,
+					     &set_selftest_cmdlist,
+					     &show_selftest_cmdlist);
+
   update_thread_pool_size ();
 }
-- 
2.33.0


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

* [PATCH 3/3] gdb: add selftest name completion
  2021-09-23 13:56 [PATCH 1/3] gdb: add add_setshow_prefix_cmd Simon Marchi
  2021-09-23 13:56 ` [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options Simon Marchi
@ 2021-09-23 13:56 ` Simon Marchi
  2021-09-23 19:35   ` Pedro Alves
  2021-09-23 20:46   ` Tom Tromey
  2021-09-23 20:35 ` [PATCH 1/3] gdb: add add_setshow_prefix_cmd Bruno Larsen
  2021-09-23 20:41 ` Tom Tromey
  3 siblings, 2 replies; 17+ messages in thread
From: Simon Marchi @ 2021-09-23 13:56 UTC (permalink / raw)
  To: gdb-patches

From: Simon Marchi <simon.marchi@polymtl.ca>

After the previous commit, it is easy to add completion for selftest
names.  Again, this is not particularly high value, but I rarely touched
completion, so it served as a simple example to get some practice.

Change the for_each_selftest_ftype parameter to gdb::function_view, so
that we can pass a lambda that captures things.

Change-Id: I87cac299ddca9ca7eb0ffab78342e850a98d954c
---
 gdb/maint.c           | 11 +++++++++--
 gdbsupport/selftest.h |  4 +++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gdb/maint.c b/gdb/maint.c
index a3777474846..f01618f6ea0 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -1176,8 +1176,15 @@ maintenance_selftest_completer (cmd_list_element *cmd,
 {
   auto grp = make_maintenance_selftest_option_group (nullptr);
 
-  gdb::option::complete_options
-    (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp);
+  if (gdb::option::complete_options
+	(tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp))
+    return;
+
+  selftests::for_each_selftest ([&tracker, text] (const std::string &name)
+    {
+      if (startswith (name.c_str (), text))
+	tracker.add_completion (make_unique_xstrdup (name.c_str ()));
+    });
 }
 
 static void
diff --git a/gdbsupport/selftest.h b/gdbsupport/selftest.h
index d76fc4b37d3..6e78dfd58f7 100644
--- a/gdbsupport/selftest.h
+++ b/gdbsupport/selftest.h
@@ -20,6 +20,7 @@
 #define COMMON_SELFTEST_H
 
 #include "gdbsupport/array-view.h"
+#include "gdbsupport/function-view.h"
 
 /* A test is just a function that does some checks and throws an
    exception if something has gone wrong.  */
@@ -62,7 +63,8 @@ extern void run_tests (gdb::array_view<const char *const> filters,
 /* Reset GDB or GDBserver's internal state.  */
 extern void reset ();
 
-typedef void for_each_selftest_ftype (const std::string &name);
+using for_each_selftest_ftype
+  = gdb::function_view<void(const std::string &name)>;
 
 /* Call FUNC for each registered selftest.  */
 
-- 
2.33.0


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

* Re: [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options
  2021-09-23 13:56 ` [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options Simon Marchi
@ 2021-09-23 15:45   ` Eli Zaretskii
  2021-09-23 19:11     ` Simon Marchi
  2021-09-23 19:31   ` Pedro Alves
  2021-09-23 20:44   ` Tom Tromey
  2 siblings, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2021-09-23 15:45 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

> Date: Thu, 23 Sep 2021 09:56:50 -0400
> From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
> 
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index bf731a1feb5..c7a11394863 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -39440,6 +39440,13 @@ If a @var{filter} is passed, only the tests with @var{filter} in their
>  name will be ran.  If @code{-verbose} is passed, the self tests can be
>  more verbose.
>  
> +@kindex maint set selftest verbose
> +@kindex maint show selftest verbose
> +@cindex self tests
> +@item maint set selftest verbose
> +@item maint show selftest verbose
> +Control whether self tests are run verbosely or not.
> +
>  @kindex maint info selftests
>  @cindex self tests
>  @item maint info selftests

This part is okay, thanks.

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

* Re: [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options
  2021-09-23 15:45   ` Eli Zaretskii
@ 2021-09-23 19:11     ` Simon Marchi
  0 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2021-09-23 19:11 UTC (permalink / raw)
  To: Eli Zaretskii, Simon Marchi; +Cc: gdb-patches



On 2021-09-23 11:45 a.m., Eli Zaretskii via Gdb-patches wrote:
>> Date: Thu, 23 Sep 2021 09:56:50 -0400
>> From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
>>
>> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
>> index bf731a1feb5..c7a11394863 100644
>> --- a/gdb/doc/gdb.texinfo
>> +++ b/gdb/doc/gdb.texinfo
>> @@ -39440,6 +39440,13 @@ If a @var{filter} is passed, only the tests with @var{filter} in their
>>  name will be ran.  If @code{-verbose} is passed, the self tests can be
>>  more verbose.
>>  
>> +@kindex maint set selftest verbose
>> +@kindex maint show selftest verbose
>> +@cindex self tests
>> +@item maint set selftest verbose
>> +@item maint show selftest verbose
>> +Control whether self tests are run verbosely or not.
>> +
>>  @kindex maint info selftests
>>  @cindex self tests
>>  @item maint info selftests
> 
> This part is okay, thanks.
> 

Thanks.

Simon

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

* Re: [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options
  2021-09-23 13:56 ` [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options Simon Marchi
  2021-09-23 15:45   ` Eli Zaretskii
@ 2021-09-23 19:31   ` Pedro Alves
  2021-10-28 14:48     ` Simon Marchi
  2021-09-23 20:44   ` Tom Tromey
  2 siblings, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2021-09-23 19:31 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 2021-09-23 2:56 p.m., Simon Marchi via Gdb-patches wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> I saw the new -verbose switch to "maint selftests" and thought it would
> be nice for it to use the option framework.  For example, that makes
> having completion easy.  It's not that high value, given this is a
> maintenance command, but I had never used the framework myself, so it
> was a good way to practice.
> 
> This patch also adds the "maint set/show selftest verbose" setting.  It
> would be possible to use option framework without adding the setting,
> but using the framework makes adding the option almost trivial, so I
> thought why not.
> 

Yay!  Thanks for doing this.  Looks right to me.

Now we could have a completer for the unit tests names.  :-)
The param is a regexp, but completing as simple string matching the test names 
I think would be still nice.  

Oh gosh, now that I write this I actually look at patch #3.  Wohoo! I've wanted
that before.

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

* Re: [PATCH 3/3] gdb: add selftest name completion
  2021-09-23 13:56 ` [PATCH 3/3] gdb: add selftest name completion Simon Marchi
@ 2021-09-23 19:35   ` Pedro Alves
  2021-10-28 15:18     ` Simon Marchi
  2021-09-23 20:46   ` Tom Tromey
  1 sibling, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2021-09-23 19:35 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 2021-09-23 2:56 p.m., Simon Marchi via Gdb-patches wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> After the previous commit, it is easy to add completion for selftest
> names.  Again, this is not particularly high value, but I rarely touched
> completion, so it served as a simple example to get some practice.
> 
> Change the for_each_selftest_ftype parameter to gdb::function_view, so
> that we can pass a lambda that captures things.
> 

LGTM.  Thanks!  Maybe adding a couple completion tests wouldn't hurt though.

- test completing some unit test name that exits.
- test completing some unit test name that doesn't exist.

At least this would make sure we don't crash.

You would use the completion-support.exp routines, like test_gdb_complete_unique,
test_gdb_complete_multiple, test_gdb_complete_none.

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

* Re: [PATCH 1/3] gdb: add add_setshow_prefix_cmd
  2021-09-23 13:56 [PATCH 1/3] gdb: add add_setshow_prefix_cmd Simon Marchi
  2021-09-23 13:56 ` [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options Simon Marchi
  2021-09-23 13:56 ` [PATCH 3/3] gdb: add selftest name completion Simon Marchi
@ 2021-09-23 20:35 ` Bruno Larsen
  2021-10-28 14:39   ` Simon Marchi
  2021-09-23 20:41 ` Tom Tromey
  3 siblings, 1 reply; 17+ messages in thread
From: Bruno Larsen @ 2021-09-23 20:35 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 9/23/21 10:56 AM, Simon Marchi via Gdb-patches wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> There's a common pattern to call add_basic_prefix_cmd and
> add_show_prefix_cmd to add matching set and show commands.  Add the
> add_setshow_prefix_cmd function to factor that out and use it at a few
> places.
> 
> Change-Id: I6e9e90a30e9efb7b255bf839cac27b85d7069cfd
> ---
>   gdb/ada-lang.c            | 27 +++++++++------------
>   gdb/arm-tdep.c            | 13 ++++-------
>   gdb/breakpoint.c          | 11 ++++-----
>   gdb/btrace.c              | 34 ++++++++++++---------------
>   gdb/cli/cli-cmds.c        | 23 ++++++++----------
>   gdb/cli/cli-decode.c      | 22 ++++++++++++++++++
>   gdb/cli/cli-logging.c     | 12 +++++-----
>   gdb/cli/cli-style.c       | 16 ++++++-------
>   gdb/command.h             | 25 ++++++++++++++------
>   gdb/dcache.c              | 11 ++++-----
>   gdb/dwarf2/read.c         | 12 ++++------
>   gdb/f-lang.c              | 13 +++++------
>   gdb/frame.c               | 11 ++++-----
>   gdb/guile/guile.c         | 22 +++++++++---------
>   gdb/i386-tdep.c           | 18 +++++---------
>   gdb/language.c            | 23 ++++++++----------
>   gdb/maint-test-settings.c | 17 +++++---------
>   gdb/memattr.c             | 13 ++++-------
>   gdb/mips-tdep.c           | 12 ++++------
>   gdb/python/python.c       | 12 ++++------
>   gdb/ravenscar-thread.c    | 13 +++++------
>   gdb/record-btrace.c       | 49 ++++++++++++++++-----------------------
>   gdb/record-full.c         | 14 +++++------
>   gdb/record.c              | 21 ++++++++---------
>   gdb/riscv-tdep.c          | 26 ++++++++-------------
>   gdb/rs6000-tdep.c         | 12 ++++------
>   gdb/ser-tcp.c             | 11 ++++-----
>   gdb/serial.c              | 16 ++++---------
>   gdb/sh-tdep.c             |  9 +++----
>   gdb/target-descriptions.c | 14 +++++------
>   gdb/tui/tui-win.c         | 11 ++++-----
>   gdb/typeprint.c           | 11 ++++-----
>   gdb/utils.c               | 10 +++-----
>   gdb/valprint.c            | 45 +++++++++++++++--------------------
>   34 files changed, 280 insertions(+), 329 deletions(-)
> 

 From my manual checks, all occurrences of this pattern were changed, and this change has not introduced any regressions, so from the technical side this looks ok.
 From a subjective point of view, this looks easier to understand and maintain.

In general, sounds like a good change

--
Cheers!
Bruno Larsen


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

* Re: [PATCH 1/3] gdb: add add_setshow_prefix_cmd
  2021-09-23 13:56 [PATCH 1/3] gdb: add add_setshow_prefix_cmd Simon Marchi
                   ` (2 preceding siblings ...)
  2021-09-23 20:35 ` [PATCH 1/3] gdb: add add_setshow_prefix_cmd Bruno Larsen
@ 2021-09-23 20:41 ` Tom Tromey
  3 siblings, 0 replies; 17+ messages in thread
From: Tom Tromey @ 2021-09-23 20:41 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
Simon> There's a common pattern to call add_basic_prefix_cmd and
Simon> add_show_prefix_cmd to add matching set and show commands.  Add the
Simon> add_setshow_prefix_cmd function to factor that out and use it at a few
Simon> places.

Looks good to me.

Tom

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

* Re: [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options
  2021-09-23 13:56 ` [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options Simon Marchi
  2021-09-23 15:45   ` Eli Zaretskii
  2021-09-23 19:31   ` Pedro Alves
@ 2021-09-23 20:44   ` Tom Tromey
  2 siblings, 0 replies; 17+ messages in thread
From: Tom Tromey @ 2021-09-23 20:44 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
Simon> I saw the new -verbose switch to "maint selftests" and thought it would
Simon> be nice for it to use the option framework.  For example, that makes
Simon> having completion easy.  It's not that high value, given this is a
Simon> maintenance command, but I had never used the framework myself, so it
Simon> was a good way to practice.

Looks good.

Sometimes I wish 'maint selftest' took just the name(s) of the test, and
not a regexp, so completion would work for the test names as well.

Tom

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

* Re: [PATCH 3/3] gdb: add selftest name completion
  2021-09-23 13:56 ` [PATCH 3/3] gdb: add selftest name completion Simon Marchi
  2021-09-23 19:35   ` Pedro Alves
@ 2021-09-23 20:46   ` Tom Tromey
  2021-10-28 15:19     ` Simon Marchi
  1 sibling, 1 reply; 17+ messages in thread
From: Tom Tromey @ 2021-09-23 20:46 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
Simon> After the previous commit, it is easy to add completion for selftest
Simon> names.  Again, this is not particularly high value, but I rarely touched
Simon> completion, so it served as a simple example to get some practice.

LOL I sent that last message before looking at this one.

And now that I look I see that the argument isn't actually a regexp:

    gdb::array_view<const char *const> filters
[...]
	  for (const char *filter : filters)
	    {
	      if (name.find (filter) != std::string::npos)

so I guess it's a substring match.

Anyway the patch seems fine.  Requiring a full name match would also be
ok with me.

Tom

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

* Re: [PATCH 1/3] gdb: add add_setshow_prefix_cmd
  2021-09-23 20:35 ` [PATCH 1/3] gdb: add add_setshow_prefix_cmd Bruno Larsen
@ 2021-10-28 14:39   ` Simon Marchi
  0 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2021-10-28 14:39 UTC (permalink / raw)
  To: Bruno Larsen, Simon Marchi, gdb-patches

On 2021-09-23 4:35 p.m., Bruno Larsen via Gdb-patches wrote:
> On 9/23/21 10:56 AM, Simon Marchi via Gdb-patches wrote:
>> From: Simon Marchi <simon.marchi@polymtl.ca>
>>
>> There's a common pattern to call add_basic_prefix_cmd and
>> add_show_prefix_cmd to add matching set and show commands.  Add the
>> add_setshow_prefix_cmd function to factor that out and use it at a few
>> places.
>>
>> Change-Id: I6e9e90a30e9efb7b255bf839cac27b85d7069cfd
>> ---
>>   gdb/ada-lang.c            | 27 +++++++++------------
>>   gdb/arm-tdep.c            | 13 ++++-------
>>   gdb/breakpoint.c          | 11 ++++-----
>>   gdb/btrace.c              | 34 ++++++++++++---------------
>>   gdb/cli/cli-cmds.c        | 23 ++++++++----------
>>   gdb/cli/cli-decode.c      | 22 ++++++++++++++++++
>>   gdb/cli/cli-logging.c     | 12 +++++-----
>>   gdb/cli/cli-style.c       | 16 ++++++-------
>>   gdb/command.h             | 25 ++++++++++++++------
>>   gdb/dcache.c              | 11 ++++-----
>>   gdb/dwarf2/read.c         | 12 ++++------
>>   gdb/f-lang.c              | 13 +++++------
>>   gdb/frame.c               | 11 ++++-----
>>   gdb/guile/guile.c         | 22 +++++++++---------
>>   gdb/i386-tdep.c           | 18 +++++---------
>>   gdb/language.c            | 23 ++++++++----------
>>   gdb/maint-test-settings.c | 17 +++++---------
>>   gdb/memattr.c             | 13 ++++-------
>>   gdb/mips-tdep.c           | 12 ++++------
>>   gdb/python/python.c       | 12 ++++------
>>   gdb/ravenscar-thread.c    | 13 +++++------
>>   gdb/record-btrace.c       | 49 ++++++++++++++++-----------------------
>>   gdb/record-full.c         | 14 +++++------
>>   gdb/record.c              | 21 ++++++++---------
>>   gdb/riscv-tdep.c          | 26 ++++++++-------------
>>   gdb/rs6000-tdep.c         | 12 ++++------
>>   gdb/ser-tcp.c             | 11 ++++-----
>>   gdb/serial.c              | 16 ++++---------
>>   gdb/sh-tdep.c             |  9 +++----
>>   gdb/target-descriptions.c | 14 +++++------
>>   gdb/tui/tui-win.c         | 11 ++++-----
>>   gdb/typeprint.c           | 11 ++++-----
>>   gdb/utils.c               | 10 +++-----
>>   gdb/valprint.c            | 45 +++++++++++++++--------------------
>>   34 files changed, 280 insertions(+), 329 deletions(-)
>>
>
> From my manual checks, all occurrences of this pattern were changed, and this change has not introduced any regressions, so from the technical side this looks ok.
> From a subjective point of view, this looks easier to understand and maintain.
>
> In general, sounds like a good change
>
> --
> Cheers!
> Bruno Larsen
>

Thanks for validating.  I'll push this patch right now, since it's an
improvement on its own.

Simon

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

* Re: [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options
  2021-09-23 19:31   ` Pedro Alves
@ 2021-10-28 14:48     ` Simon Marchi
  0 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2021-10-28 14:48 UTC (permalink / raw)
  To: Pedro Alves, Simon Marchi, gdb-patches

On 2021-09-23 3:31 p.m., Pedro Alves wrote:
> On 2021-09-23 2:56 p.m., Simon Marchi via Gdb-patches wrote:
>> From: Simon Marchi <simon.marchi@polymtl.ca>
>>
>> I saw the new -verbose switch to "maint selftests" and thought it would
>> be nice for it to use the option framework.  For example, that makes
>> having completion easy.  It's not that high value, given this is a
>> maintenance command, but I had never used the framework myself, so it
>> was a good way to practice.
>>
>> This patch also adds the "maint set/show selftest verbose" setting.  It
>> would be possible to use option framework without adding the setting,
>> but using the framework makes adding the option almost trivial, so I
>> thought why not.
>>
> 
> Yay!  Thanks for doing this.  Looks right to me.
> 
> Now we could have a completer for the unit tests names.  :-)
> The param is a regexp, but completing as simple string matching the test names 
> I think would be still nice.  
> 
> Oh gosh, now that I write this I actually look at patch #3.  Wohoo! I've wanted
> that before.
> 


Thanks, pushed.

Simon

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

* Re: [PATCH 3/3] gdb: add selftest name completion
  2021-09-23 19:35   ` Pedro Alves
@ 2021-10-28 15:18     ` Simon Marchi
  2021-10-29  7:24       ` Tom de Vries
  0 siblings, 1 reply; 17+ messages in thread
From: Simon Marchi @ 2021-10-28 15:18 UTC (permalink / raw)
  To: Pedro Alves, Simon Marchi, gdb-patches

On 2021-09-23 3:35 p.m., Pedro Alves wrote:
> On 2021-09-23 2:56 p.m., Simon Marchi via Gdb-patches wrote:
>> From: Simon Marchi <simon.marchi@polymtl.ca>
>>
>> After the previous commit, it is easy to add completion for selftest
>> names.  Again, this is not particularly high value, but I rarely touched
>> completion, so it served as a simple example to get some practice.
>>
>> Change the for_each_selftest_ftype parameter to gdb::function_view, so
>> that we can pass a lambda that captures things.
>>
> 
> LGTM.  Thanks!  Maybe adding a couple completion tests wouldn't hurt though.
> 
> - test completing some unit test name that exits.
> - test completing some unit test name that doesn't exist.
> 
> At least this would make sure we don't crash.
> 
> You would use the completion-support.exp routines, like test_gdb_complete_unique,
> test_gdb_complete_multiple, test_gdb_complete_none.
> 

Thanks, added a test and pushed.

Simon

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

* Re: [PATCH 3/3] gdb: add selftest name completion
  2021-09-23 20:46   ` Tom Tromey
@ 2021-10-28 15:19     ` Simon Marchi
  0 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2021-10-28 15:19 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches; +Cc: Simon Marchi

On 2021-09-23 4:46 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
> Simon> After the previous commit, it is easy to add completion for selftest
> Simon> names.  Again, this is not particularly high value, but I rarely touched
> Simon> completion, so it served as a simple example to get some practice.
> 
> LOL I sent that last message before looking at this one.
> 
> And now that I look I see that the argument isn't actually a regexp:
> 
>     gdb::array_view<const char *const> filters
> [...]
> 	  for (const char *filter : filters)
> 	    {
> 	      if (name.find (filter) != std::string::npos)
> 
> so I guess it's a substring match.
> 
> Anyway the patch seems fine.  Requiring a full name match would also be
> ok with me.
> 
> Tom
> 

I think it's ok if it stays a substring match (or is even a regexp), the completion
is just there to help in case you are looking for a specific test name.

Simon

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

* Re: [PATCH 3/3] gdb: add selftest name completion
  2021-10-28 15:18     ` Simon Marchi
@ 2021-10-29  7:24       ` Tom de Vries
  2021-10-29 12:05         ` Simon Marchi
  0 siblings, 1 reply; 17+ messages in thread
From: Tom de Vries @ 2021-10-29  7:24 UTC (permalink / raw)
  To: Simon Marchi, Pedro Alves, Simon Marchi, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

On 10/28/21 5:18 PM, Simon Marchi wrote:
> On 2021-09-23 3:35 p.m., Pedro Alves wrote:
>> On 2021-09-23 2:56 p.m., Simon Marchi via Gdb-patches wrote:
>>> From: Simon Marchi <simon.marchi@polymtl.ca>
>>>
>>> After the previous commit, it is easy to add completion for selftest
>>> names.  Again, this is not particularly high value, but I rarely touched
>>> completion, so it served as a simple example to get some practice.
>>>
>>> Change the for_each_selftest_ftype parameter to gdb::function_view, so
>>> that we can pass a lambda that captures things.
>>>
>>
>> LGTM.  Thanks!  Maybe adding a couple completion tests wouldn't hurt though.
>>
>> - test completing some unit test name that exits.
>> - test completing some unit test name that doesn't exist.
>>
>> At least this would make sure we don't crash.
>>
>> You would use the completion-support.exp routines, like test_gdb_complete_unique,
>> test_gdb_complete_multiple, test_gdb_complete_none.
>>
> 
> Thanks, added a test and pushed.

This caused a build breaker with --disable-unit-tests, fixed by patch
below.  Any comments?

Thanks,
- Tom


[-- Attachment #2: 0001-gdb-build-Fix-build-with-disable-unit-tests.patch --]
[-- Type: text/x-patch, Size: 3196 bytes --]

[gdb/build] Fix build with --disable-unit-tests

A build with --disable-unit-tests currently run into:
...
ld: maint.o: in function \
  `maintenance_selftest_completer(cmd_list_element*, completion_tracker&,
                                  char const*, char const*)':
src/gdb/maint.c:1183: undefined reference to \
  `selftests::for_each_selftest(
    gdb::function_view<
      void (std::__cxx11::basic_string<char,std::char_traits<char>,
                                       std::allocator<char> > const&)>)'
...

Fix this by guarding the call to selftests::for_each_selftest in
maintenance_selftest_completer with GDB_SELF_TEST, such that the "-verbose"
completion still works.

Rebuild on x86_64-linux and ran gdb.gdb/unittest.exp.

---
 gdb/maint.c                        |  2 ++
 gdb/testsuite/gdb.gdb/unittest.exp | 21 +++++++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/gdb/maint.c b/gdb/maint.c
index 85fa18c34a0..bcc71aab579 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -1180,11 +1180,13 @@ maintenance_selftest_completer (cmd_list_element *cmd,
 	(tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp))
     return;
 
+#if GDB_SELF_TEST
   selftests::for_each_selftest ([&tracker, text] (const std::string &name)
     {
       if (startswith (name.c_str (), text))
 	tracker.add_completion (make_unique_xstrdup (name.c_str ()));
     });
+#endif
 }
 
 static void
diff --git a/gdb/testsuite/gdb.gdb/unittest.exp b/gdb/testsuite/gdb.gdb/unittest.exp
index 0ddd2068377..bcb4bbd2a82 100644
--- a/gdb/testsuite/gdb.gdb/unittest.exp
+++ b/gdb/testsuite/gdb.gdb/unittest.exp
@@ -40,6 +40,7 @@ proc run_selftests { binfile } {
 	clean_restart ${binfile}
     }
 
+    set enabled 1
     set test "maintenance selftest"
     gdb_test_multiple $test $test {
 	-re ".*Running selftest \[^\n\r\]+\." {
@@ -57,23 +58,35 @@ proc run_selftests { binfile } {
 	}
 	-re "Selftests have been disabled for this build.\r\n$gdb_prompt $" {
 	    unsupported $test
+	    set enabled 0
 	}
     }
+
+    return $enabled
 }
 
 # Test completion of command "maintenance selftest".
 
 proc_with_prefix test_completion {} {
+    global self_tests_enabled
+
     clean_restart
-    test_gdb_complete_tab_multiple "maintenance selftest string_v" "" \
-	{string_vappendf string_view string_vprintf}
-    test_gdb_complete_tab_unique "maintenance selftest string_vie" "maintenance selftest string_view" " "
+
+    if { $self_tests_enabled } {
+	test_gdb_complete_tab_multiple "maintenance selftest string_v" "" \
+	    {string_vappendf string_view string_vprintf}
+	test_gdb_complete_tab_unique "maintenance selftest string_vie" \
+	    "maintenance selftest string_view" " "
+    } else {
+	test_gdb_complete_tab_none "maintenance selftest string_v"
+	test_gdb_complete_tab_none "maintenance selftest string_vie"
+    }
     test_gdb_complete_tab_unique "maintenance selftest -ver" "maintenance selftest -verbose" " "
     test_gdb_complete_tab_none "maintenance selftest name_that_does_not_exist"
 }
 
 with_test_prefix "no executable loaded" {
-    run_selftests ""
+    set self_tests_enabled [run_selftests ""]
 }
 
 with_test_prefix "executable loaded" {

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

* Re: [PATCH 3/3] gdb: add selftest name completion
  2021-10-29  7:24       ` Tom de Vries
@ 2021-10-29 12:05         ` Simon Marchi
  0 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2021-10-29 12:05 UTC (permalink / raw)
  To: Tom de Vries, Simon Marchi, Pedro Alves, Simon Marchi, gdb-patches



On 2021-10-29 03:24, Tom de Vries wrote:
> On 10/28/21 5:18 PM, Simon Marchi wrote:
>> On 2021-09-23 3:35 p.m., Pedro Alves wrote:
>>> On 2021-09-23 2:56 p.m., Simon Marchi via Gdb-patches wrote:
>>>> From: Simon Marchi <simon.marchi@polymtl.ca>
>>>>
>>>> After the previous commit, it is easy to add completion for selftest
>>>> names.  Again, this is not particularly high value, but I rarely touched
>>>> completion, so it served as a simple example to get some practice.
>>>>
>>>> Change the for_each_selftest_ftype parameter to gdb::function_view, so
>>>> that we can pass a lambda that captures things.
>>>>
>>>
>>> LGTM.  Thanks!  Maybe adding a couple completion tests wouldn't hurt though.
>>>
>>> - test completing some unit test name that exits.
>>> - test completing some unit test name that doesn't exist.
>>>
>>> At least this would make sure we don't crash.
>>>
>>> You would use the completion-support.exp routines, like test_gdb_complete_unique,
>>> test_gdb_complete_multiple, test_gdb_complete_none.
>>>
>>
>> Thanks, added a test and pushed.
> 
> This caused a build breaker with --disable-unit-tests, fixed by patch
> below.  Any comments?
> 
> Thanks,
> - Tom
> 

Ah, sorry for the breakage, the patch LGTM, thanks.

Simon

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

end of thread, other threads:[~2021-10-29 12:06 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-23 13:56 [PATCH 1/3] gdb: add add_setshow_prefix_cmd Simon Marchi
2021-09-23 13:56 ` [PATCH 2/3] gdb: add "maint set/show selftest verbose" commands and use process_options Simon Marchi
2021-09-23 15:45   ` Eli Zaretskii
2021-09-23 19:11     ` Simon Marchi
2021-09-23 19:31   ` Pedro Alves
2021-10-28 14:48     ` Simon Marchi
2021-09-23 20:44   ` Tom Tromey
2021-09-23 13:56 ` [PATCH 3/3] gdb: add selftest name completion Simon Marchi
2021-09-23 19:35   ` Pedro Alves
2021-10-28 15:18     ` Simon Marchi
2021-10-29  7:24       ` Tom de Vries
2021-10-29 12:05         ` Simon Marchi
2021-09-23 20:46   ` Tom Tromey
2021-10-28 15:19     ` Simon Marchi
2021-09-23 20:35 ` [PATCH 1/3] gdb: add add_setshow_prefix_cmd Bruno Larsen
2021-10-28 14:39   ` Simon Marchi
2021-09-23 20:41 ` Tom Tromey

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).