Update more calls to add_prefix_cmd

Message ID 20200425191051.15586-1-tom@tromey.com
State New
Headers show
Series
  • Update more calls to add_prefix_cmd
Related show

Commit Message

Tom Tromey April 25, 2020, 7:10 p.m.
I looked at all the calls to add_prefix_cmd, and replaced them with
calls to add_basic_prefix_cmd or add_show_prefix_cmd when appropriate.
This makes gdb's command language a bit more regular.  I don't think
there's a significant downside.

Note that this patch removes a couple of tests.  The removed ones are
completely redundant.

gdb/ChangeLog
2020-04-25  Tom Tromey  <tom@tromey.com>

	* breakpoint.c (catch_command, tcatch_command): Remove.
	(_initialize_breakpoint): Use add_basic_prefix_cmd,
	add_show_prefix_cmd.
	(set_breakpoint_cmd, show_breakpoint_cmd): Remove
	* utils.c (set_internal_problem_cmd, show_internal_problem_cmd):
	Remove.
	(add_internal_problem_command): Use add_basic_prefix_cmd,
	add_show_prefix_cmd.
	* mips-tdep.c (set_mipsfpu_command): Remove.
	(_initialize_mips_tdep): Use add_basic_prefix_cmd.
	* dwarf2/index-cache.c (set_index_cache_command): Remove.
	(_initialize_index_cache): Use add_basic_prefix_cmd.
	* memattr.c (dummy_cmd): Remove.
	(_initialize_mem): Use add_basic_prefix_cmd, add_show_prefix_cmd.
	* tui/tui-win.c (set_tui_cmd, show_tui_cmd): Remove.
	(_initialize_tui_win): Use add_basic_prefix_cmd,
	add_show_prefix_cmd.
	* cli/cli-logging.c (set_logging_command): Remove.
	(_initialize_cli_logging): Use add_basic_prefix_cmd,
	add_show_prefix_cmd.
	(show_logging_command): Remove.
	* target.c (target_command): Remove.
	(add_target): Use add_basic_prefix_cmd.

gdb/testsuite/ChangeLog
2020-04-25  Tom Tromey  <tom@tromey.com>

	* gdb.base/sepdebug.exp: Remove "catch" test.
	* gdb.base/break.exp: Remove "catch" test.
	* gdb.base/default.exp: Update expected output.
---
 gdb/ChangeLog                       | 26 +++++++++++++++
 gdb/breakpoint.c                    | 45 +++++++-------------------
 gdb/cli/cli-logging.c               | 49 ++++-------------------------
 gdb/dwarf2/index-cache.c            | 16 +++-------
 gdb/memattr.c                       | 17 ++++------
 gdb/mips-tdep.c                     | 14 ++-------
 gdb/target.c                        | 13 ++------
 gdb/testsuite/ChangeLog             |  6 ++++
 gdb/testsuite/gdb.base/break.exp    |  4 ---
 gdb/testsuite/gdb.base/default.exp  |  4 +--
 gdb/testsuite/gdb.base/sepdebug.exp |  3 --
 gdb/tui/tui-win.c                   | 26 +++++----------
 gdb/utils.c                         | 36 +++++++--------------
 13 files changed, 86 insertions(+), 173 deletions(-)

-- 
2.17.2

Comments

Tom Tromey May 3, 2020, 7:54 p.m. | #1
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:


Tom> I looked at all the calls to add_prefix_cmd, and replaced them with
Tom> calls to add_basic_prefix_cmd or add_show_prefix_cmd when appropriate.
Tom> This makes gdb's command language a bit more regular.  I don't think
Tom> there's a significant downside.

Tom> Note that this patch removes a couple of tests.  The removed ones are
Tom> completely redundant.

I'm checking this in.

Tom

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 858f4c75691..4cba7740097 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -11214,19 +11214,8 @@  init_ada_exception_breakpoint (struct breakpoint *b,
   b->language = language_ada;
 }
 
-static void
-catch_command (const char *arg, int from_tty)
-{
-  error (_("Catch requires an event name."));
-}
 
 
-static void
-tcatch_command (const char *arg, int from_tty)
-{
-  error (_("Catch requires an event name."));
-}
-
 /* Compare two breakpoints and return a strcmp-like result.  */
 
 static int
@@ -14335,16 +14324,6 @@  enable_delete_command (const char *args, int from_tty)
      });
 }
 
-static void
-set_breakpoint_cmd (const char *args, int from_tty)
-{
-}
-
-static void
-show_breakpoint_cmd (const char *args, int from_tty)
-{
-}
-
 /* Invalidate last known value of any hardware watchpoint if
    the memory which that value represents has been written to by
    GDB itself.  */
@@ -15614,15 +15593,15 @@  Convenience variable \"$bpnum\" contains the number of the last\n\
 breakpoint set."),
 	   &maintenanceinfolist);
 
-  add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\
+  add_basic_prefix_cmd ("catch", class_breakpoint, _("\
 Set catchpoints to catch events."),
-		  &catch_cmdlist, "catch ",
-		  0/*allow-unknown*/, &cmdlist);
+			&catch_cmdlist, "catch ",
+			0/*allow-unknown*/, &cmdlist);
 
-  add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\
+  add_basic_prefix_cmd ("tcatch", class_breakpoint, _("\
 Set temporary catchpoints to catch events."),
-		  &tcatch_cmdlist, "tcatch ",
-		  0/*allow-unknown*/, &cmdlist);
+			&tcatch_cmdlist, "tcatch ",
+			0/*allow-unknown*/, &cmdlist);
 
   add_catch_command ("fork", _("Catch calls to fork."),
 		     catch_fork_command_1,
@@ -15799,18 +15778,18 @@  Use the 'source' command in another debug session to restore them."),
   c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
   deprecate_cmd (c, "save tracepoints");
 
-  add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\
+  add_basic_prefix_cmd ("breakpoint", class_maintenance, _("\
 Breakpoint specific settings.\n\
 Configure various breakpoint-specific variables such as\n\
 pending breakpoint behavior."),
-		  &breakpoint_set_cmdlist, "set breakpoint ",
-		  0/*allow-unknown*/, &setlist);
-  add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\
+			&breakpoint_set_cmdlist, "set breakpoint ",
+			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, "show breakpoint ",
-		  0/*allow-unknown*/, &showlist);
+		       &breakpoint_show_cmdlist, "show breakpoint ",
+		       0/*allow-unknown*/, &showlist);
 
   add_setshow_auto_boolean_cmd ("pending", no_class,
 				&pending_break_support, _("\
diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c
index d7c1b779bfe..a58cdcec876 100644
--- a/gdb/cli/cli-logging.c
+++ b/gdb/cli/cli-logging.c
@@ -165,55 +165,18 @@  set_logging_off (const char *args, int from_tty)
   saved_filename = NULL;
 }
 
-static void
-set_logging_command (const char *args, int from_tty)
-{
-  printf_unfiltered (_("\"set logging\" lets you log output to a file.\n"
-		       "Usage: set logging on [FILENAME]\n"
-		       "       set logging off\n"
-		       "       set logging file FILENAME\n"
-		       "       set logging overwrite [on|off]\n"
-		       "       set logging redirect [on|off]\n"));
-}
-
-static void
-show_logging_command (const char *args, int from_tty)
-{
-  if (saved_filename)
-    printf_unfiltered (_("Currently logging to \"%s\".\n"), saved_filename);
-  if (saved_filename == NULL
-      || strcmp (logging_filename, saved_filename) != 0)
-    printf_unfiltered (_("Future logs will be written to %s.\n"),
-		       logging_filename);
-
-  if (logging_overwrite)
-    printf_unfiltered (_("Logs will overwrite the log file.\n"));
-  else
-    printf_unfiltered (_("Logs will be appended to the log file.\n"));
-
-  if (logging_redirect)
-    printf_unfiltered (_("Output will be sent only to the log file.\n"));
-  else
-    printf_unfiltered (_("Output will be logged and displayed.\n"));
-
-  if (debug_redirect)
-    printf_unfiltered (_("Debug output will be sent only to the log file.\n"));
-  else
-    printf_unfiltered (_("Debug output will be logged and displayed.\n"));
-}
-
 void _initialize_cli_logging ();
 void
 _initialize_cli_logging ()
 {
   static struct cmd_list_element *set_logging_cmdlist, *show_logging_cmdlist;
 
-  add_prefix_cmd ("logging", class_support, set_logging_command,
-		  _("Set logging options."), &set_logging_cmdlist,
-		  "set logging ", 0, &setlist);
-  add_prefix_cmd ("logging", class_support, show_logging_command,
-		  _("Show logging options."), &show_logging_cmdlist,
-		  "show logging ", 0, &showlist);
+  add_basic_prefix_cmd ("logging", class_support,
+			_("Set logging options."), &set_logging_cmdlist,
+			"set logging ", 0, &setlist);
+  add_show_prefix_cmd ("logging", class_support,
+		       _("Show logging options."), &show_logging_cmdlist,
+		       "show logging ", 0, &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/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c
index 62fbe2a0b4d..23e938b0102 100644
--- a/gdb/dwarf2/index-cache.c
+++ b/gdb/dwarf2/index-cache.c
@@ -246,15 +246,6 @@  index_cache::make_index_filename (const bfd_build_id *build_id,
   return m_dir + SLASH_STRING + build_id_str + suffix;
 }
 
-/* "set index-cache" handler.  */
-
-static void
-set_index_cache_command (const char *arg, int from_tty)
-{
-  printf_unfiltered (_("\
-Missing arguments.  See \"help set index-cache\" for help.\n"));
-}
-
 /* True when we are executing "show index-cache".  This is used to improve the
    printout a little bit.  */
 static bool in_show_index_cache_command = false;
@@ -341,9 +332,10 @@  _initialize_index_cache ()
     warning (_("Couldn't determine a path for the index cache directory."));
 
   /* set index-cache */
-  add_prefix_cmd ("index-cache", class_files, set_index_cache_command,
-		  _("Set index-cache options."), &set_index_cache_prefix_list,
-		  "set index-cache ", false, &setlist);
+  add_basic_prefix_cmd ("index-cache", class_files,
+			_("Set index-cache options."),
+			&set_index_cache_prefix_list,
+			"set index-cache ", false, &setlist);
 
   /* show index-cache */
   add_prefix_cmd ("index-cache", class_files, show_index_cache_command,
diff --git a/gdb/memattr.c b/gdb/memattr.c
index da60df071c5..e38bc5c33ab 100644
--- a/gdb/memattr.c
+++ b/gdb/memattr.c
@@ -586,11 +586,6 @@  delete_mem_command (const char *args, int from_tty)
   dont_repeat ();
 }
 
-static void
-dummy_cmd (const char *args, int from_tty)
-{
-}
-
 static struct cmd_list_element *mem_set_cmdlist;
 static struct cmd_list_element *mem_show_cmdlist;
 
@@ -628,14 +623,14 @@  Do \"info mem\" to see current list of IDs."), &deletelist);
   add_info ("mem", info_mem_command,
 	    _("Memory region attributes."));
 
-  add_prefix_cmd ("mem", class_vars, dummy_cmd, _("\
+  add_basic_prefix_cmd ("mem", class_vars, _("\
 Memory regions settings."),
-		  &mem_set_cmdlist, "set mem ",
-		  0/* allow-unknown */, &setlist);
-  add_prefix_cmd ("mem", class_vars, dummy_cmd, _("\
+			&mem_set_cmdlist, "set mem ",
+			0/* allow-unknown */, &setlist);
+  add_show_prefix_cmd ("mem", class_vars, _("\
 Memory regions settings."),
-		  &mem_show_cmdlist, "show mem  ",
-		  0/* allow-unknown */, &showlist);
+		       &mem_show_cmdlist, "show mem  ",
+		       0/* allow-unknown */, &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 2e93f9e5fd3..e3d8581c9c9 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -6916,14 +6916,6 @@  show_mipsfpu_command (const char *args, int from_tty)
 }
 
 
-static void
-set_mipsfpu_command (const char *args, int from_tty)
-{
-  printf_unfiltered ("\"set mipsfpu\" must be followed by \"double\", "
-		     "\"single\",\"none\" or \"auto\".\n");
-  show_mipsfpu_command (args, from_tty);
-}
-
 static void
 set_mipsfpu_single_command (const char *args, int from_tty)
 {
@@ -9018,9 +9010,9 @@  and is updated automatically from ELF file flags if available."),
   /* Let the user turn off floating point and set the fence post for
      heuristic_proc_start.  */
 
-  add_prefix_cmd ("mipsfpu", class_support, set_mipsfpu_command,
-		  _("Set use of MIPS floating-point coprocessor."),
-		  &mipsfpulist, "set mipsfpu ", 0, &setlist);
+  add_basic_prefix_cmd ("mipsfpu", class_support,
+			_("Set use of MIPS floating-point coprocessor."),
+			&mipsfpulist, "set mipsfpu ", 0, &setlist);
   add_cmd ("single", class_support, set_mipsfpu_single_command,
 	   _("Select single-precision MIPS floating-point coprocessor."),
 	   &mipsfpulist);
diff --git a/gdb/target.c b/gdb/target.c
index 2dc356d935f..6982a806e3e 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -168,15 +168,6 @@  show_targetdebug (struct ui_file *file, int from_tty,
   fprintf_filtered (file, _("Target debugging is %s.\n"), value);
 }
 
-/* The user just typed 'target' without the name of a target.  */
-
-static void
-target_command (const char *arg, int from_tty)
-{
-  fputs_filtered ("Argument required (target name).  Try `help target'\n",
-		  gdb_stdout);
-}
-
 int
 target_has_all_memory_1 (void)
 {
@@ -269,13 +260,13 @@  add_target (const target_info &t, target_open_ftype *func,
   func_slot = func;
 
   if (targetlist == NULL)
-    add_prefix_cmd ("target", class_run, target_command, _("\
+    add_basic_prefix_cmd ("target", class_run, _("\
 Connect to a target machine or process.\n\
 The first argument is the type or protocol of the target machine.\n\
 Remaining arguments are interpreted by the target protocol.  For more\n\
 information on the arguments for a particular protocol, type\n\
 `help target ' followed by the protocol name."),
-		    &targetlist, "target ", 0, &cmdlist);
+			  &targetlist, "target ", 0, &cmdlist);
   c = add_cmd (t.shortname, no_class, t.doc, &targetlist);
   set_cmd_context (c, (void *) &t);
   set_cmd_sfunc (c, open_target);
diff --git a/gdb/testsuite/gdb.base/break.exp b/gdb/testsuite/gdb.base/break.exp
index 67cc8a7a26d..d6ee6487940 100644
--- a/gdb/testsuite/gdb.base/break.exp
+++ b/gdb/testsuite/gdb.base/break.exp
@@ -469,10 +469,6 @@  gdb_test "info break" "Num     Type.*Disp Enb Address.*What.*\[\r\n\]
 #
 if ![runto_main] then { fail "break tests suppressed" }
 
-gdb_test "catch" \
-    "Catch requires an event name." \
-    "catch requires an event name"
-
 gdb_test "catch fork" "Catchpoint \[0-9\]+ \\(fork\\)" \
     "set catch fork, never expected to trigger"
 
diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
index 846c91af6bc..95b92c48716 100644
--- a/gdb/testsuite/gdb.base/default.exp
+++ b/gdb/testsuite/gdb.base/default.exp
@@ -78,7 +78,7 @@  gdb_test "call" "The history is empty..*"
 
 
 #test catch
-gdb_test "catch" "Catch requires an event name..*"
+gdb_test "catch" "List of catch subcommands:(\[^\r\n\]*\[\r\n\])+Type \"help catch\" followed by catch subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous."
 
 #test cd
 gdb_test "cd" "Working directory \[^\r\n\]*\(\r\n \\(canonically \[^\r\n\]*\\)\)?\\."
@@ -794,7 +794,7 @@  gdb_expect {
 }
 
 #test target
-gdb_test "target" "Argument required .target name.*"
+gdb_test "target" "List of target subcommands:(\[^\r\n\]*\[\r\n\])+Type \"help target\" followed by target subcommand name for full documentation.(\[^\r\n\]*\[\r\n\])+Command name abbreviations are allowed if unambiguous."
 #test tbreak
 gdb_test "tbreak" "No default breakpoint address now."
 #test thread
diff --git a/gdb/testsuite/gdb.base/sepdebug.exp b/gdb/testsuite/gdb.base/sepdebug.exp
index 70f29d5b35f..bdbfa2c98ee 100644
--- a/gdb/testsuite/gdb.base/sepdebug.exp
+++ b/gdb/testsuite/gdb.base/sepdebug.exp
@@ -280,9 +280,6 @@  gdb_test "info break" "Num     Type.*Disp Enb Address.*What.*\[\r\n\]
 #
 if ![runto_main] then { fail "sepdebug tests suppressed" }
 
-gdb_test "catch" "Catch requires an event name.*" \
-    "catch requires an event name"
-
 gdb_test "catch fork" "Catchpoint \[0-9\]+ \\(fork\\)" \
     "set catch fork, never expected to trigger"
 
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 6546793d6bd..a78837fe689 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -298,16 +298,6 @@  tui_update_variables ()
   return need_redraw;
 }
 
-static void
-set_tui_cmd (const char *args, int from_tty)
-{
-}
-
-static void
-show_tui_cmd (const char *args, int from_tty)
-{
-}
-
 static struct cmd_list_element *tuilist;
 
 struct cmd_list_element **
@@ -1004,14 +994,14 @@  _initialize_tui_win ()
 
   /* Define the classes of commands.
      They will appear in the help list in the reverse of this order.  */
-  add_prefix_cmd ("tui", class_tui, set_tui_cmd,
-                  _("TUI configuration variables."),
-		  &tui_setlist, "set tui ",
-		  0 /* allow-unknown */, &setlist);
-  add_prefix_cmd ("tui", class_tui, show_tui_cmd,
-                  _("TUI configuration variables."),
-		  &tui_showlist, "show tui ",
-		  0 /* allow-unknown */, &showlist);
+  add_basic_prefix_cmd ("tui", class_tui,
+			_("TUI configuration variables."),
+			&tui_setlist, "set tui ",
+			0 /* allow-unknown */, &setlist);
+  add_show_prefix_cmd ("tui", class_tui,
+		       _("TUI configuration variables."),
+		       &tui_showlist, "show tui ",
+		       0 /* allow-unknown */, &showlist);
 
   add_com ("refresh", class_tui, tui_refresh_all_command,
            _("Refresh the terminal display."));
diff --git a/gdb/utils.c b/gdb/utils.c
index 2f2cd845c4b..989b13d0e0f 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -469,18 +469,6 @@  demangler_warning (const char *file, int line, const char *string, ...)
   va_end (ap);
 }
 
-/* Dummy functions to keep add_prefix_cmd happy.  */
-
-static void
-set_internal_problem_cmd (const char *args, int from_tty)
-{
-}
-
-static void
-show_internal_problem_cmd (const char *args, int from_tty)
-{
-}
-
 /* When GDB reports an internal problem (error or warning) it gives
    the user the opportunity to quit GDB and/or create a core file of
    the current debug session.  This function registers a few commands
@@ -515,19 +503,17 @@  add_internal_problem_command (struct internal_problem *problem)
   show_doc = xstrprintf (_("Show what GDB does when %s is detected."),
 			 problem->name);
 
-  add_prefix_cmd (problem->name,
-		  class_maintenance, set_internal_problem_cmd, set_doc,
-		  set_cmd_list,
-		  concat ("maintenance set ", problem->name, " ",
-			  (char *) NULL),
-		  0/*allow-unknown*/, &maintenance_set_cmdlist);
-
-  add_prefix_cmd (problem->name,
-		  class_maintenance, show_internal_problem_cmd, show_doc,
-		  show_cmd_list,
-		  concat ("maintenance show ", problem->name, " ",
-			  (char *) NULL),
-		  0/*allow-unknown*/, &maintenance_show_cmdlist);
+  add_basic_prefix_cmd (problem->name, class_maintenance, set_doc,
+			set_cmd_list,
+			concat ("maintenance set ", problem->name, " ",
+				(char *) NULL),
+			0/*allow-unknown*/, &maintenance_set_cmdlist);
+
+  add_show_prefix_cmd (problem->name, class_maintenance, show_doc,
+		       show_cmd_list,
+		       concat ("maintenance show ", problem->name, " ",
+			       (char *) NULL),
+		       0/*allow-unknown*/, &maintenance_show_cmdlist);
 
   if (problem->user_settable_should_quit)
     {