[binutils-gdb] gdb: remove unnecessary lookup_cmd when deprecating commands

Simon Marchi simark@sourceware.org
Thu May 27 18:00:26 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9f26053690299e3a5d295d78c4ceeaf840344f0b

commit 9f26053690299e3a5d295d78c4ceeaf840344f0b
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Thu May 27 13:59:00 2021 -0400

    gdb: remove unnecessary lookup_cmd when deprecating commands
    
    Remove a few instances where we look up a command by name, but could
    just use the return value of a previous "add command" function call
    instead.
    
    gdb/ChangeLog:
    
            * mi/mi-main.c (_initialize_mi_main):
            * python/py-auto-load.c (gdbpy_initialize_auto_load):
            * remote.c (_initialize_remote):
    
    Change-Id: I6d06f9ca636e340c88c1064ae870483ad392607d

Diff:
---
 gdb/ChangeLog             |  6 ++++++
 gdb/mi/mi-main.c          | 26 ++++++++++++++------------
 gdb/python/py-auto-load.c | 29 +++++++++++------------------
 gdb/remote.c              | 18 ++++++------------
 4 files changed, 37 insertions(+), 42 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8c17e20fb7d..354384a3937 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2021-05-27  Simon Marchi  <simon.marchi@polymtl.ca>
+
+	* mi/mi-main.c (_initialize_mi_main):
+	* python/py-auto-load.c (gdbpy_initialize_auto_load):
+	* remote.c (_initialize_remote):
+
 2021-05-27  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* command.h (set_show_commands): New.
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 9d205f0208b..e293dddc08d 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -2737,21 +2737,23 @@ void _initialize_mi_main ();
 void
 _initialize_mi_main ()
 {
-  struct cmd_list_element *c;
-
-  add_setshow_boolean_cmd ("mi-async", class_run,
-			   &mi_async_1, _("\
+  set_show_commands mi_async_cmds
+    = add_setshow_boolean_cmd ("mi-async", class_run,
+			       &mi_async_1, _("\
 Set whether MI asynchronous mode is enabled."), _("\
 Show whether MI asynchronous mode is enabled."), _("\
 Tells GDB whether MI should be in asynchronous mode."),
-			   set_mi_async_command,
-			   show_mi_async_command,
-			   &setlist,
-			   &showlist);
+			       set_mi_async_command,
+			       show_mi_async_command,
+			       &setlist, &showlist);
 
   /* Alias old "target-async" to "mi-async".  */
-  c = add_alias_cmd ("target-async", "mi-async", class_run, 0, &setlist);
-  deprecate_cmd (c, "set mi-async");
-  c = add_alias_cmd ("target-async", "mi-async", class_run, 0, &showlist);
-  deprecate_cmd (c, "show mi-async");
+  cmd_list_element *set_target_async_cmd
+    = add_alias_cmd ("target-async", mi_async_cmds.set, class_run, 0, &setlist);
+  deprecate_cmd (set_target_async_cmd, "set mi-async");
+
+  cmd_list_element *show_target_async_cmd
+    = add_alias_cmd ("target-async", mi_async_cmds.show, class_run, 0,
+		     &showlist);
+  deprecate_cmd (show_target_async_cmd, "show mi-async");
 }
diff --git a/gdb/python/py-auto-load.c b/gdb/python/py-auto-load.c
index 3b279312e88..20659858a56 100644
--- a/gdb/python/py-auto-load.c
+++ b/gdb/python/py-auto-load.c
@@ -59,9 +59,6 @@ info_auto_load_python_scripts (const char *pattern, int from_tty)
 int
 gdbpy_initialize_auto_load (void)
 {
-  struct cmd_list_element *cmd;
-  const char *cmd_name;
-
   add_setshow_boolean_cmd ("python-scripts", class_support,
 			   &auto_load_python_scripts, _("\
 Set the debugger's behaviour regarding auto-loaded Python scripts."), _("\
@@ -73,32 +70,28 @@ This options has security implications for untrusted inferiors."),
 			   auto_load_set_cmdlist_get (),
 			   auto_load_show_cmdlist_get ());
 
-  add_setshow_boolean_cmd ("auto-load-scripts", class_support,
-			   &auto_load_python_scripts, _("\
+  set_show_commands auto_load_scripts_cmds
+    = add_setshow_boolean_cmd ("auto-load-scripts", class_support,
+			       &auto_load_python_scripts, _("\
 Set the debugger's behaviour regarding auto-loaded Python scripts, "
 								 "deprecated."),
-			   _("\
+			       _("\
 Show the debugger's behaviour regarding auto-loaded Python scripts, "
 								 "deprecated."),
-			   NULL, NULL, show_auto_load_python_scripts,
-			   &setlist, &showlist);
-  cmd_name = "auto-load-scripts";
-  cmd = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
-  deprecate_cmd (cmd, "set auto-load python-scripts");
-
-  /* It is needed because lookup_cmd updates the CMD_NAME pointer.  */
-  cmd_name = "auto-load-scripts";
-  cmd = lookup_cmd (&cmd_name, showlist, "", NULL, -1, 1);
-  deprecate_cmd (cmd, "show auto-load python-scripts");
+			       NULL, NULL, show_auto_load_python_scripts,
+			       &setlist, &showlist);
+  deprecate_cmd (auto_load_scripts_cmds.set, "set auto-load python-scripts");
+  deprecate_cmd (auto_load_scripts_cmds.show, "show auto-load python-scripts");
 
   add_cmd ("python-scripts", class_info, info_auto_load_python_scripts,
 	   _("Print the list of automatically loaded Python scripts.\n\
 Usage: info auto-load python-scripts [REGEXP]"),
 	   auto_load_info_cmdlist_get ());
 
-  cmd = add_info ("auto-load-scripts", info_auto_load_python_scripts, _("\
+  cmd_list_element *info_auto_load_scripts_cmd
+    = add_info ("auto-load-scripts", info_auto_load_python_scripts, _("\
 Print the list of automatically loaded Python scripts, deprecated."));
-  deprecate_cmd (cmd, "info auto-load python-scripts");
+  deprecate_cmd (info_auto_load_scripts_cmd, "info auto-load python-scripts");
 
   return 0;
 }
diff --git a/gdb/remote.c b/gdb/remote.c
index aa98f5f951e..f2cb35116c8 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -14828,9 +14828,6 @@ void _initialize_remote ();
 void
 _initialize_remote ()
 {
-  struct cmd_list_element *cmd;
-  const char *cmd_name;
-
   /* architecture specific data */
   remote_g_packet_data_handle =
     gdbarch_data_register_pre_init (remote_g_packet_data_init);
@@ -14875,18 +14872,15 @@ response packet.  GDB supplies the initial `$' character, and the\n\
 terminating `#' character and checksum."),
 	   &maintenancelist);
 
-  add_setshow_boolean_cmd ("remotebreak", no_class, &remote_break, _("\
+  set_show_commands remotebreak_cmds
+    = add_setshow_boolean_cmd ("remotebreak", no_class, &remote_break, _("\
 Set whether to send break if interrupted."), _("\
 Show whether to send break if interrupted."), _("\
 If set, a break, instead of a cntrl-c, is sent to the remote target."),
-			   set_remotebreak, show_remotebreak,
-			   &setlist, &showlist);
-  cmd_name = "remotebreak";
-  cmd = lookup_cmd (&cmd_name, setlist, "", NULL, -1, 1);
-  deprecate_cmd (cmd, "set remote interrupt-sequence");
-  cmd_name = "remotebreak"; /* needed because lookup_cmd updates the pointer */
-  cmd = lookup_cmd (&cmd_name, showlist, "", NULL, -1, 1);
-  deprecate_cmd (cmd, "show remote interrupt-sequence");
+			       set_remotebreak, show_remotebreak,
+			       &setlist, &showlist);
+  deprecate_cmd (remotebreak_cmds.set, "set remote interrupt-sequence");
+  deprecate_cmd (remotebreak_cmds.show, "show remote interrupt-sequence");
 
   add_setshow_enum_cmd ("interrupt-sequence", class_support,
 			interrupt_sequence_modes, &interrupt_sequence_mode,


More information about the Gdb-cvs mailing list