public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/8] Change alias creation functions to accept target as cmd_list_element
@ 2021-05-18 20:23 Simon Marchi
  2021-05-18 20:23 ` [PATCH 1/8] gdb: make add_setshow commands return set_show_commands Simon Marchi
                   ` (7 more replies)
  0 siblings, 8 replies; 15+ messages in thread
From: Simon Marchi @ 2021-05-18 20:23 UTC (permalink / raw)
  To: gdb-patches

Following this patch:

    https://sourceware.org/pipermail/gdb-patches/2021-May/178881.html

I realized that we didn't support creating a command alias before the
command it aliases.  Although this doesn't happen normally, the fact
that alias creation functions accept the target command as a string (the
target command name) make it possible to happen.

I tried reversing the order of the calls of the initialize functions, to
see if there were any unintended dependencies between them.  For
example, a command created in a file and an alias for this command
created in another file.  This exposed one case where an alias is
created before a prefix of its target function, which made the alias
creation fail.

This fix this, this series changes all alias creation functions to take
the target command as a cmd_list_element.  This forces the target
command to be created before the alias.

Finally, it adds a runtime option (an environment variable) to reverse
the calls of the initialize functions, and a test is built using that.

Simon Marchi (8):
  gdb: make add_setshow commands return set_show_commands
  gdb: remove unnecessary lookup_cmd when deprecating commands
  gdb/python: use return values of add_setshow functions in
    add_setshow_generic
  gdb: make add_com_alias accept target as a cmd_list_element
  gdb: make add_info_alias accept target as a cmd_list_element
  gdb: remove add_alias_cmd overload that accepts a string
  gdb: add make-init-c script
  gdb: add option to reverse order of _initialize function calls

 gdb/Makefile.in                               |  51 ++--
 gdb/arch-utils.c                              |  16 +-
 gdb/bpf-tdep.c                                |   2 +-
 gdb/breakpoint.c                              |  78 +++---
 gdb/cli/cli-cmds.c                            |  67 ++---
 gdb/cli/cli-decode.c                          | 244 +++++++++---------
 gdb/command.h                                 | 229 ++++++----------
 gdb/compile/compile.c                         |   2 +-
 gdb/corefile.c                                |  14 +-
 gdb/cp-support.c                              |  12 +-
 gdb/disasm.c                                  |   9 +-
 gdb/gcore.c                                   |   5 +-
 gdb/gnu-nat.c                                 |  54 ++--
 gdb/guile/guile.c                             |  41 +--
 gdb/infcmd.c                                  |  60 +++--
 gdb/infrun.c                                  |   5 +-
 gdb/language.c                                |  24 +-
 gdb/macrocmd.c                                |  15 +-
 gdb/maint.c                                   |  19 +-
 gdb/make-init-c                               |  63 +++++
 gdb/mi/mi-main.c                              |  26 +-
 gdb/mips-tdep.c                               |  25 +-
 gdb/objc-lang.c                               |   7 +-
 gdb/printcmd.c                                |  16 +-
 gdb/python/py-auto-load.c                     |  29 +--
 gdb/python/py-param.c                         | 133 +++++-----
 gdb/python/python.c                           |   9 +-
 gdb/record-btrace.c                           |  30 ++-
 gdb/record-full.c                             |  69 ++---
 gdb/record.c                                  |  70 ++---
 gdb/regcache.c                                |   9 +-
 gdb/remote.c                                  |  37 ++-
 gdb/reverse.c                                 |  37 +--
 gdb/silent-rules.mk                           |   2 +-
 gdb/solib.c                                   |  22 +-
 gdb/source.c                                  |  21 +-
 gdb/sparc64-tdep.c                            |   7 +-
 gdb/stack.c                                   |  59 +++--
 gdb/symfile.c                                 |  11 +-
 gdb/symtab.c                                  |  11 +-
 .../gdb.base/reverse-init-functions.exp       |  29 +++
 gdb/thread.c                                  |   9 +-
 gdb/top.c                                     |   2 +-
 gdb/tracepoint.c                              |  12 +-
 gdb/tui/tui-win.c                             |  20 +-
 gdb/valprint.c                                |  24 +-
 gdb/value.c                                   |   5 +-
 gdb/windows-tdep.c                            |   9 +-
 48 files changed, 931 insertions(+), 819 deletions(-)
 create mode 100755 gdb/make-init-c
 create mode 100644 gdb/testsuite/gdb.base/reverse-init-functions.exp

-- 
2.31.1


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

* [PATCH 1/8] gdb: make add_setshow commands return set_show_commands
  2021-05-18 20:23 [PATCH 0/8] Change alias creation functions to accept target as cmd_list_element Simon Marchi
@ 2021-05-18 20:23 ` Simon Marchi
  2021-05-24 14:57   ` Tom Tromey
  2021-05-18 20:23 ` [PATCH 2/8] gdb: remove unnecessary lookup_cmd when deprecating commands Simon Marchi
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2021-05-18 20:23 UTC (permalink / raw)
  To: gdb-patches

Some add_set_show commands return a single cmd_list_element, the one for
the "set" command.  A subsequent patch will need to access the show
command's cmd_list_element as well.  Change these functions to return a
new structure type that holds both pointers.

I initially only modified add_setshow_boolean_cmd (the one I needed),
but I think it's better to change the whole chain to keep everything in
sync.

gdb/ChangeLog:

	* command.h (set_show_commands): New.
	(add_setshow_enum_cmd, add_setshow_auto_boolean_cmd,
	add_setshow_boolean_cmd, add_setshow_filename_cmd,
	add_setshow_string_cmd, add_setshow_string_noescape_cmd,
	add_setshow_optional_filename_cmd, add_setshow_integer_cmd,
	add_setshow_uinteger_cmd, add_setshow_zinteger_cmd,
	add_setshow_zuinteger_cmd, add_setshow_zuinteger_unlimited_cmd):
	Return set_show_commands.  Adjust callers.
	* cli/cli-decode.c (add_setshow_cmd_full): Return
	set_show_commands, remove result parameters, adjust callers.

Change-Id: I17492b01b76002d09effc84830f9c6db26f1db7a
---
 gdb/cli/cli-decode.c | 220 +++++++++++++++++++++----------------------
 gdb/command.h        | 214 ++++++++++++++++-------------------------
 gdb/corefile.c       |  12 +--
 gdb/disasm.c         |   9 +-
 gdb/stack.c          |  15 +--
 gdb/top.c            |   2 +-
 6 files changed, 208 insertions(+), 264 deletions(-)

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index fbead7004ed4..0482cca7a627 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -531,11 +531,11 @@ add_set_or_show_cmd (const char *name,
    setting.  VAR is address of the variable being controlled by this
    command.  SET_FUNC and SHOW_FUNC are the callback functions (if
    non-NULL).  SET_DOC, SHOW_DOC and HELP_DOC are the documentation
-   strings.  PRINT the format string to print the value.  SET_RESULT
-   and SHOW_RESULT, if not NULL, are set to the resulting command
-   structures.  */
+   strings.
 
-static void
+   Return the newly created set and show commands.  */
+
+static set_show_commands
 add_setshow_cmd_full (const char *name,
 		      enum command_class theclass,
 		      var_types var_type, void *var,
@@ -544,9 +544,7 @@ add_setshow_cmd_full (const char *name,
 		      cmd_const_sfunc_ftype *set_func,
 		      show_value_ftype *show_func,
 		      struct cmd_list_element **set_list,
-		      struct cmd_list_element **show_list,
-		      struct cmd_list_element **set_result,
-		      struct cmd_list_element **show_result)
+		      struct cmd_list_element **show_list)
 {
   struct cmd_list_element *set;
   struct cmd_list_element *show;
@@ -578,10 +576,7 @@ add_setshow_cmd_full (const char *name,
      for the "show" command to complete on anything.  */
   set_cmd_completer (show, nullptr);
 
-  if (set_result != NULL)
-    *set_result = set;
-  if (show_result != NULL)
-    *show_result = show;
+  return {set, show};
 }
 
 /* Add element named NAME to command list LIST (the list for set or
@@ -589,7 +584,7 @@ add_setshow_cmd_full (const char *name,
    of strings which may follow NAME.  VAR is address of the variable
    which will contain the matching string (from ENUMLIST).  */
 
-void
+set_show_commands
 add_setshow_enum_cmd (const char *name,
 		      enum command_class theclass,
 		      const char *const *enumlist,
@@ -603,17 +598,17 @@ add_setshow_enum_cmd (const char *name,
 		      struct cmd_list_element **show_list,
 		      void *context)
 {
-  struct cmd_list_element *c, *show;
+  set_show_commands commands
+    =  add_setshow_cmd_full (name, theclass, var_enum, var,
+			     set_doc, show_doc, help_doc,
+			     set_func, show_func,
+			     set_list, show_list);
+  commands.set->enums = enumlist;
 
-  add_setshow_cmd_full (name, theclass, var_enum, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			&c, &show);
-  c->enums = enumlist;
+  set_cmd_context (commands.set, context);
+  set_cmd_context (commands.show, context);
 
-  set_cmd_context (c, context);
-  set_cmd_context (show, context);
+  return commands;
 }
 
 /* See cli-decode.h.  */
@@ -623,7 +618,8 @@ const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL };
    command list lists.  CLASS is as in add_cmd.  VAR is address of the
    variable which will contain the value.  DOC is the documentation
    string.  FUNC is the corresponding callback.  */
-void
+
+set_show_commands
 add_setshow_auto_boolean_cmd (const char *name,
 			      enum command_class theclass,
 			      enum auto_boolean *var,
@@ -634,14 +630,15 @@ add_setshow_auto_boolean_cmd (const char *name,
 			      struct cmd_list_element **set_list,
 			      struct cmd_list_element **show_list)
 {
-  struct cmd_list_element *c;
+  set_show_commands commands
+    = add_setshow_cmd_full (name, theclass, var_auto_boolean, var,
+			    set_doc, show_doc, help_doc,
+			    set_func, show_func,
+			    set_list, show_list);
 
-  add_setshow_cmd_full (name, theclass, var_auto_boolean, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			&c, NULL);
-  c->enums = auto_boolean_enums;
+  commands.set->enums = auto_boolean_enums;
+
+  return commands;
 }
 
 /* See cli-decode.h.  */
@@ -653,7 +650,7 @@ const char * const boolean_enums[] = { "on", "off", NULL };
    value.  SET_DOC and SHOW_DOC are the documentation strings.
    Returns the new command element.  */
 
-cmd_list_element *
+set_show_commands
 add_setshow_boolean_cmd (const char *name, enum command_class theclass, bool *var,
 			 const char *set_doc, const char *show_doc,
 			 const char *help_doc,
@@ -662,21 +659,21 @@ add_setshow_boolean_cmd (const char *name, enum command_class theclass, bool *va
 			 struct cmd_list_element **set_list,
 			 struct cmd_list_element **show_list)
 {
-  struct cmd_list_element *c;
+  set_show_commands commands
+    = add_setshow_cmd_full (name, theclass, var_boolean, var,
+			    set_doc, show_doc, help_doc,
+			    set_func, show_func,
+			    set_list, show_list);
 
-  add_setshow_cmd_full (name, theclass, var_boolean, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			&c, NULL);
-  c->enums = boolean_enums;
+  commands.set->enums = boolean_enums;
 
-  return c;
+  return commands;
 }
 
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  */
-void
+
+set_show_commands
 add_setshow_filename_cmd (const char *name, enum command_class theclass,
 			  char **var,
 			  const char *set_doc, const char *show_doc,
@@ -686,19 +683,21 @@ add_setshow_filename_cmd (const char *name, enum command_class theclass,
 			  struct cmd_list_element **set_list,
 			  struct cmd_list_element **show_list)
 {
-  struct cmd_list_element *set_result;
+  set_show_commands commands
+    = add_setshow_cmd_full (name, theclass, var_filename, var,
+			    set_doc, show_doc, help_doc,
+			    set_func, show_func,
+			    set_list, show_list);
+
+  set_cmd_completer (commands.set, filename_completer);
 
-  add_setshow_cmd_full (name, theclass, var_filename, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			&set_result, NULL);
-  set_cmd_completer (set_result, filename_completer);
+  return commands;
 }
 
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  */
-void
+
+set_show_commands
 add_setshow_string_cmd (const char *name, enum command_class theclass,
 			char **var,
 			const char *set_doc, const char *show_doc,
@@ -708,21 +707,22 @@ add_setshow_string_cmd (const char *name, enum command_class theclass,
 			struct cmd_list_element **set_list,
 			struct cmd_list_element **show_list)
 {
-  cmd_list_element *set_cmd;
-
-  add_setshow_cmd_full (name, theclass, var_string, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			&set_cmd, NULL);
+  set_show_commands commands
+    = add_setshow_cmd_full (name, theclass, var_string, var,
+			    set_doc, show_doc, help_doc,
+			    set_func, show_func,
+			    set_list, show_list);
 
   /* Disable the default symbol completer.  */
-  set_cmd_completer (set_cmd, nullptr);
+  set_cmd_completer (commands.set, nullptr);
+
+  return commands;
 }
 
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  */
-struct cmd_list_element *
+
+set_show_commands
 add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
 				 char **var,
 				 const char *set_doc, const char *show_doc,
@@ -732,23 +732,22 @@ add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
 				 struct cmd_list_element **set_list,
 				 struct cmd_list_element **show_list)
 {
-  struct cmd_list_element *set_cmd;
-
-  add_setshow_cmd_full (name, theclass, var_string_noescape, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			&set_cmd, NULL);
+  set_show_commands commands
+    = add_setshow_cmd_full (name, theclass, var_string_noescape, var,
+			    set_doc, show_doc, help_doc,
+			    set_func, show_func,
+			    set_list, show_list);
 
   /* Disable the default symbol completer.  */
-  set_cmd_completer (set_cmd, nullptr);
+  set_cmd_completer (commands.set, nullptr);
 
-  return set_cmd;
+  return commands;
 }
 
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  */
-void
+
+set_show_commands
 add_setshow_optional_filename_cmd (const char *name, enum command_class theclass,
 				   char **var,
 				   const char *set_doc, const char *show_doc,
@@ -758,16 +757,15 @@ add_setshow_optional_filename_cmd (const char *name, enum command_class theclass
 				   struct cmd_list_element **set_list,
 				   struct cmd_list_element **show_list)
 {
-  struct cmd_list_element *set_result;
- 
-  add_setshow_cmd_full (name, theclass, var_optional_filename, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			&set_result, NULL);
+  set_show_commands commands
+    = add_setshow_cmd_full (name, theclass, var_optional_filename, var,
+			    set_doc, show_doc, help_doc,
+			    set_func, show_func,
+			    set_list, show_list);
 		
-  set_cmd_completer (set_result, filename_completer);
+  set_cmd_completer (commands.set, filename_completer);
 
+  return commands;
 }
 
 /* Completes on literal "unlimited".  Used by integer commands that
@@ -792,7 +790,8 @@ integer_unlimited_completer (struct cmd_list_element *ignore,
    add_cmd.  VAR is address of the variable which will contain the
    value.  SET_DOC and SHOW_DOC are the documentation strings.  This
    function is only used in Python API.  Please don't use it elsewhere.  */
-void
+
+set_show_commands
 add_setshow_integer_cmd (const char *name, enum command_class theclass,
 			 int *var,
 			 const char *set_doc, const char *show_doc,
@@ -802,22 +801,23 @@ add_setshow_integer_cmd (const char *name, enum command_class theclass,
 			 struct cmd_list_element **set_list,
 			 struct cmd_list_element **show_list)
 {
-  struct cmd_list_element *set;
+  set_show_commands commands
+    = add_setshow_cmd_full (name, theclass, var_integer, var,
+			    set_doc, show_doc, help_doc,
+			    set_func, show_func,
+			    set_list, show_list);
 
-  add_setshow_cmd_full (name, theclass, var_integer, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			&set, NULL);
+  set_cmd_completer (commands.set, integer_unlimited_completer);
 
-  set_cmd_completer (set, integer_unlimited_completer);
+  return commands;
 }
 
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  CLASS is as in
    add_cmd.  VAR is address of the variable which will contain the
    value.  SET_DOC and SHOW_DOC are the documentation strings.  */
-void
+
+set_show_commands
 add_setshow_uinteger_cmd (const char *name, enum command_class theclass,
 			  unsigned int *var,
 			  const char *set_doc, const char *show_doc,
@@ -827,22 +827,23 @@ add_setshow_uinteger_cmd (const char *name, enum command_class theclass,
 			  struct cmd_list_element **set_list,
 			  struct cmd_list_element **show_list)
 {
-  struct cmd_list_element *set;
+  set_show_commands commands
+    = add_setshow_cmd_full (name, theclass, var_uinteger, var,
+			    set_doc, show_doc, help_doc,
+			    set_func, show_func,
+			    set_list, show_list);
 
-  add_setshow_cmd_full (name, theclass, var_uinteger, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			&set, NULL);
+  set_cmd_completer (commands.set, integer_unlimited_completer);
 
-  set_cmd_completer (set, integer_unlimited_completer);
+  return commands;
 }
 
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  CLASS is as in
    add_cmd.  VAR is address of the variable which will contain the
    value.  SET_DOC and SHOW_DOC are the documentation strings.  */
-void
+
+set_show_commands
 add_setshow_zinteger_cmd (const char *name, enum command_class theclass,
 			  int *var,
 			  const char *set_doc, const char *show_doc,
@@ -852,14 +853,13 @@ add_setshow_zinteger_cmd (const char *name, enum command_class theclass,
 			  struct cmd_list_element **set_list,
 			  struct cmd_list_element **show_list)
 {
-  add_setshow_cmd_full (name, theclass, var_zinteger, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			NULL, NULL);
+  return add_setshow_cmd_full (name, theclass, var_zinteger, var,
+			       set_doc, show_doc, help_doc,
+			       set_func, show_func,
+			       set_list, show_list);
 }
 
-void
+set_show_commands
 add_setshow_zuinteger_unlimited_cmd (const char *name,
 				     enum command_class theclass,
 				     int *var,
@@ -871,22 +871,23 @@ add_setshow_zuinteger_unlimited_cmd (const char *name,
 				     struct cmd_list_element **set_list,
 				     struct cmd_list_element **show_list)
 {
-  struct cmd_list_element *set;
+  set_show_commands commands
+    = add_setshow_cmd_full (name, theclass, var_zuinteger_unlimited, var,
+			    set_doc, show_doc, help_doc,
+			    set_func, show_func,
+			    set_list, show_list);
 
-  add_setshow_cmd_full (name, theclass, var_zuinteger_unlimited, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			&set, NULL);
+  set_cmd_completer (commands.set, integer_unlimited_completer);
 
-  set_cmd_completer (set, integer_unlimited_completer);
+  return commands;
 }
 
 /* Add element named NAME to both the set and show command LISTs (the
    list for set/show or some sublist thereof).  CLASS is as in
    add_cmd.  VAR is address of the variable which will contain the
    value.  SET_DOC and SHOW_DOC are the documentation strings.  */
-void
+
+set_show_commands
 add_setshow_zuinteger_cmd (const char *name, enum command_class theclass,
 			   unsigned int *var,
 			   const char *set_doc, const char *show_doc,
@@ -896,11 +897,10 @@ add_setshow_zuinteger_cmd (const char *name, enum command_class theclass,
 			   struct cmd_list_element **set_list,
 			   struct cmd_list_element **show_list)
 {
-  add_setshow_cmd_full (name, theclass, var_zuinteger, var,
-			set_doc, show_doc, help_doc,
-			set_func, show_func,
-			set_list, show_list,
-			NULL, NULL);
+  return add_setshow_cmd_full (name, theclass, var_zuinteger, var,
+			       set_doc, show_doc, help_doc,
+			       set_func, show_func,
+			       set_list, show_list);
 }
 
 /* Remove the command named NAME from the command list.  Return the
diff --git a/gdb/command.h b/gdb/command.h
index 685038716a41..e82f2eabaed7 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -398,141 +398,85 @@ typedef void (show_value_ftype) (struct ui_file *file,
    instead print the value out directly.  */
 extern show_value_ftype deprecated_show_value_hack;
 
-extern void add_setshow_enum_cmd (const char *name,
-				  enum command_class theclass,
-				  const char *const *enumlist,
-				  const char **var,
-				  const char *set_doc,
-				  const char *show_doc,
-				  const char *help_doc,
-				  cmd_const_sfunc_ftype *set_func,
-				  show_value_ftype *show_func,
-				  struct cmd_list_element **set_list,
-				  struct cmd_list_element **show_list,
-				  void *context = nullptr);
-
-extern void add_setshow_auto_boolean_cmd (const char *name,
-					  enum command_class theclass,
-					  enum auto_boolean *var,
-					  const char *set_doc,
-					  const char *show_doc,
-					  const char *help_doc,
-					  cmd_const_sfunc_ftype *set_func,
-					  show_value_ftype *show_func,
-					  struct cmd_list_element **set_list,
-					  struct cmd_list_element **show_list);
-
-extern cmd_list_element *
-  add_setshow_boolean_cmd (const char *name,
-			   enum command_class theclass,
-			   bool *var,
-			   const char *set_doc, const char *show_doc,
-			   const char *help_doc,
-			   cmd_const_sfunc_ftype *set_func,
-			   show_value_ftype *show_func,
-			   struct cmd_list_element **set_list,
-			   struct cmd_list_element **show_list);
-
-extern void add_setshow_filename_cmd (const char *name,
-				      enum command_class theclass,
-				      char **var,
-				      const char *set_doc,
-				      const char *show_doc,
-				      const char *help_doc,
-				      cmd_const_sfunc_ftype *set_func,
-				      show_value_ftype *show_func,
-				      struct cmd_list_element **set_list,
-				      struct cmd_list_element **show_list);
-
-extern void add_setshow_string_cmd (const char *name,
-				    enum command_class theclass,
-				    char **var,
-				    const char *set_doc,
-				    const char *show_doc,
-				    const char *help_doc,
-				    cmd_const_sfunc_ftype *set_func,
-				    show_value_ftype *show_func,
-				    struct cmd_list_element **set_list,
-				    struct cmd_list_element **show_list);
-
-extern struct cmd_list_element *add_setshow_string_noescape_cmd
-		      (const char *name,
-		       enum command_class theclass,
-		       char **var,
-		       const char *set_doc,
-		       const char *show_doc,
-		       const char *help_doc,
-		       cmd_const_sfunc_ftype *set_func,
-		       show_value_ftype *show_func,
-		       struct cmd_list_element **set_list,
-		       struct cmd_list_element **show_list);
-
-extern void add_setshow_optional_filename_cmd (const char *name,
-					       enum command_class theclass,
-					       char **var,
-					       const char *set_doc,
-					       const char *show_doc,
-					       const char *help_doc,
-					       cmd_const_sfunc_ftype *set_func,
-					       show_value_ftype *show_func,
-					       struct cmd_list_element **set_list,
-					       struct cmd_list_element **show_list);
-
-extern void add_setshow_integer_cmd (const char *name,
-				     enum command_class theclass,
-				     int *var,
-				     const char *set_doc,
-				     const char *show_doc,
-				     const char *help_doc,
-				     cmd_const_sfunc_ftype *set_func,
-				     show_value_ftype *show_func,
-				     struct cmd_list_element **set_list,
-				     struct cmd_list_element **show_list);
-
-extern void add_setshow_uinteger_cmd (const char *name,
-				      enum command_class theclass,
-				      unsigned int *var,
-				      const char *set_doc,
-				      const char *show_doc,
-				      const char *help_doc,
-				      cmd_const_sfunc_ftype *set_func,
-				      show_value_ftype *show_func,
-				      struct cmd_list_element **set_list,
-				      struct cmd_list_element **show_list);
-
-extern void add_setshow_zinteger_cmd (const char *name,
-				      enum command_class theclass,
-				      int *var,
-				      const char *set_doc,
-				      const char *show_doc,
-				      const char *help_doc,
-				      cmd_const_sfunc_ftype *set_func,
-				      show_value_ftype *show_func,
-				      struct cmd_list_element **set_list,
-				      struct cmd_list_element **show_list);
-
-extern void add_setshow_zuinteger_cmd (const char *name,
-				       enum command_class theclass,
-				       unsigned int *var,
-				       const char *set_doc,
-				       const char *show_doc,
-				       const char *help_doc,
-				       cmd_const_sfunc_ftype *set_func,
-				       show_value_ftype *show_func,
-				       struct cmd_list_element **set_list,
-				       struct cmd_list_element **show_list);
-
-extern void
-  add_setshow_zuinteger_unlimited_cmd (const char *name,
-				       enum command_class theclass,
-				       int *var,
-				       const char *set_doc,
-				       const char *show_doc,
-				       const char *help_doc,
-				       cmd_const_sfunc_ftype *set_func,
-				       show_value_ftype *show_func,
-				       struct cmd_list_element **set_list,
-				       struct cmd_list_element **show_list);
+/* 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,
+   const char *help_doc, cmd_const_sfunc_ftype *set_func,
+   show_value_ftype *show_func, cmd_list_element **set_list,
+   cmd_list_element **show_list, void *context = nullptr);
+
+extern set_show_commands add_setshow_auto_boolean_cmd
+  (const char *name, command_class theclass, auto_boolean *var,
+   const char *set_doc, const char *show_doc, const char *help_doc,
+   cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func,
+   cmd_list_element **set_list, cmd_list_element **show_list);
+
+extern set_show_commands add_setshow_boolean_cmd
+  (const char *name, command_class theclass, bool *var, const char *set_doc,
+   const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func,
+   show_value_ftype *show_func, cmd_list_element **set_list,
+   cmd_list_element **show_list);
+
+extern set_show_commands add_setshow_filename_cmd
+  (const char *name, command_class theclass, char **var, const char *set_doc,
+   const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func,
+   show_value_ftype *show_func, cmd_list_element **set_list,
+   cmd_list_element **show_list);
+
+extern set_show_commands add_setshow_string_cmd
+  (const char *name, command_class theclass, char **var, const char *set_doc,
+   const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func,
+   show_value_ftype *show_func, cmd_list_element **set_list,
+   cmd_list_element **show_list);
+
+extern set_show_commands add_setshow_string_noescape_cmd
+  (const char *name, command_class theclass, char **var, const char *set_doc,
+   const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func,
+   show_value_ftype *show_func, cmd_list_element **set_list,
+   cmd_list_element **show_list);
+
+extern set_show_commands add_setshow_optional_filename_cmd
+  (const char *name, command_class theclass, char **var, const char *set_doc,
+   const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func,
+   show_value_ftype *show_func, cmd_list_element **set_list,
+   cmd_list_element **show_list);
+
+extern set_show_commands add_setshow_integer_cmd
+  (const char *name, command_class theclass, int *var, const char *set_doc,
+   const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func,
+   show_value_ftype *show_func, cmd_list_element **set_list,
+   cmd_list_element **show_list);
+
+extern set_show_commands add_setshow_uinteger_cmd
+  (const char *name, command_class theclass, unsigned int *var,
+   const char *set_doc, const char *show_doc, const char *help_doc,
+   cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func,
+   cmd_list_element **set_list, cmd_list_element **show_list);
+
+extern set_show_commands add_setshow_zinteger_cmd
+  (const char *name, command_class theclass, int *var, const char *set_doc,
+   const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func,
+   show_value_ftype *show_func, cmd_list_element **set_list,
+   cmd_list_element **show_list);
+
+extern set_show_commands add_setshow_zuinteger_cmd
+  (const char *name, command_class theclass, unsigned int *var,
+   const char *set_doc, const char *show_doc, const char *help_doc,
+   cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func,
+   cmd_list_element **set_list, cmd_list_element **show_list);
+
+extern set_show_commands add_setshow_zuinteger_unlimited_cmd
+  (const char *name, command_class theclass, int *var, const char *set_doc,
+   const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func,
+   show_value_ftype *show_func, cmd_list_element **set_list,
+   cmd_list_element **show_list);
 
 /* Do a "show" command for each thing on a command list.  */
 
diff --git a/gdb/corefile.c b/gdb/corefile.c
index 30960c129fda..ddaa77272a93 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -458,17 +458,17 @@ void _initialize_core ();
 void
 _initialize_core ()
 {
-  struct cmd_list_element *c;
-
-  c = add_cmd ("core-file", class_files, core_file_command, _("\
+  cmd_list_element *core_file_cmd
+    = add_cmd ("core-file", class_files, core_file_command, _("\
 Use FILE as core dump for examining memory and registers.\n\
 Usage: core-file FILE\n\
 No arg means have no core file.  This command has been superseded by the\n\
 `target core' and `detach' commands."), &cmdlist);
-  set_cmd_completer (c, filename_completer);
+  set_cmd_completer (core_file_cmd, filename_completer);
 
   
-  c = add_setshow_string_noescape_cmd ("gnutarget", class_files,
+  set_show_commands set_show_gnutarget
+    = add_setshow_string_noescape_cmd ("gnutarget", class_files,
 				       &gnutarget_string, _("\
 Set the current BFD target."), _("\
 Show the current BFD target."), _("\
@@ -476,7 +476,7 @@ Use `set gnutarget auto' to specify automatic detection."),
 				       set_gnutarget_command,
 				       show_gnutarget_string,
 				       &setlist, &showlist);
-  set_cmd_completer (c, complete_set_gnutarget);
+  set_cmd_completer (set_show_gnutarget.set, complete_set_gnutarget);
 
   add_alias_cmd ("g", "gnutarget", class_files, 1, &setlist);
 
diff --git a/gdb/disasm.c b/gdb/disasm.c
index eb69e89017b2..c4b4baf8c2d6 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -1139,11 +1139,10 @@ void _initialize_disasm ();
 void
 _initialize_disasm ()
 {
-  struct cmd_list_element *cmd;
-
   /* Add the command that controls the disassembler options.  */
-  cmd = add_setshow_string_noescape_cmd ("disassembler-options", no_class,
-					 &prospective_options, _("\
+  set_show_commands set_show_disas_opts
+    = add_setshow_string_noescape_cmd ("disassembler-options", no_class,
+				       &prospective_options, _("\
 Set the disassembler options.\n\
 Usage: set disassembler-options OPTION [,OPTION]...\n\n\
 See: 'show disassembler-options' for valid option values."), _("\
@@ -1151,5 +1150,5 @@ Show the disassembler options."), NULL,
 					 set_disassembler_options_sfunc,
 					 show_disassembler_options_sfunc,
 					 &setlist, &showlist);
-  set_cmd_completer (cmd, disassembler_options_completer);
+  set_cmd_completer (set_show_disas_opts.set, disassembler_options_completer);
 }
diff --git a/gdb/stack.c b/gdb/stack.c
index 7856a5a81765..334d9744dee1 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -3572,17 +3572,18 @@ Usage: func NAME"));
 
   /* Install "set print raw frame-arguments", a deprecated spelling of
      "set print raw-frame-arguments".  */
-  cmd = add_setshow_boolean_cmd
-    ("frame-arguments", no_class,
-     &user_frame_print_options.print_raw_frame_arguments,
-     _("\
+  set_show_commands set_show_frame_args
+    = add_setshow_boolean_cmd
+      ("frame-arguments", no_class,
+       &user_frame_print_options.print_raw_frame_arguments,
+       _("\
 Set whether to print frame arguments in raw form."), _("\
 Show whether to print frame arguments in raw form."), _("\
 If set, frame arguments are printed in raw form, bypassing any\n\
 pretty-printers for that value."),
-     NULL, NULL,
-     &setprintrawlist, &showprintrawlist);
-  deprecate_cmd (cmd, "set print raw-frame-arguments");
+       NULL, NULL,
+       &setprintrawlist, &showprintrawlist);
+  deprecate_cmd (set_show_frame_args.set, "set print raw-frame-arguments");
 
   add_setshow_auto_boolean_cmd ("disassemble-next-line", class_stack,
 				&disassemble_next_line, _("\
diff --git a/gdb/top.c b/gdb/top.c
index b9635368cacb..6e0f43d2fd92 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2345,7 +2345,7 @@ input settings."),
 			show_interactive_mode,
 			&setlist, &showlist);
 
-  c = add_setshow_boolean_cmd ("startup-quietly", class_support,
+  add_setshow_boolean_cmd ("startup-quietly", class_support,
 			       &startup_quiet, _("\
 Set whether GDB should start up quietly."), _("		\
 Show whether GDB should start up quietly."), _("\
-- 
2.31.1


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

* [PATCH 2/8] gdb: remove unnecessary lookup_cmd when deprecating commands
  2021-05-18 20:23 [PATCH 0/8] Change alias creation functions to accept target as cmd_list_element Simon Marchi
  2021-05-18 20:23 ` [PATCH 1/8] gdb: make add_setshow commands return set_show_commands Simon Marchi
@ 2021-05-18 20:23 ` Simon Marchi
  2021-05-18 20:23 ` [PATCH 3/8] gdb/python: use return values of add_setshow functions in add_setshow_generic Simon Marchi
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2021-05-18 20:23 UTC (permalink / raw)
  To: gdb-patches

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
---
 gdb/mi/mi-main.c          | 26 ++++++++++++++------------
 gdb/python/py-auto-load.c | 29 +++++++++++------------------
 gdb/remote.c              | 18 ++++++------------
 3 files changed, 31 insertions(+), 42 deletions(-)

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 582a55490d17..582629fca3b8 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 3b279312e888..20659858a564 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 aa98f5f951e8..f2cb35116c89 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,
-- 
2.31.1


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

* [PATCH 3/8] gdb/python: use return values of add_setshow functions in add_setshow_generic
  2021-05-18 20:23 [PATCH 0/8] Change alias creation functions to accept target as cmd_list_element Simon Marchi
  2021-05-18 20:23 ` [PATCH 1/8] gdb: make add_setshow commands return set_show_commands Simon Marchi
  2021-05-18 20:23 ` [PATCH 2/8] gdb: remove unnecessary lookup_cmd when deprecating commands Simon Marchi
@ 2021-05-18 20:23 ` Simon Marchi
  2021-05-18 20:23 ` [PATCH 4/8] gdb: make add_com_alias accept target as a cmd_list_element Simon Marchi
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2021-05-18 20:23 UTC (permalink / raw)
  To: gdb-patches

In add_setshow_generic, we create set/show commands using add_setshow_*
functions, then look up the commands by name to set the context pointer.
It would be simpler and more efficient to use the return values of the
add_setshow_* functions, do that.

gdb/ChangeLog:

	* python/py-param.c (add_setshow_generic): Use return values of
	add_setshow functions.

Change-Id: I04d50736e1001ddb732d81e088468876df9c88ff
---
 gdb/python/py-param.c | 133 +++++++++++++++++++++---------------------
 1 file changed, 66 insertions(+), 67 deletions(-)

diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 99a57960c059..d0a4850bdc04 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -465,113 +465,112 @@ add_setshow_generic (int parmclass, enum command_class cmdclass,
 		     struct cmd_list_element **set_list,
 		     struct cmd_list_element **show_list)
 {
-  struct cmd_list_element *param = NULL;
-  const char *tmp_name = NULL;
+  set_show_commands commands;
 
   switch (parmclass)
     {
     case var_boolean:
-
-      add_setshow_boolean_cmd (cmd_name.get (), cmdclass,
-			       &self->value.boolval, set_doc, show_doc,
-			       help_doc, get_set_value, get_show_value,
-			       set_list, show_list);
+      commands = add_setshow_boolean_cmd (cmd_name.get (), cmdclass,
+					  &self->value.boolval, set_doc,
+					  show_doc, help_doc, get_set_value,
+					  get_show_value, set_list, show_list);
 
       break;
 
     case var_auto_boolean:
-      add_setshow_auto_boolean_cmd (cmd_name.get (), cmdclass,
-				    &self->value.autoboolval,
-				    set_doc, show_doc, help_doc,
-				    get_set_value, get_show_value,
-				    set_list, show_list);
+      commands = add_setshow_auto_boolean_cmd (cmd_name.get (), cmdclass,
+					       &self->value.autoboolval,
+					       set_doc, show_doc, help_doc,
+					       get_set_value, get_show_value,
+					       set_list, show_list);
       break;
 
     case var_uinteger:
-      add_setshow_uinteger_cmd (cmd_name.get (), cmdclass,
-				&self->value.uintval, set_doc, show_doc,
-				help_doc, get_set_value, get_show_value,
-				set_list, show_list);
+      commands = add_setshow_uinteger_cmd (cmd_name.get (), cmdclass,
+					   &self->value.uintval, set_doc,
+					   show_doc, help_doc, get_set_value,
+					   get_show_value, set_list, show_list);
       break;
 
     case var_integer:
-      add_setshow_integer_cmd (cmd_name.get (), cmdclass,
-			       &self->value.intval, set_doc, show_doc,
-			       help_doc, get_set_value, get_show_value,
-			       set_list, show_list); break;
+      commands = add_setshow_integer_cmd (cmd_name.get (), cmdclass,
+					  &self->value.intval, set_doc,
+					  show_doc, help_doc, get_set_value,
+					  get_show_value, set_list, show_list);
+      break;
 
     case var_string:
-      add_setshow_string_cmd (cmd_name.get (), cmdclass,
-			      &self->value.stringval, set_doc, show_doc,
-			      help_doc, get_set_value, get_show_value,
-			      set_list, show_list); break;
+      commands = add_setshow_string_cmd (cmd_name.get (), cmdclass,
+					 &self->value.stringval, set_doc,
+					 show_doc, help_doc, get_set_value,
+					 get_show_value, set_list, show_list);
+      break;
 
     case var_string_noescape:
-      add_setshow_string_noescape_cmd (cmd_name.get (), cmdclass,
-				       &self->value.stringval,
-				       set_doc, show_doc, help_doc,
-				       get_set_value, get_show_value,
-				       set_list, show_list);
-
+      commands = add_setshow_string_noescape_cmd (cmd_name.get (), cmdclass,
+						  &self->value.stringval,
+						  set_doc, show_doc, help_doc,
+						  get_set_value, get_show_value,
+						  set_list, show_list);
       break;
 
     case var_optional_filename:
-      add_setshow_optional_filename_cmd (cmd_name.get (), cmdclass,
-					 &self->value.stringval, set_doc,
-					 show_doc, help_doc, get_set_value,
-					 get_show_value, set_list,
-					 show_list);
+      commands = add_setshow_optional_filename_cmd (cmd_name.get (), cmdclass,
+						    &self->value.stringval,
+						    set_doc, show_doc, help_doc,
+						    get_set_value,
+						    get_show_value, set_list,
+						    show_list);
       break;
 
     case var_filename:
-      add_setshow_filename_cmd (cmd_name.get (), cmdclass,
-				&self->value.stringval, set_doc, show_doc,
-				help_doc, get_set_value, get_show_value,
-				set_list, show_list); break;
+      commands = add_setshow_filename_cmd (cmd_name.get (), cmdclass,
+					   &self->value.stringval, set_doc,
+					   show_doc, help_doc, get_set_value,
+					   get_show_value, set_list, show_list);
+      break;
 
     case var_zinteger:
-      add_setshow_zinteger_cmd (cmd_name.get (), cmdclass,
-				&self->value.intval, set_doc, show_doc,
-				help_doc, get_set_value, get_show_value,
-				set_list, show_list);
+      commands = add_setshow_zinteger_cmd (cmd_name.get (), cmdclass,
+					   &self->value.intval, set_doc,
+					   show_doc, help_doc, get_set_value,
+					   get_show_value, set_list, show_list);
       break;
 
     case var_zuinteger:
-      add_setshow_zuinteger_cmd (cmd_name.get (), cmdclass,
-				&self->value.uintval, set_doc, show_doc,
-				help_doc, get_set_value, get_show_value,
-				set_list, show_list);
+      commands = add_setshow_zuinteger_cmd (cmd_name.get (), cmdclass,
+					    &self->value.uintval, set_doc,
+					    show_doc, help_doc, get_set_value,
+					    get_show_value, set_list,
+					    show_list);
       break;
 
     case var_zuinteger_unlimited:
-      add_setshow_zuinteger_unlimited_cmd (cmd_name.get (), cmdclass,
-					   &self->value.intval, set_doc,
-					   show_doc, help_doc, get_set_value,
-					   get_show_value,
-					   set_list, show_list);
+      commands = add_setshow_zuinteger_unlimited_cmd (cmd_name.get (), cmdclass,
+						      &self->value.intval,
+						      set_doc, show_doc,
+						      help_doc, get_set_value,
+						      get_show_value, set_list,
+						      show_list);
       break;
 
     case var_enum:
-      add_setshow_enum_cmd (cmd_name.get (), cmdclass, self->enumeration,
-			    &self->value.cstringval, set_doc, show_doc,
-			    help_doc, get_set_value, get_show_value,
-			    set_list, show_list);
+      commands = add_setshow_enum_cmd (cmd_name.get (), cmdclass,
+				       self->enumeration,
+				       &self->value.cstringval, set_doc,
+				       show_doc, help_doc, get_set_value,
+				       get_show_value, set_list, show_list);
       /* Initialize the value, just in case.  */
       self->value.cstringval = self->enumeration[0];
       break;
+
+    default:
+      gdb_assert_not_reached ("Unhandled parameter class.");
     }
 
-  /* Lookup created parameter, and register Python object against the
-     parameter context.  Perform this task against both lists.  */
-  tmp_name = cmd_name.get ();
-  param = lookup_cmd (&tmp_name, *show_list, "", NULL, 0, 1);
-  if (param)
-    set_cmd_context (param, self);
-
-  tmp_name = cmd_name.get ();
-  param = lookup_cmd (&tmp_name, *set_list, "", NULL, 0, 1);
-  if (param)
-    set_cmd_context (param, self);
+  /* Register Python objects in both commands' context.  */
+  set_cmd_context (commands.set, self);
+  set_cmd_context (commands.show, self);
 
   /* We (unfortunately) currently leak the command name.  */
   cmd_name.release ();
-- 
2.31.1


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

* [PATCH 4/8] gdb: make add_com_alias accept target as a cmd_list_element
  2021-05-18 20:23 [PATCH 0/8] Change alias creation functions to accept target as cmd_list_element Simon Marchi
                   ` (2 preceding siblings ...)
  2021-05-18 20:23 ` [PATCH 3/8] gdb/python: use return values of add_setshow functions in add_setshow_generic Simon Marchi
@ 2021-05-18 20:23 ` Simon Marchi
  2021-05-18 20:23 ` [PATCH 5/8] gdb: make add_info_alias " Simon Marchi
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2021-05-18 20:23 UTC (permalink / raw)
  To: gdb-patches

The alias creation functions currently accept a name to specify the
target command.  They pass this to add_alias_cmd, which needs to lookup
the target command by name.

Given that:

 - We don't support creating an alias for a command before that command
   exists.
 - We always use add_info_alias just after creating that target command,
   and therefore have access to the target command's cmd_list_element.

... change add_com_alias to accept the target command as a
cmd_list_element (other functions are done in subsequent patches).  This
ensures we don't create the alias before the target command, because you
need to get the cmd_list_element from somewhere when you call the alias
creation function.  And it avoids an unecessary command lookup.  So it
seems better to me in every aspect.

gdb/ChangeLog:

	* command.h (add_com_alias): Accept target as
	cmd_list_element.  Update callers.

Change-Id: I24bed7da57221cc77606034de3023fedac015150
---
 gdb/breakpoint.c      | 63 +++++++++++++++++++++++-------------------
 gdb/cli/cli-cmds.c    | 64 ++++++++++++++++++++++++-------------------
 gdb/cli/cli-decode.c  |  6 ++--
 gdb/command.h         |  6 ++--
 gdb/compile/compile.c |  2 +-
 gdb/gcore.c           |  5 ++--
 gdb/guile/guile.c     |  8 +++---
 gdb/infcmd.c          | 53 ++++++++++++++++++++---------------
 gdb/maint.c           |  9 +++---
 gdb/objc-lang.c       |  7 +++--
 gdb/printcmd.c        |  9 +++---
 gdb/python/python.c   |  9 +++---
 gdb/record.c          |  7 +++--
 gdb/regcache.c        |  9 +++---
 gdb/reverse.c         | 37 +++++++++++++------------
 gdb/source.c          | 21 +++++++-------
 gdb/stack.c           | 28 ++++++++++---------
 gdb/symfile.c         | 11 ++++----
 gdb/thread.c          |  9 +++---
 gdb/tracepoint.c      |  4 +--
 gdb/tui/tui-win.c     | 20 ++++++++------
 21 files changed, 214 insertions(+), 173 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index d479f0089489..1df0080dd520 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -15724,16 +15724,17 @@ so it will be deleted when hit.\n\
 BREAK_ARGS_HELP ("thbreak")));
   set_cmd_completer (c, location_completer);
 
-  add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
+  cmd_list_element *enable_cmd
+    = add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\
 Enable all or some breakpoints.\n\
 Usage: enable [BREAKPOINTNUM]...\n\
 Give breakpoint numbers (separated by spaces) as arguments.\n\
 With no subcommand, breakpoints are enabled until you command otherwise.\n\
 This is used to cancel the effect of the \"disable\" command.\n\
 With a subcommand you can enable temporarily."),
-		  &enablelist, 1, &cmdlist);
+		      &enablelist, 1, &cmdlist);
 
-  add_com_alias ("en", "enable", class_breakpoint, 1);
+  add_com_alias ("en", enable_cmd, class_breakpoint, 1);
 
   add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\
 Enable all or some breakpoints.\n\
@@ -15781,15 +15782,16 @@ If a breakpoint is hit while enabled in this fashion,\n\
 the count is decremented; when it reaches zero, the breakpoint is disabled."),
 	   &enablelist);
 
-  add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
+  cmd_list_element *disable_cmd
+    = add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\
 Disable all or some breakpoints.\n\
 Usage: disable [BREAKPOINTNUM]...\n\
 Arguments are breakpoint numbers with spaces in between.\n\
 To disable all breakpoints, give no argument.\n\
 A disabled breakpoint is not forgotten, but has no effect until re-enabled."),
-		  &disablelist, 1, &cmdlist);
-  add_com_alias ("dis", "disable", class_breakpoint, 1);
-  add_com_alias ("disa", "disable", class_breakpoint, 1);
+		      &disablelist, 1, &cmdlist);
+  add_com_alias ("dis", disable_cmd, class_breakpoint, 1);
+  add_com_alias ("disa", disable_cmd, class_breakpoint, 1);
 
   add_cmd ("breakpoints", class_breakpoint, disable_command, _("\
 Disable all or some breakpoints.\n\
@@ -15800,16 +15802,17 @@ A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\
 This command may be abbreviated \"disable\"."),
 	   &disablelist);
 
-  add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
+  cmd_list_element *delete_cmd
+    = add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\
 Delete all or some breakpoints.\n\
 Usage: delete [BREAKPOINTNUM]...\n\
 Arguments are breakpoint numbers with spaces in between.\n\
 To delete all breakpoints, give no argument.\n\
 \n\
 Also a prefix command for deletion of other GDB objects."),
-		  &deletelist, 1, &cmdlist);
-  add_com_alias ("d", "delete", class_breakpoint, 1);
-  add_com_alias ("del", "delete", class_breakpoint, 1);
+		      &deletelist, 1, &cmdlist);
+  add_com_alias ("d", delete_cmd, class_breakpoint, 1);
+  add_com_alias ("del", delete_cmd, class_breakpoint, 1);
 
   add_cmd ("breakpoints", class_breakpoint, delete_command, _("\
 Delete all or some breakpoints or auto-display expressions.\n\
@@ -15819,7 +15822,8 @@ To delete all breakpoints, give no argument.\n\
 This command may be abbreviated \"delete\"."),
 	   &deletelist);
 
-  add_com ("clear", class_breakpoint, clear_command, _("\
+  cmd_list_element *clear_cmd
+   = add_com ("clear", class_breakpoint, clear_command, _("\
 Clear breakpoint at specified location.\n\
 Argument may be a linespec, explicit, or address location as described below.\n\
 \n\
@@ -15827,17 +15831,18 @@ With no argument, clears all breakpoints in the line that the selected frame\n\
 is executing in.\n"
 "\n" LOCATION_HELP_STRING "\n\n\
 See also the \"delete\" command which clears breakpoints by number."));
-  add_com_alias ("cl", "clear", class_breakpoint, 1);
+  add_com_alias ("cl", clear_cmd, class_breakpoint, 1);
 
-  c = add_com ("break", class_breakpoint, break_command, _("\
+  cmd_list_element *break_cmd
+    = add_com ("break", class_breakpoint, break_command, _("\
 Set breakpoint at specified location.\n"
 BREAK_ARGS_HELP ("break")));
-  set_cmd_completer (c, location_completer);
+  set_cmd_completer (break_cmd, location_completer);
 
-  add_com_alias ("b", "break", class_run, 1);
-  add_com_alias ("br", "break", class_run, 1);
-  add_com_alias ("bre", "break", class_run, 1);
-  add_com_alias ("brea", "break", class_run, 1);
+  add_com_alias ("b", break_cmd, class_run, 1);
+  add_com_alias ("br", break_cmd, class_run, 1);
+  add_com_alias ("bre", break_cmd, class_run, 1);
+  add_com_alias ("brea", break_cmd, class_run, 1);
 
   if (dbx_commands)
     {
@@ -16006,17 +16011,18 @@ hardware.)"),
 
   /* Tracepoint manipulation commands.  */
 
-  c = add_com ("trace", class_breakpoint, trace_command, _("\
+  cmd_list_element *trace_cmd
+    = add_com ("trace", class_breakpoint, trace_command, _("\
 Set a tracepoint at specified location.\n\
 \n"
 BREAK_ARGS_HELP ("trace") "\n\
 Do \"help tracepoints\" for info on other tracepoint commands."));
-  set_cmd_completer (c, location_completer);
+  set_cmd_completer (trace_cmd, location_completer);
 
-  add_com_alias ("tp", "trace", class_breakpoint, 0);
-  add_com_alias ("tr", "trace", class_breakpoint, 1);
-  add_com_alias ("tra", "trace", class_breakpoint, 1);
-  add_com_alias ("trac", "trace", class_breakpoint, 1);
+  add_com_alias ("tp", trace_cmd, class_breakpoint, 0);
+  add_com_alias ("tr", trace_cmd, class_breakpoint, 1);
+  add_com_alias ("tra", trace_cmd, class_breakpoint, 1);
+  add_com_alias ("trac", trace_cmd, class_breakpoint, 1);
 
   c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\
 Set a fast tracepoint at specified location.\n\
@@ -16094,13 +16100,14 @@ session to restore them."),
 	       &save_cmdlist);
   set_cmd_completer (c, filename_completer);
 
-  c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
+  cmd_list_element *save_tracepoints_cmd
+    = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\
 Save current tracepoint definitions as a script.\n\
 Use the 'source' command in another debug session to restore them."),
 	       &save_cmdlist);
-  set_cmd_completer (c, filename_completer);
+  set_cmd_completer (save_tracepoints_cmd, filename_completer);
 
-  c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0);
+  c = add_com_alias ("save-tracepoints", save_tracepoints_cmd, class_trace, 0);
   deprecate_cmd (c, "save tracepoints");
 
   add_basic_prefix_cmd ("breakpoint", class_maintenance, _("\
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 0bf418e510ea..8b2aa5aad5a9 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1750,19 +1750,20 @@ argv_to_string (char **argv, int n)
    and the user would expect bbb to execute 'backtrace -full -past-main'
    while it will execute 'backtrace -past-main'.  */
 
-static void
+static cmd_list_element *
 validate_aliased_command (const char *command)
 {
-  struct cmd_list_element *c;
   std::string default_args;
-
-  c = lookup_cmd_1 (& command, cmdlist, NULL, &default_args, 1);
+  cmd_list_element *c
+    = lookup_cmd_1 (& command, cmdlist, NULL, &default_args, 1);
 
   if (c == NULL || c == (struct cmd_list_element *) -1)
     error (_("Invalid command to alias to: %s"), command);
 
   if (!default_args.empty ())
     error (_("Cannot define an alias of an alias that has default args"));
+
+  return c;
 }
 
 /* Called when "alias" was incorrectly used.  */
@@ -1832,7 +1833,7 @@ alias_command (const char *args, int from_tty)
   std::string command_string (argv_to_string (command_argv.get (),
 					      command_argc));
   command = command_string.c_str ();
-  validate_aliased_command (command);
+  cmd_list_element *target_cmd = validate_aliased_command (command);
 
   /* ALIAS must not exist.  */
   std::string alias_string (argv_to_string (alias_argv, alias_argc));
@@ -1875,8 +1876,8 @@ alias_command (const char *args, int from_tty)
   if (alias_argc == 1)
     {
       /* add_cmd requires *we* allocate space for name, hence the xstrdup.  */
-      alias_cmd = add_com_alias (xstrdup (alias_argv[0]), command, class_alias,
-				 a_opts.abbrev_flag);
+      alias_cmd = add_com_alias (xstrdup (alias_argv[0]), target_cmd,
+				 class_alias, a_opts.abbrev_flag);
     }
   else
     {
@@ -2332,16 +2333,18 @@ strict == evaluate script according to filename extension, error if not supporte
 			show_script_ext_mode,
 			&setlist, &showlist);
 
-  add_com ("quit", class_support, quit_command, _("\
+  cmd_list_element *quit_cmd
+    = add_com ("quit", class_support, quit_command, _("\
 Exit gdb.\n\
 Usage: quit [EXPR]\n\
 The optional expression EXPR, if present, is evaluated and the result\n\
 used as GDB's exit code.  The default is zero."));
-  c = add_com ("help", class_support, help_command,
+  cmd_list_element *help_cmd
+    = add_com ("help", class_support, help_command,
 	       _("Print list of commands."));
-  set_cmd_completer (c, command_completer);
-  add_com_alias ("q", "quit", class_support, 1);
-  add_com_alias ("h", "help", class_support, 1);
+  set_cmd_completer (help_cmd, command_completer);
+  add_com_alias ("q", quit_cmd, class_support, 1);
+  add_com_alias ("h", help_cmd, class_support, 1);
 
   add_setshow_boolean_cmd ("verbose", class_support, &info_verbose, _("\
 Set verbosity."), _("\
@@ -2365,11 +2368,12 @@ Without an argument, history expansion is enabled."),
 			   show_history_expansion_p,
 			   &sethistlist, &showhistlist);
 
-  add_prefix_cmd ("info", class_info, info_command, _("\
+  cmd_list_element *info_cmd
+    = add_prefix_cmd ("info", class_info, info_command, _("\
 Generic command for showing things about the program being debugged."),
-		  &infolist, 0, &cmdlist);
-  add_com_alias ("i", "info", class_info, 1);
-  add_com_alias ("inf", "info", class_info, 1);
+		      &infolist, 0, &cmdlist);
+  add_com_alias ("i", info_cmd, class_info, 1);
+  add_com_alias ("inf", info_cmd, class_info, 1);
 
   add_com ("complete", class_obscure, complete_command,
 	   _("List the completions for the rest of the line as a command."));
@@ -2380,7 +2384,8 @@ Generic command for showing things about the debugger."),
   /* Another way to get at the same thing.  */
   add_alias_cmd ("set", c, class_info, 0, &infolist);
 
-  c = add_com ("with", class_vars, with_command, _("\
+  cmd_list_element *with_cmd
+    = add_com ("with", class_vars, with_command, _("\
 Temporarily set SETTING to VALUE, run COMMAND, and restore SETTING.\n\
 Usage: with SETTING [VALUE] [-- COMMAND]\n\
 Usage: w SETTING [VALUE] [-- COMMAND]\n\
@@ -2394,8 +2399,8 @@ E.g.:\n\
 You can change multiple settings using nested with, and use\n\
 abbreviations for commands and/or values.  E.g.:\n\
   w la p -- w p el u -- p obj"));
-  set_cmd_completer_handle_brkchars (c, with_command_completer);
-  add_com_alias ("w", "with", class_vars, 1);
+  set_cmd_completer_handle_brkchars (with_cmd, with_command_completer);
+  add_com_alias ("w", with_cmd, class_vars, 1);
 
   add_internal_function ("_gdb_setting_str", _("\
 $_gdb_setting_str - returns the value of a GDB setting as a string.\n\
@@ -2455,12 +2460,13 @@ the previous command number shown."),
 		       _("Generic command for showing gdb debugging flags."),
 		       &showdebuglist, 0, &showlist);
 
-  c = add_com ("shell", class_support, shell_command, _("\
+  cmd_list_element *shell_cmd
+    = add_com ("shell", class_support, shell_command, _("\
 Execute the rest of the line as a shell command.\n\
 With no arguments, run an inferior shell."));
-  set_cmd_completer (c, filename_completer);
+  set_cmd_completer (shell_cmd, filename_completer);
 
-  add_com_alias ("!", "shell", class_support, 0);
+  add_com_alias ("!", shell_cmd, class_support, 0);
 
   c = add_com ("edit", class_files, edit_command, _("\
 Edit specified file or function.\n\
@@ -2474,7 +2480,8 @@ Uses EDITOR environment variable contents as editor (or ex as default)."));
 
   c->completer = location_completer;
 
-  c = add_com ("pipe", class_support, pipe_command, _("\
+  cmd_list_element *pipe_cmd
+    = add_com ("pipe", class_support, pipe_command, _("\
 Send the output of a gdb command to a shell command.\n\
 Usage: | [COMMAND] | SHELL_COMMAND\n\
 Usage: | -d DELIM COMMAND DELIM SHELL_COMMAND\n\
@@ -2489,10 +2496,11 @@ case COMMAND contains a | character.\n\
 \n\
 With no COMMAND, repeat the last executed command\n\
 and send its output to SHELL_COMMAND."));
-  set_cmd_completer_handle_brkchars (c, pipe_command_completer);
-  add_com_alias ("|", "pipe", class_support, 0);
+  set_cmd_completer_handle_brkchars (pipe_cmd, pipe_command_completer);
+  add_com_alias ("|", pipe_cmd, class_support, 0);
 
-  add_com ("list", class_files, list_command, _("\
+  cmd_list_element *list_cmd
+    = add_com ("list", class_files, list_command, _("\
 List specified function or line.\n\
 With no argument, lists ten more lines after or around previous listing.\n\
 \"list -\" lists the ten lines before a previous ten-line listing.\n\
@@ -2511,10 +2519,10 @@ By default, when a single location is given, display ten lines.\n\
 This can be changed using \"set listsize\", and the current value\n\
 can be shown using \"show listsize\"."));
 
-  add_com_alias ("l", "list", class_files, 1);
+  add_com_alias ("l", list_cmd, class_files, 1);
 
   if (dbx_commands)
-    add_com_alias ("file", "list", class_files, 1);
+    add_com_alias ("file", list_cmd, class_files, 1);
 
   c = add_com ("disassemble", class_vars, disassemble_command, _("\
 Disassemble a specified section of memory.\n\
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 0482cca7a627..dd6499621886 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -1007,11 +1007,11 @@ add_com (const char *name, enum command_class theclass,
    different of class_alias, as class_alias is used to identify
    user defined aliases.  */
 
-struct cmd_list_element *
-add_com_alias (const char *name, const char *target_name,
+cmd_list_element *
+add_com_alias (const char *name, cmd_list_element *target,
 	       command_class theclass, int abbrev_flag)
 {
-  return add_alias_cmd (name, target_name, theclass, abbrev_flag, &cmdlist);
+  return add_alias_cmd (name, target, theclass, abbrev_flag, &cmdlist);
 }
 
 /* Add an element with a suppress notification to the list of commands.  */
diff --git a/gdb/command.h b/gdb/command.h
index e82f2eabaed7..638de1efde91 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -359,8 +359,10 @@ extern struct cmd_list_element *add_com (const char *, enum command_class,
 					 cmd_const_cfunc_ftype *fun,
 					 const char *);
 
-extern struct cmd_list_element *add_com_alias (const char *, const char *,
-					       enum command_class, int);
+extern cmd_list_element *add_com_alias (const char *name,
+					cmd_list_element *target,
+					command_class theclass,
+					int abbrev_flag);
 
 extern struct cmd_list_element *add_com_suppress_notification
 		       (const char *name, enum command_class theclass,
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index c7f7d384752b..8481d14576ec 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -931,7 +931,7 @@ _initialize_compile ()
 					compile_command, _("\
 Command to compile source code and inject it into the inferior."),
 		  &compile_command_list, 1, &cmdlist);
-  add_com_alias ("expression", "compile", class_obscure, 0);
+  add_com_alias ("expression", compile_cmd_element, class_obscure, 0);
 
   const auto compile_opts = make_compile_options_def_group (nullptr);
 
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 3b9025322f32..76e856d71a81 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -604,10 +604,11 @@ void _initialize_gcore ();
 void
 _initialize_gcore ()
 {
-  add_com ("generate-core-file", class_files, gcore_command, _("\
+  cmd_list_element *generate_core_file_cmd
+    = add_com ("generate-core-file", class_files, gcore_command, _("\
 Save a core file with the current state of the debugged process.\n\
 Usage: generate-core-file [FILENAME]\n\
 Argument is optional filename.  Default filename is 'core.PROCESS_ID'."));
 
-  add_com_alias ("gcore", "generate-core-file", class_files, 1);
+  add_com_alias ("gcore", generate_core_file_cmd, class_files, 1);
 }
diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c
index 0166355b786b..a707c89b8461 100644
--- a/gdb/guile/guile.c
+++ b/gdb/guile/guile.c
@@ -726,8 +726,8 @@ cmd_list_element *guile_cmd_element = nullptr;
 static void
 install_gdb_commands (void)
 {
-  add_com ("guile-repl", class_obscure,
-	   guile_repl_command,
+  cmd_list_element *guile_repl_cmd
+    = add_com ("guile-repl", class_obscure, guile_repl_command,
 #ifdef HAVE_GUILE
 	   _("\
 Start an interactive Guile prompt.\n\
@@ -742,7 +742,7 @@ Guile scripting is not supported in this copy of GDB.\n\
 This command is only a placeholder.")
 #endif /* HAVE_GUILE */
 	   );
-  add_com_alias ("gr", "guile-repl", class_obscure, 1);
+  add_com_alias ("gr", guile_repl_cmd, class_obscure, 1);
 
   /* Since "help guile" is easy to type, and intuitive, we add general help
      in using GDB+Guile to this command.  */
@@ -778,7 +778,7 @@ Guile scripting is not supported in this copy of GDB.\n\
 This command is only a placeholder.")
 #endif /* HAVE_GUILE */
 	   );
-  add_com_alias ("gu", "guile", class_obscure, 1);
+  add_com_alias ("gu", guile_cmd_element, class_obscure, 1);
 
   add_basic_prefix_cmd ("guile", class_obscure,
 			_("Prefix command for Guile preference settings."),
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index a22d815f2302..5451b8be8fcb 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -3174,48 +3174,54 @@ In a multi-threaded program the signal is queued with, or discarded from,\n\
 the current thread only."));
   set_cmd_completer (c, signal_completer);
 
-  add_com ("stepi", class_run, stepi_command, _("\
+  cmd_list_element *stepi_cmd
+    = add_com ("stepi", class_run, stepi_command, _("\
 Step one instruction exactly.\n\
 Usage: stepi [N]\n\
 Argument N means step N times (or till program stops for another \
 reason)."));
-  add_com_alias ("si", "stepi", class_run, 0);
+  add_com_alias ("si", stepi_cmd, class_run, 0);
 
-  add_com ("nexti", class_run, nexti_command, _("\
+  cmd_list_element *nexti_cmd
+   = add_com ("nexti", class_run, nexti_command, _("\
 Step one instruction, but proceed through subroutine calls.\n\
 Usage: nexti [N]\n\
 Argument N means step N times (or till program stops for another \
 reason)."));
-  add_com_alias ("ni", "nexti", class_run, 0);
+  add_com_alias ("ni", nexti_cmd, class_run, 0);
 
-  add_com ("finish", class_run, finish_command, _("\
+  cmd_list_element *finish_cmd
+    = add_com ("finish", class_run, finish_command, _("\
 Execute until selected stack frame returns.\n\
 Usage: finish\n\
 Upon return, the value returned is printed and put in the value history."));
-  add_com_alias ("fin", "finish", class_run, 1);
+  add_com_alias ("fin", finish_cmd, class_run, 1);
 
-  add_com ("next", class_run, next_command, _("\
+  cmd_list_element *next_cmd
+    = add_com ("next", class_run, next_command, _("\
 Step program, proceeding through subroutine calls.\n\
 Usage: next [N]\n\
 Unlike \"step\", if the current source line calls a subroutine,\n\
 this command does not enter the subroutine, but instead steps over\n\
 the call, in effect treating it as a single source line."));
-  add_com_alias ("n", "next", class_run, 1);
+  add_com_alias ("n", next_cmd, class_run, 1);
 
-  add_com ("step", class_run, step_command, _("\
+  cmd_list_element *step_cmd
+    = add_com ("step", class_run, step_command, _("\
 Step program until it reaches a different source line.\n\
 Usage: step [N]\n\
 Argument N means step N times (or till program stops for another \
 reason)."));
-  add_com_alias ("s", "step", class_run, 1);
+  add_com_alias ("s", step_cmd, class_run, 1);
 
-  c = add_com ("until", class_run, until_command, _("\
+  cmd_list_element *until_cmd
+    = add_com ("until", class_run, until_command, _("\
 Execute until past the current line or past a LOCATION.\n\
 Execute until the program reaches a source line greater than the current\n\
 or a specified location (same args as break command) within the current \
 frame."));
-  set_cmd_completer (c, location_completer);
-  add_com_alias ("u", "until", class_run, 1);
+  set_cmd_completer (until_cmd, location_completer);
+  add_com_alias ("u", until_cmd, class_run, 1);
 
   c = add_com ("advance", class_run, advance_command, _("\
 Continue the program up to the given location (same form as args for break \
@@ -3223,15 +3229,17 @@ command).\n\
 Execution will also stop upon exit from the current stack frame."));
   set_cmd_completer (c, location_completer);
 
-  c = add_com ("jump", class_run, jump_command, _("\
+  cmd_list_element *jump_cmd
+    = add_com ("jump", class_run, jump_command, _("\
 Continue program being debugged at specified line or address.\n\
 Usage: jump LOCATION\n\
 Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\
 for an address to start at."));
-  set_cmd_completer (c, location_completer);
-  add_com_alias ("j", "jump", class_run, 1);
+  set_cmd_completer (jump_cmd, location_completer);
+  add_com_alias ("j", jump_cmd, class_run, 1);
 
-  add_com ("continue", class_run, continue_command, _("\
+  cmd_list_element *continue_cmd
+    = add_com ("continue", class_run, continue_command, _("\
 Continue program being debugged, after signal or breakpoint.\n\
 Usage: continue [N]\n\
 If proceeding from breakpoint, a number N may be used as an argument,\n\
@@ -3242,14 +3250,15 @@ If non-stop mode is enabled, continue only the current thread,\n\
 otherwise all the threads in the program are continued.  To \n\
 continue all stopped threads in non-stop mode, use the -a option.\n\
 Specifying -a and an ignore count simultaneously is an error."));
-  add_com_alias ("c", "cont", class_run, 1);
-  add_com_alias ("fg", "cont", class_run, 1);
+  add_com_alias ("c", continue_cmd, class_run, 1);
+  add_com_alias ("fg", continue_cmd, class_run, 1);
 
-  c = add_com ("run", class_run, run_command, _("\
+  cmd_list_element *run_cmd
+    = add_com ("run", class_run, run_command, _("\
 Start debugged program.\n"
 RUN_ARGS_HELP));
-  set_cmd_completer (c, filename_completer);
-  add_com_alias ("r", "run", class_run, 1);
+  set_cmd_completer (run_cmd, filename_completer);
+  add_com_alias ("r", run_cmd, class_run, 1);
 
   c = add_com ("start", class_run, start_command, _("\
 Start the debugged program stopping at the beginning of the main procedure.\n"
diff --git a/gdb/maint.c b/gdb/maint.c
index 154bef559811..91a7f77d0eb0 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -1133,14 +1133,15 @@ _initialize_maint_cmds ()
 {
   struct cmd_list_element *cmd;
 
-  add_basic_prefix_cmd ("maintenance", class_maintenance, _("\
+  cmd_list_element *maintenance_cmd
+    = add_basic_prefix_cmd ("maintenance", class_maintenance, _("\
 Commands for use by GDB maintainers.\n\
 Includes commands to dump specific internal GDB structures in\n\
 a human readable form, to cause GDB to deliberately dump core, etc."),
-			&maintenancelist, 0,
-			&cmdlist);
+			    &maintenancelist, 0,
+			    &cmdlist);
 
-  add_com_alias ("mt", "maintenance", class_maintenance, 1);
+  add_com_alias ("mt", maintenance_cmd, class_maintenance, 1);
 
   add_basic_prefix_cmd ("info", class_maintenance, _("\
 Commands for showing internal info about the program being debugged."),
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 1d440128a3d2..077ac772f79f 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -1319,9 +1319,10 @@ _initialize_objc_language ()
 	    _("All Objective-C selectors, or those matching REGEXP."));
   add_info ("classes", info_classes_command,
 	    _("All Objective-C classes, or those matching REGEXP."));
-  add_com ("print-object", class_vars, print_object_command, 
-	   _("Ask an Objective-C object to print itself."));
-  add_com_alias ("po", "print-object", class_vars, 1);
+  cmd_list_element *print_object_cmd
+    = add_com ("print-object", class_vars, print_object_command,
+	       _("Ask an Objective-C object to print itself."));
+  add_com_alias ("po", print_object_cmd, class_vars, 1);
 }
 
 static void 
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index a5c03c3a8307..8daa87cf978f 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -3351,10 +3351,11 @@ EXP may be preceded with /FMT, where FMT is a format letter\n\
 but no count or size letter (see \"x\" command)."),
 					      print_opts);
 
-  c = add_com ("print", class_vars, print_command, print_help.c_str ());
-  set_cmd_completer_handle_brkchars (c, print_command_completer);
-  add_com_alias ("p", "print", class_vars, 1);
-  add_com_alias ("inspect", "print", class_vars, 1);
+  cmd_list_element *print_cmd
+    = add_com ("print", class_vars, print_command, print_help.c_str ());
+  set_cmd_completer_handle_brkchars (print_cmd, print_command_completer);
+  add_com_alias ("p", print_cmd, class_vars, 1);
+  add_com_alias ("inspect", print_cmd, class_vars, 1);
 
   add_setshow_uinteger_cmd ("max-symbolic-offset", no_class,
 			    &max_symbolic_offset, _("\
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 4cea83c38373..e42cbc4fd5ee 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1886,8 +1886,9 @@ void _initialize_python ();
 void
 _initialize_python ()
 {
-  add_com ("python-interactive", class_obscure,
-	   python_interactive_command,
+  cmd_list_element *python_interactive_cmd
+    =	add_com ("python-interactive", class_obscure,
+		 python_interactive_command,
 #ifdef HAVE_PYTHON
 	   _("\
 Start an interactive Python prompt.\n\
@@ -1909,7 +1910,7 @@ Python scripting is not supported in this copy of GDB.\n\
 This command is only a placeholder.")
 #endif /* HAVE_PYTHON */
 	   );
-  add_com_alias ("pi", "python-interactive", class_obscure, 1);
+  add_com_alias ("pi", python_interactive_cmd, class_obscure, 1);
 
   python_cmd_element = add_com ("python", class_obscure, python_command,
 #ifdef HAVE_PYTHON
@@ -1931,7 +1932,7 @@ Python scripting is not supported in this copy of GDB.\n\
 This command is only a placeholder.")
 #endif /* HAVE_PYTHON */
 	   );
-  add_com_alias ("py", "python", class_obscure, 1);
+  add_com_alias ("py", python_cmd_element, class_obscure, 1);
 
   /* Add set/show python print-stack.  */
   add_basic_prefix_cmd ("python", no_class,
diff --git a/gdb/record.c b/gdb/record.c
index 7dae18f77b4f..a09137b34feb 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -785,12 +785,13 @@ A size of \"unlimited\" means unlimited lines.  The default is 10."),
 			    set_record_call_history_size, NULL,
 			    &set_record_cmdlist, &show_record_cmdlist);
 
-  c = add_prefix_cmd ("record", class_obscure, cmd_record_start,
+  cmd_list_element *record_cmd
+    = add_prefix_cmd ("record", class_obscure, cmd_record_start,
 		      _("Start recording."),
 		      &record_cmdlist, 0, &cmdlist);
-  set_cmd_completer (c, filename_completer);
+  set_cmd_completer (record_cmd, filename_completer);
 
-  add_com_alias ("rec", "record", class_obscure, 1);
+  add_com_alias ("rec", record_cmd, class_obscure, 1);
   add_basic_prefix_cmd ("record", class_support,
 			_("Set record options."), &set_record_cmdlist,
 			0, &setlist);
diff --git a/gdb/regcache.c b/gdb/regcache.c
index d2386308b822..93e216112548 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -2089,10 +2089,11 @@ _initialize_regcache ()
   gdb::observers::thread_ptid_changed.attach (regcache_thread_ptid_changed,
 					      "regcache");
 
-  add_cmd ("register-cache", class_maintenance, reg_flush_command,
-	   _("Force gdb to flush its register and frame cache."),
-	   &maintenanceflushlist);
-  c = add_com_alias ("flushregs", "maintenance flush register-cache",
+  cmd_list_element *maintenance_flush_register_cache_cmd
+    = add_cmd ("register-cache", class_maintenance, reg_flush_command,
+	       _("Force gdb to flush its register and frame cache."),
+	       &maintenanceflushlist);
+  c = add_com_alias ("flushregs", maintenance_flush_register_cache_cmd,
 		     class_maintenance, 0);
   deprecate_cmd (c, "maintenance flush register-cache");
 
diff --git a/gdb/reverse.c b/gdb/reverse.c
index e51defb27a3c..feca1b647309 100644
--- a/gdb/reverse.c
+++ b/gdb/reverse.c
@@ -326,38 +326,39 @@ void _initialize_reverse ();
 void
 _initialize_reverse ()
 {
-  add_com ("reverse-step", class_run, reverse_step, _("\
+  cmd_list_element *reverse_step_cmd
+   = add_com ("reverse-step", class_run, reverse_step, _("\
 Step program backward until it reaches the beginning of another source line.\n\
-Argument N means do this N times (or till program stops for another reason).")
-	   );
-  add_com_alias ("rs", "reverse-step", class_run, 1);
+Argument N means do this N times (or till program stops for another reason)."));
+  add_com_alias ("rs", reverse_step_cmd, class_run, 1);
 
-  add_com ("reverse-next", class_run, reverse_next, _("\
+  cmd_list_element *reverse_next_cmd
+    = add_com ("reverse-next", class_run, reverse_next, _("\
 Step program backward, proceeding through subroutine calls.\n\
 Like the \"reverse-step\" command as long as subroutine calls do not happen;\n\
 when they do, the call is treated as one instruction.\n\
-Argument N means do this N times (or till program stops for another reason).")
-	   );
-  add_com_alias ("rn", "reverse-next", class_run, 1);
+Argument N means do this N times (or till program stops for another reason)."));
+  add_com_alias ("rn", reverse_next_cmd, class_run, 1);
 
-  add_com ("reverse-stepi", class_run, reverse_stepi, _("\
+  cmd_list_element *reverse_stepi_cmd
+    = add_com ("reverse-stepi", class_run, reverse_stepi, _("\
 Step backward exactly one instruction.\n\
-Argument N means do this N times (or till program stops for another reason).")
-	   );
-  add_com_alias ("rsi", "reverse-stepi", class_run, 0);
+Argument N means do this N times (or till program stops for another reason)."));
+  add_com_alias ("rsi", reverse_stepi_cmd, class_run, 0);
 
-  add_com ("reverse-nexti", class_run, reverse_nexti, _("\
+  cmd_list_element *reverse_nexti_cmd
+    = add_com ("reverse-nexti", class_run, reverse_nexti, _("\
 Step backward one instruction, but proceed through called subroutines.\n\
-Argument N means do this N times (or till program stops for another reason).")
-	   );
-  add_com_alias ("rni", "reverse-nexti", class_run, 0);
+Argument N means do this N times (or till program stops for another reason)."));
+  add_com_alias ("rni", reverse_nexti_cmd, class_run, 0);
 
-  add_com ("reverse-continue", class_run, reverse_continue, _("\
+  cmd_list_element *reverse_continue_cmd
+    = add_com ("reverse-continue", class_run, reverse_continue, _("\
 Continue program being debugged but run it in reverse.\n\
 If proceeding from breakpoint, a number N may be used as an argument,\n\
 which means to set the ignore count of that breakpoint to N - 1 (so that\n\
 the breakpoint won't break until the Nth time it is reached)."));
-  add_com_alias ("rc", "reverse-continue", class_run, 0);
+  add_com_alias ("rc", reverse_continue_cmd, class_run, 0);
 
   add_com ("reverse-finish", class_run, reverse_finish, _("\
 Execute backward until just before selected stack frame is called."));
diff --git a/gdb/source.c b/gdb/source.c
index b6dab6eb236a..a922a6c559cd 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1904,8 +1904,6 @@ void _initialize_source ();
 void
 _initialize_source ()
 {
-  struct cmd_list_element *c;
-
   init_source_path ();
 
   /* The intention is to use POSIX Basic Regular Expressions.
@@ -1914,7 +1912,8 @@ _initialize_source ()
      just an approximation.  */
   re_set_syntax (RE_SYNTAX_GREP);
 
-  c = add_cmd ("directory", class_files, directory_command, _("\
+  cmd_list_element *directory_cmd
+    = add_cmd ("directory", class_files, directory_command, _("\
 Add directory DIR to beginning of search path for source files.\n\
 Forget cached info on source file locations and line positions.\n\
 DIR can also be $cwd for the current working directory, or $cdir for the\n\
@@ -1923,9 +1922,9 @@ With no argument, reset the search path to $cdir:$cwd, the default."),
 	       &cmdlist);
 
   if (dbx_commands)
-    add_com_alias ("use", "directory", class_files, 0);
+    add_com_alias ("use", directory_cmd, class_files, 0);
 
-  set_cmd_completer (c, filename_completer);
+  set_cmd_completer (directory_cmd, filename_completer);
 
   add_setshow_optional_filename_cmd ("directories",
 				     class_files,
@@ -1959,16 +1958,18 @@ This sets the default address for \"x\" to the line's first instruction\n\
 so that \"x/i\" suffices to start examining the machine code.\n\
 The address is also stored as the value of \"$_\"."));
 
-  add_com ("forward-search", class_files, forward_search_command, _("\
+  cmd_list_element *forward_search_cmd
+    = add_com ("forward-search", class_files, forward_search_command, _("\
 Search for regular expression (see regex(3)) from last line listed.\n\
 The matching line number is also stored as the value of \"$_\"."));
-  add_com_alias ("search", "forward-search", class_files, 0);
-  add_com_alias ("fo", "forward-search", class_files, 1);
+  add_com_alias ("search", forward_search_cmd, class_files, 0);
+  add_com_alias ("fo", forward_search_cmd, class_files, 1);
 
-  add_com ("reverse-search", class_files, reverse_search_command, _("\
+  cmd_list_element *reverse_search_cmd
+    = add_com ("reverse-search", class_files, reverse_search_command, _("\
 Search backward for regular expression (see regex(3)) from last line listed.\n\
 The matching line number is also stored as the value of \"$_\"."));
-  add_com_alias ("rev", "reverse-search", class_files, 1);
+  add_com_alias ("rev", reverse_search_cmd, class_files, 1);
 
   add_setshow_integer_cmd ("listsize", class_support, &lines_to_list, _("\
 Set number of source lines gdb will list by default."), _("\
diff --git a/gdb/stack.c b/gdb/stack.c
index 334d9744dee1..a3a6ba6c4196 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -3329,22 +3329,24 @@ An argument says how many frames up to go."));
 Same as the `up' command, but does not print anything.\n\
 This is useful in command scripts."));
 
-  add_com ("down", class_stack, down_command, _("\
+  cmd_list_element *down_cmd
+    = add_com ("down", class_stack, down_command, _("\
 Select and print stack frame called by this one.\n\
 An argument says how many frames down to go."));
-  add_com_alias ("do", "down", class_stack, 1);
-  add_com_alias ("dow", "down", class_stack, 1);
+  add_com_alias ("do", down_cmd, class_stack, 1);
+  add_com_alias ("dow", down_cmd, class_stack, 1);
   add_com ("down-silently", class_support, down_silently_command, _("\
 Same as the `down' command, but does not print anything.\n\
 This is useful in command scripts."));
 
-  add_prefix_cmd ("frame", class_stack,
-		  &frame_cmd.base_command, _("\
+  cmd_list_element *frame_cmd_el
+    = add_prefix_cmd ("frame", class_stack,
+		      &frame_cmd.base_command, _("\
 Select and print a stack frame.\n\
 With no argument, print the selected stack frame.  (See also \"info frame\").\n\
 A single numerical argument specifies the frame to select."),
-		  &frame_cmd_list, 1, &cmdlist);
-  add_com_alias ("f", "frame", class_stack, 1);
+		      &frame_cmd_list, 1, &cmdlist);
+  add_com_alias ("f", frame_cmd_el, class_stack, 1);
 
 #define FRAME_APPLY_OPTION_HELP "\
 Prints the frame location information followed by COMMAND output.\n\
@@ -3498,14 +3500,14 @@ For backward compatibility, the following qualifiers are supported:\n\
 With a negative COUNT, print outermost -COUNT frames."),
 			       backtrace_opts);
 
-  cmd_list_element *c = add_com ("backtrace", class_stack,
-				 backtrace_command,
-				 backtrace_help.c_str ());
-  set_cmd_completer_handle_brkchars (c, backtrace_command_completer);
+  cmd_list_element *backtrace_cmd
+    = add_com ("backtrace", class_stack, backtrace_command,
+	       backtrace_help.c_str ());
+  set_cmd_completer_handle_brkchars (backtrace_cmd, backtrace_command_completer);
 
-  add_com_alias ("bt", "backtrace", class_stack, 0);
+  add_com_alias ("bt", backtrace_cmd, class_stack, 0);
 
-  add_com_alias ("where", "backtrace", class_stack, 0);
+  add_com_alias ("where", backtrace_cmd, class_stack, 0);
   add_info ("stack", backtrace_command,
 	    _("Backtrace of the stack, or innermost COUNT frames."));
   add_info_alias ("s", "stack", 1);
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 4ba695360fbc..b2034c6e0c36 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3863,12 +3863,13 @@ When OFFSET is provided, FILE must also be provided.  FILE can be provided\n\
 on its own."), &cmdlist);
   set_cmd_completer (c, filename_completer);
 
-  add_basic_prefix_cmd ("overlay", class_support,
-			_("Commands for debugging overlays."), &overlaylist,
-			0, &cmdlist);
+  cmd_list_element *overlay_cmd
+    = add_basic_prefix_cmd ("overlay", class_support,
+			    _("Commands for debugging overlays."), &overlaylist,
+			    0, &cmdlist);
 
-  add_com_alias ("ovly", "overlay", class_support, 1);
-  add_com_alias ("ov", "overlay", class_support, 1);
+  add_com_alias ("ovly", overlay_cmd, class_support, 1);
+  add_com_alias ("ov", overlay_cmd, class_support, 1);
 
   add_cmd ("map-overlay", class_support, map_overlay_command,
 	   _("Assert that an overlay section is mapped."), &overlaylist);
diff --git a/gdb/thread.c b/gdb/thread.c
index 3cd588e0b121..8d8135c5b504 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -2134,10 +2134,13 @@ Options:\n\
   c = add_info ("threads", info_threads_command, info_threads_help.c_str ());
   set_cmd_completer_handle_brkchars (c, info_threads_command_completer);
 
-  add_prefix_cmd ("thread", class_run, thread_command, _("\
+  cmd_list_element *thread_cmd
+    = add_prefix_cmd ("thread", class_run, thread_command, _("\
 Use this command to switch between threads.\n\
 The new thread ID must be currently known."),
-		  &thread_cmd_list, 1, &cmdlist);
+		      &thread_cmd_list, 1, &cmdlist);
+
+  add_com_alias ("t", thread_cmd, class_run, 1);
 
 #define THREAD_APPLY_OPTION_HELP "\
 Prints per-inferior thread number and target system's thread id\n\
@@ -2204,8 +2207,6 @@ Usage: thread find REGEXP\n\
 Will display thread ids whose name, target ID, or extra info matches REGEXP."),
 	   &thread_cmd_list);
 
-  add_com_alias ("t", "thread", class_run, 1);
-
   add_setshow_boolean_cmd ("thread-events", no_class,
 			   &print_thread_events, _("\
 Set printing of thread events (such as thread start and exit)."), _("\
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 7f6d3e4a16be..e7e0d7be70bd 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -4116,8 +4116,8 @@ one or more \"collect\" commands, to specify what to collect\n\
 while single-stepping.\n\n\
 Note: this command can only be used in a tracepoint \"actions\" list."));
 
-  add_com_alias ("ws", "while-stepping", class_trace, 0);
-  add_com_alias ("stepping", "while-stepping", class_trace, 0);
+  add_com_alias ("ws", while_stepping_cmd_element, class_trace, 0);
+  add_com_alias ("stepping", while_stepping_cmd_element, class_trace, 0);
 
   add_com ("collect", class_trace, collect_pseudocommand, _("\
 Specify one or more data items to be collected at a tracepoint.\n\
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index f036127b018c..4e75a66a00e9 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -990,7 +990,6 @@ _initialize_tui_win ()
 {
   static struct cmd_list_element *tui_setlist;
   static struct cmd_list_element *tui_showlist;
-  struct cmd_list_element *cmd;
 
   /* Define the classes of commands.
      They will appear in the help list in the reverse of this order.  */
@@ -1004,26 +1003,29 @@ _initialize_tui_win ()
   add_com ("refresh", class_tui, tui_refresh_all_command,
 	   _("Refresh the terminal display."));
 
-  cmd = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
+  cmd_list_element *tabset_cmd
+    = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
 Set the width (in characters) of tab stops.\n\
 Usage: tabset N"));
-  deprecate_cmd (cmd, "set tui tab-width");
+  deprecate_cmd (tabset_cmd, "set tui tab-width");
 
-  cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\
+  cmd_list_element *winheight_cmd
+    = add_com ("winheight", class_tui, tui_set_win_height_command, _("\
 Set or modify the height of a specified window.\n\
 Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n\
 Use \"info win\" to see the names of the windows currently being displayed."));
-  add_com_alias ("wh", "winheight", class_tui, 0);
-  set_cmd_completer (cmd, winheight_completer);
+  add_com_alias ("wh", winheight_cmd, class_tui, 0);
+  set_cmd_completer (winheight_cmd, winheight_completer);
   add_info ("win", tui_all_windows_info,
 	    _("List of all displayed windows.\n\
 Usage: info win"));
-  cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\
+  cmd_list_element *focus_cmd
+    = add_com ("focus", class_tui, tui_set_focus_command, _("\
 Set focus to named window or next/prev window.\n\
 Usage: focus [WINDOW-NAME | next | prev]\n\
 Use \"info win\" to see the names of the windows currently being displayed."));
-  add_com_alias ("fs", "focus", class_tui, 0);
-  set_cmd_completer (cmd, focus_completer);
+  add_com_alias ("fs", focus_cmd, class_tui, 0);
+  set_cmd_completer (focus_cmd, focus_completer);
   add_com ("+", class_tui, tui_scroll_forward_command, _("\
 Scroll window forward.\n\
 Usage: + [N] [WIN]\n\
-- 
2.31.1


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

* [PATCH 5/8] gdb: make add_info_alias accept target as a cmd_list_element
  2021-05-18 20:23 [PATCH 0/8] Change alias creation functions to accept target as cmd_list_element Simon Marchi
                   ` (3 preceding siblings ...)
  2021-05-18 20:23 ` [PATCH 4/8] gdb: make add_com_alias accept target as a cmd_list_element Simon Marchi
@ 2021-05-18 20:23 ` Simon Marchi
  2021-05-18 20:23 ` [PATCH 6/8] gdb: remove add_alias_cmd overload that accepts a string Simon Marchi
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2021-05-18 20:23 UTC (permalink / raw)
  To: gdb-patches

Same idea as previous patch, but for add_info_alias.

gdb/ChangeLog:

	* command.h (add_info_alias): Accept target as
	cmd_list_element.  Update callers.

Change-Id: If830d423364bf42d7bea5ac4dd3a81adcfce6f7a
---
 gdb/breakpoint.c     | 10 ++++++----
 gdb/cli/cli-decode.c |  6 +++---
 gdb/command.h        |  5 +++--
 gdb/guile/guile.c    |  9 +++++----
 gdb/infcmd.c         |  7 ++++---
 gdb/infrun.c         |  5 +++--
 gdb/solib.c          |  7 ++++---
 gdb/stack.c          | 18 ++++++++++--------
 8 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 1df0080dd520..ae05d1802a8c 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -15870,7 +15870,8 @@ Convenience variable \"$bpnum\" contains the number of the last\n\
 breakpoint set."));
     }
 
-  add_info ("breakpoints", info_breakpoints_command, _("\
+  cmd_list_element *info_breakpoints_cmd
+    = add_info ("breakpoints", info_breakpoints_command, _("\
 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\
 The \"Type\" column indicates one of:\n\
 \tbreakpoint     - normal breakpoint\n\
@@ -15886,7 +15887,7 @@ is prefixed with \"server \".\n\n\
 Convenience variable \"$bpnum\" contains the number of the last\n\
 breakpoint set."));
 
-  add_info_alias ("b", "breakpoints", 1);
+  add_info_alias ("b", info_breakpoints_cmd, 1);
 
   add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\
 Status of all breakpoints, or breakpoint number NUMBER.\n\
@@ -16053,12 +16054,13 @@ Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\
 Do \"help tracepoints\" for info on other tracepoint commands."));
   set_cmd_completer (c, location_completer);
 
-  add_info ("tracepoints", info_tracepoints_command, _("\
+  cmd_list_element *info_tracepoints_cmd
+    = add_info ("tracepoints", info_tracepoints_command, _("\
 Status of specified tracepoints (all tracepoints if no argument).\n\
 Convenience variable \"$tpnum\" contains the number of the\n\
 last tracepoint set."));
 
-  add_info_alias ("tp", "tracepoints", 1);
+  add_info_alias ("tp", info_tracepoints_cmd, 1);
 
   add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
 Delete specified tracepoints.\n\
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index dd6499621886..2c2d72e20906 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -986,10 +986,10 @@ add_info (const char *name, cmd_const_cfunc_ftype *fun, const char *doc)
 
 /* Add an alias to the list of info subcommands.  */
 
-struct cmd_list_element *
-add_info_alias (const char *name, const char *target_name, int abbrev_flag)
+cmd_list_element *
+add_info_alias (const char *name, cmd_list_element *target, int abbrev_flag)
 {
-  return add_alias_cmd (name, target_name, class_run, abbrev_flag, &infolist);
+  return add_alias_cmd (name, target, class_run, abbrev_flag, &infolist);
 }
 
 /* Add an element to the list of commands.  */
diff --git a/gdb/command.h b/gdb/command.h
index 638de1efde91..e14f27b5f9a7 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -373,8 +373,9 @@ extern struct cmd_list_element *add_info (const char *,
 					  cmd_const_cfunc_ftype *fun,
 					  const char *);
 
-extern struct cmd_list_element *add_info_alias (const char *, const char *,
-						int);
+extern cmd_list_element *add_info_alias (const char *name,
+					 cmd_list_element *target,
+					 int abbrev_flag);
 
 extern void complete_on_cmdlist (struct cmd_list_element *,
 				 completion_tracker &tracker,
diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c
index a707c89b8461..3b1fca3d20cc 100644
--- a/gdb/guile/guile.c
+++ b/gdb/guile/guile.c
@@ -790,10 +790,11 @@ This command is only a placeholder.")
 		       &show_guile_list, 0, &showlist);
   add_alias_cmd ("gu", "guile", class_obscure, 1, &showlist);
 
-  add_basic_prefix_cmd ("guile", class_obscure,
-			_("Prefix command for Guile info displays."),
-			&info_guile_list, 0, &infolist);
-  add_info_alias ("gu", "guile", 1);
+  cmd_list_element *info_guile_cmd
+    = add_basic_prefix_cmd ("guile", class_obscure,
+			    _("Prefix command for Guile info displays."),
+			    &info_guile_list, 0, &infolist);
+  add_info_alias ("gu", info_guile_cmd, 1);
 
   /* The name "print-stack" is carried over from Python.
      A better name is "print-exception".  */
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 5451b8be8fcb..11eee2983c9d 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -3276,13 +3276,14 @@ If non-stop mode is enabled, interrupt only the current thread,\n\
 otherwise all the threads in the program are stopped.  To \n\
 interrupt all running threads in non-stop mode, use the -a option."));
 
-  c = add_info ("registers", info_registers_command, _("\
+  cmd_list_element *info_registers_cmd
+    = add_info ("registers", info_registers_command, _("\
 List of integer registers and their contents, for selected stack frame.\n\
 One or more register names as argument means describe the given registers.\n\
 One or more register group names as argument means describe the registers\n\
 in the named register groups."));
-  add_info_alias ("r", "registers", 1);
-  set_cmd_completer (c, reg_or_group_completer);
+  add_info_alias ("r", info_registers_cmd, 1);
+  set_cmd_completer (info_registers_cmd, reg_or_group_completer);
 
   c = add_info ("all-registers", info_all_registers_command, _("\
 List of all registers and their contents, for selected stack frame.\n\
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 7fc56dc51f02..427c694bb760 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -9501,10 +9501,11 @@ _initialize_infrun ()
     = create_async_event_handler (infrun_async_inferior_event_handler, NULL,
 				  "infrun");
 
-  add_info ("signals", info_signals_command, _("\
+  cmd_list_element *info_signals_cmd
+    = add_info ("signals", info_signals_command, _("\
 What debugger does when program gets various signals.\n\
 Specify a signal as argument to print info on that signal only."));
-  add_info_alias ("handle", "signals", 0);
+  add_info_alias ("handle", info_signals_cmd, 0);
 
   c = add_com ("handle", class_run, handle_command, _("\
 Specify how to handle signals.\n\
diff --git a/gdb/solib.c b/gdb/solib.c
index f3cd48fde77c..5c8e6ca63662 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1565,9 +1565,10 @@ _initialize_solib ()
 
   add_com ("sharedlibrary", class_files, sharedlibrary_command,
 	   _("Load shared object library symbols for files matching REGEXP."));
-  add_info ("sharedlibrary", info_sharedlibrary_command,
-	    _("Status of loaded shared object libraries."));
-  add_info_alias ("dll", "sharedlibrary", 1);
+  cmd_list_element *info_sharedlibrary_cmd
+    = add_info ("sharedlibrary", info_sharedlibrary_command,
+		_("Status of loaded shared object libraries."));
+  add_info_alias ("dll", info_sharedlibrary_cmd, 1);
   add_com ("nosharedlibrary", class_files, no_shared_libraries,
 	   _("Unload all shared object library symbols."));
 
diff --git a/gdb/stack.c b/gdb/stack.c
index a3a6ba6c4196..66a461019932 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -3508,17 +3508,19 @@ With a negative COUNT, print outermost -COUNT frames."),
   add_com_alias ("bt", backtrace_cmd, class_stack, 0);
 
   add_com_alias ("where", backtrace_cmd, class_stack, 0);
-  add_info ("stack", backtrace_command,
-	    _("Backtrace of the stack, or innermost COUNT frames."));
-  add_info_alias ("s", "stack", 1);
-
-  add_prefix_cmd ("frame", class_info, &info_frame_cmd.base_command,
-		  _("All about the selected stack frame.\n\
+  cmd_list_element *info_stack_cmd
+    = add_info ("stack", backtrace_command,
+		_("Backtrace of the stack, or innermost COUNT frames."));
+  add_info_alias ("s", info_stack_cmd, 1);
+
+  cmd_list_element *info_frame_cmd_el
+    = add_prefix_cmd ("frame", class_info, &info_frame_cmd.base_command,
+		      _("All about the selected stack frame.\n\
 With no arguments, displays information about the currently selected stack\n\
 frame.  Alternatively a frame specification may be provided (See \"frame\")\n\
 the information is then printed about the specified frame."),
-		  &info_frame_cmd_list, 1, &infolist);
-  add_info_alias ("f", "frame", 1);
+		      &info_frame_cmd_list, 1, &infolist);
+  add_info_alias ("f", info_frame_cmd_el, 1);
 
   add_cmd ("address", class_stack, &info_frame_cmd.address,
 	   _("\
-- 
2.31.1


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

* [PATCH 6/8] gdb: remove add_alias_cmd overload that accepts a string
  2021-05-18 20:23 [PATCH 0/8] Change alias creation functions to accept target as cmd_list_element Simon Marchi
                   ` (4 preceding siblings ...)
  2021-05-18 20:23 ` [PATCH 5/8] gdb: make add_info_alias " Simon Marchi
@ 2021-05-18 20:23 ` Simon Marchi
  2021-05-18 20:23 ` [PATCH 7/8] gdb: add make-init-c script Simon Marchi
  2021-05-18 20:23 ` [PATCH 8/8] gdb: add option to reverse order of _initialize function calls Simon Marchi
  7 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2021-05-18 20:23 UTC (permalink / raw)
  To: gdb-patches

Same idea as previous patch, but for add_alias_cmd.  Remove the overload
that accepts the target command as a string (the target command name),
leaving only the one that takes the cmd_list_element.

gdb/ChangeLog:

	* command.h (add_alias_cmd): Accept target as
	cmd_list_element.  Update callers.

Change-Id: I546311f411e9e7da9302322d6ffad4e6c56df266
---
 gdb/arch-utils.c     | 16 +++++-----
 gdb/breakpoint.c     |  5 ++--
 gdb/cli/cli-cmds.c   |  3 +-
 gdb/cli/cli-decode.c | 12 --------
 gdb/command.h        |  4 ---
 gdb/corefile.c       |  2 +-
 gdb/cp-support.c     | 12 ++++----
 gdb/gnu-nat.c        | 54 ++++++++++++++++++++--------------
 gdb/guile/guile.c    | 20 +++++++------
 gdb/language.c       | 24 ++++++++-------
 gdb/macrocmd.c       | 15 ++++++----
 gdb/maint.c          | 10 ++++---
 gdb/mips-tdep.c      | 25 +++++++++-------
 gdb/printcmd.c       |  7 +++--
 gdb/record-btrace.c  | 30 ++++++++++---------
 gdb/record-full.c    | 69 ++++++++++++++++++++++++--------------------
 gdb/record.c         | 63 +++++++++++++++++++++++-----------------
 gdb/remote.c         | 19 +++++++-----
 gdb/solib.c          | 15 +++++-----
 gdb/sparc64-tdep.c   |  7 +++--
 gdb/symtab.c         | 11 +++----
 gdb/tracepoint.c     |  8 ++---
 gdb/valprint.c       | 24 ++++++++-------
 gdb/value.c          |  5 ++--
 gdb/windows-tdep.c   |  9 +++---
 25 files changed, 255 insertions(+), 214 deletions(-)

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 5bb9c7584493..c75a79757ea2 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -757,13 +757,15 @@ initialize_current_architecture (void)
     arches = XRESIZEVEC (const char *, arches, nr + 2);
     arches[nr + 0] = "auto";
     arches[nr + 1] = NULL;
-    add_setshow_enum_cmd ("architecture", class_support,
-			  arches, &set_architecture_string, 
-			  _("Set architecture of target."),
-			  _("Show architecture of target."), NULL,
-			  set_architecture, show_architecture,
-			  &setlist, &showlist);
-    add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
+    set_show_commands architecture_cmds
+      = add_setshow_enum_cmd ("architecture", class_support,
+			      arches, &set_architecture_string,
+			      _("Set architecture of target."),
+			      _("Show architecture of target."), NULL,
+			      set_architecture, show_architecture,
+			      &setlist, &showlist);
+    add_alias_cmd ("processor", architecture_cmds.set, class_support, 1,
+		   &setlist);
   }
 }
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index ae05d1802a8c..dc00b4c73592 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -16062,12 +16062,13 @@ last tracepoint set."));
 
   add_info_alias ("tp", info_tracepoints_cmd, 1);
 
-  add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
+  cmd_list_element *delete_tracepoints_cmd
+    = add_cmd ("tracepoints", class_trace, delete_trace_command, _("\
 Delete specified tracepoints.\n\
 Arguments are tracepoint numbers, separated by spaces.\n\
 No argument means delete all tracepoints."),
 	   &deletelist);
-  add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist);
+  add_alias_cmd ("tr", delete_tracepoints_cmd, class_trace, 1, &deletelist);
 
   c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\
 Disable specified tracepoints.\n\
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 8b2aa5aad5a9..56ae12a0c19d 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1908,8 +1908,7 @@ alias_command (const char *args, int from_tty)
 
       /* add_cmd requires *we* allocate space for name, hence the xstrdup.  */
       alias_cmd = add_alias_cmd (xstrdup (alias_argv[alias_argc - 1]),
-				 command_argv[command_argc - 1],
-				 class_alias, a_opts.abbrev_flag,
+				 target_cmd, class_alias, a_opts.abbrev_flag,
 				 c_command->subcommands);
     }
 
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 2c2d72e20906..009986c9cb10 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -333,18 +333,6 @@ add_alias_cmd (const char *name, cmd_list_element *target,
   return c;
 }
 
-struct cmd_list_element *
-add_alias_cmd (const char *name, const char *target_name,
-	       enum command_class theclass, int abbrev_flag,
-	       struct cmd_list_element **list)
-{
-  const char *tmp = target_name;
-  cmd_list_element *target = lookup_cmd (&tmp, *list, "", NULL, 1, 1);
-
-  return add_alias_cmd (name, target, theclass, abbrev_flag, list);
-}
-
-
 /* Update the prefix field of all sub-commands of the prefix command C.
    We must do this when a prefix command is defined as the GDB init sequence
    does not guarantee that a prefix command is created before its sub-commands.
diff --git a/gdb/command.h b/gdb/command.h
index e14f27b5f9a7..f8988e414943 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -174,10 +174,6 @@ extern struct cmd_list_element *add_cmd_suppress_notification
 			 struct cmd_list_element **list,
 			 int *suppress_notification);
 
-extern struct cmd_list_element *add_alias_cmd (const char *, const char *,
-					       enum command_class, int,
-					       struct cmd_list_element **);
-
 extern struct cmd_list_element *add_alias_cmd (const char *,
 					       cmd_list_element *,
 					       enum command_class, int,
diff --git a/gdb/corefile.c b/gdb/corefile.c
index ddaa77272a93..ff2494738b0d 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -478,7 +478,7 @@ Use `set gnutarget auto' to specify automatic detection."),
 				       &setlist, &showlist);
   set_cmd_completer (set_show_gnutarget.set, complete_set_gnutarget);
 
-  add_alias_cmd ("g", "gnutarget", class_files, 1, &setlist);
+  add_alias_cmd ("g", set_show_gnutarget.set, class_files, 1, &setlist);
 
   if (getenv ("GNUTARGET"))
     set_gnutarget (getenv ("GNUTARGET"));
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index e87c9d420e40..5bd8fd4e9408 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -2209,12 +2209,12 @@ void _initialize_cp_support ();
 void
 _initialize_cp_support ()
 {
-  add_basic_prefix_cmd ("cplus", class_maintenance,
-			_("C++ maintenance commands."),
-			&maint_cplus_cmd_list,
-			0, &maintenancelist);
-  add_alias_cmd ("cp", "cplus",
-		 class_maintenance, 1,
+  cmd_list_element *maintenance_cplus
+    = add_basic_prefix_cmd ("cplus", class_maintenance,
+			    _("C++ maintenance commands."),
+			    &maint_cplus_cmd_list,
+			    0, &maintenancelist);
+  add_alias_cmd ("cp", maintenance_cplus, class_maintenance, 1,
 		 &maintenancelist);
 
   add_cmd ("first_component",
diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index aadd3e894ce1..67ce00e9c302 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -3197,25 +3197,31 @@ Show whether new threads are allowed to run (once gdb has noticed them)."),
 	   _("Show the default detach-suspend-count value for new threads."),
 	   &show_thread_default_cmd_list);
 
-  add_cmd ("signals", class_run, set_signals_cmd, _("\
+  cmd_list_element *set_signals_cmd
+    = add_cmd ("signals", class_run, set_signals_cmd, _("\
 Set whether the inferior process's signals will be intercepted.\n\
 Mach exceptions (such as breakpoint traps) are not affected."),
-	   &setlist);
-  add_alias_cmd ("sigs", "signals", class_run, 1, &setlist);
-  add_cmd ("signals", no_class, show_signals_cmd, _("\
+	       &setlist);
+  add_alias_cmd ("sigs", set_signals_cmd, class_run, 1, &setlist);
+
+  cmd_list_element *show_signals_cmd
+    = add_cmd ("signals", no_class, show_signals_cmd, _("\
 Show whether the inferior process's signals will be intercepted."),
-	   &showlist);
-  add_alias_cmd ("sigs", "signals", no_class, 1, &showlist);
+	       &showlist);
+  add_alias_cmd ("sigs", show_signals_cmd, no_class, 1, &showlist);
 
-  add_cmd ("signal-thread", class_run, set_sig_thread_cmd, _("\
+  cmd_list_element *set_signal_thread_cmd
+    = add_cmd ("signal-thread", class_run, set_sig_thread_cmd, _("\
 Set the thread that gdb thinks is the libc signal thread.\n\
 This thread is run when delivering a signal to a non-stopped process."),
-	   &setlist);
-  add_alias_cmd ("sigthread", "signal-thread", class_run, 1, &setlist);
-  add_cmd ("signal-thread", no_class, show_sig_thread_cmd, _("\
+	       &setlist);
+  add_alias_cmd ("sigthread", set_signal_thread_cmd, class_run, 1, &setlist);
+
+  cmd_list_element *show_signal_thread_cmd
+    = add_cmd ("signal-thread", no_class, show_sig_thread_cmd, _("\
 Set the thread that gdb thinks is the libc signal thread."),
-	   &showlist);
-  add_alias_cmd ("sigthread", "signal-thread", no_class, 1, &showlist);
+	       &showlist);
+  add_alias_cmd ("sigthread", show_signal_thread_cmd, no_class, 1, &showlist);
 
   add_cmd ("stopped", class_run, set_stopped_cmd, _("\
 Set whether gdb thinks the inferior process is stopped as with SIGSTOP.\n\
@@ -3225,13 +3231,14 @@ Stopped process will be continued by sending them a signal."),
 Show whether gdb thinks the inferior process is stopped as with SIGSTOP."),
 	   &showlist);
 
-  add_cmd ("exceptions", class_run, set_exceptions_cmd, _("\
+  cmd_list_element *set_exceptions_cmd
+    = add_cmd ("exceptions", class_run, set_exceptions_cmd, _("\
 Set whether exceptions in the inferior process will be trapped.\n\
 When exceptions are turned off, neither breakpoints nor single-stepping\n\
-will work."),
-	   &setlist);
+will work."), &setlist);
   /* Allow `set exc' despite conflict with `set exception-port'.  */
-  add_alias_cmd ("exc", "exceptions", class_run, 1, &setlist);
+  add_alias_cmd ("exc", set_exceptions_cmd, class_run, 1, &setlist);
+
   add_cmd ("exceptions", no_class, show_exceptions_cmd, _("\
 Show whether exceptions in the inferior process will be trapped."),
 	   &showlist);
@@ -3262,12 +3269,14 @@ used to pause individual threads by default instead."),
 	     "on the thread when detaching."),
 	   &show_task_cmd_list);
 
-  add_cmd ("exception-port", no_class, set_task_exc_port_cmd, _("\
+  cmd_list_element *set_task_exception_port_cmd
+    = add_cmd ("exception-port", no_class, set_task_exc_port_cmd, _("\
 Set the task exception port to which we forward exceptions.\n\
 The argument should be the value of the send right in the task."),
-	   &set_task_cmd_list);
-  add_alias_cmd ("excp", "exception-port", no_class, 1, &set_task_cmd_list);
-  add_alias_cmd ("exc-port", "exception-port", no_class, 1,
+	       &set_task_cmd_list);
+  add_alias_cmd ("excp", set_task_exception_port_cmd, no_class, 1,
+		 &set_task_cmd_list);
+  add_alias_cmd ("exc-port", set_task_exception_port_cmd, no_class, 1,
 		 &set_task_cmd_list);
 
   /* A convenient way of turning on all options require to noninvasively
@@ -3458,8 +3467,9 @@ Set the thread exception port to which we forward exceptions.\n\
 This overrides the task exception port.\n\
 The argument should be the value of the send right in the task."),
 	   &set_thread_cmd_list);
-  add_alias_cmd ("excp", "exception-port", no_class, 1, &set_thread_cmd_list);
-  add_alias_cmd ("exc-port", "exception-port", no_class, 1,
+  add_alias_cmd ("excp", set_thread_exception_port_cmd, no_class, 1,
+		 &set_thread_cmd_list);
+  add_alias_cmd ("exc-port", set_thread_exception_port_cmd, no_class, 1,
 		 &set_thread_cmd_list);
 
   add_cmd ("takeover-suspend-count", no_class, thread_takeover_sc_cmd, _("\
diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c
index 3b1fca3d20cc..a28dee37ed87 100644
--- a/gdb/guile/guile.c
+++ b/gdb/guile/guile.c
@@ -780,15 +780,17 @@ This command is only a placeholder.")
 	   );
   add_com_alias ("gu", guile_cmd_element, class_obscure, 1);
 
-  add_basic_prefix_cmd ("guile", class_obscure,
-			_("Prefix command for Guile preference settings."),
-			&set_guile_list, 0, &setlist);
-  add_alias_cmd ("gu", "guile", class_obscure, 1, &setlist);
-
-  add_show_prefix_cmd ("guile", class_obscure,
-		       _("Prefix command for Guile preference settings."),
-		       &show_guile_list, 0, &showlist);
-  add_alias_cmd ("gu", "guile", class_obscure, 1, &showlist);
+  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);
 
   cmd_list_element *info_guile_cmd
     = add_basic_prefix_cmd ("guile", class_obscure,
diff --git a/gdb/language.c b/gdb/language.c
index a3f96ecd6ff7..0d1e3848de85 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -1164,17 +1164,19 @@ _initialize_language ()
 
   /* GDB commands for language specific stuff.  */
 
-  add_basic_prefix_cmd ("check", no_class,
-			_("Set the status of the type/range checker."),
-			&setchecklist, 0, &setlist);
-  add_alias_cmd ("c", "check", no_class, 1, &setlist);
-  add_alias_cmd ("ch", "check", no_class, 1, &setlist);
-
-  add_show_prefix_cmd ("check", no_class,
-		       _("Show the status of the type/range checker."),
-		       &showchecklist, 0, &showlist);
-  add_alias_cmd ("c", "check", no_class, 1, &showlist);
-  add_alias_cmd ("ch", "check", no_class, 1, &showlist);
+  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);
 
   add_setshow_enum_cmd ("range", class_support, type_or_range_names,
 			&range,
diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c
index 4e4a68d5c1d5..28a57f7bac95 100644
--- a/gdb/macrocmd.c
+++ b/gdb/macrocmd.c
@@ -457,12 +457,15 @@ _initialize_macrocmd ()
 			_("Prefix for commands dealing with C preprocessor macros."),
 			&macrolist, 0, &cmdlist);
 
-  add_cmd ("expand", no_class, macro_expand_command, _("\
+  cmd_list_element *macro_expand_cmd
+    = add_cmd ("expand", no_class, macro_expand_command, _("\
 Fully expand any C/C++ preprocessor macro invocations in EXPRESSION.\n\
 Show the expanded expression."),
-	   &macrolist);
-  add_alias_cmd ("exp", "expand", no_class, 1, &macrolist);
-  add_cmd ("expand-once", no_class, macro_expand_once_command, _("\
+	       &macrolist);
+  add_alias_cmd ("exp", macro_expand_cmd, no_class, 1, &macrolist);
+
+  cmd_list_element *macro_expand_once_cmd
+    = add_cmd ("expand-once", no_class, macro_expand_once_command, _("\
 Expand C/C++ preprocessor macro invocations appearing directly in EXPRESSION.\n\
 Show the expanded expression.\n\
 \n\
@@ -473,8 +476,8 @@ introduces further macro invocations, those are left unexpanded.\n\
 `macro expand-once' helps you see how a particular macro expands,\n\
 whereas `macro expand' shows you how all the macros involved in an\n\
 expression work together to yield a pre-processed expression."),
-	   &macrolist);
-  add_alias_cmd ("exp1", "expand-once", no_class, 1, &macrolist);
+	       &macrolist);
+  add_alias_cmd ("exp1", macro_expand_once_cmd, no_class, 1, &macrolist);
 
   add_info ("macro", info_macro_command,
 	    _("Show the definition of MACRO, and it's source location.\n\
diff --git a/gdb/maint.c b/gdb/maint.c
index 91a7f77d0eb0..26bacbfeb768 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -1143,11 +1143,13 @@ a human readable form, to cause GDB to deliberately dump core, etc."),
 
   add_com_alias ("mt", maintenance_cmd, class_maintenance, 1);
 
-  add_basic_prefix_cmd ("info", class_maintenance, _("\
+  cmd_list_element *maintenance_info_cmd
+    = add_basic_prefix_cmd ("info", class_maintenance, _("\
 Commands for showing internal info about the program being debugged."),
-			&maintenanceinfolist, 0,
-			&maintenancelist);
-  add_alias_cmd ("i", "info", class_maintenance, 1, &maintenancelist);
+			    &maintenanceinfolist, 0,
+			    &maintenancelist);
+  add_alias_cmd ("i", maintenance_info_cmd, class_maintenance, 1,
+		 &maintenancelist);
 
   const auto opts = make_maint_info_sections_options_def_group (nullptr);
   static std::string maint_info_sections_command_help
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 2fe83324738f..31cac9384e9e 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -8994,17 +8994,20 @@ and is updated automatically from ELF file flags if available."),
   add_cmd ("single", class_support, set_mipsfpu_single_command,
 	   _("Select single-precision MIPS floating-point coprocessor."),
 	   &mipsfpulist);
-  add_cmd ("double", class_support, set_mipsfpu_double_command,
-	   _("Select double-precision MIPS floating-point coprocessor."),
-	   &mipsfpulist);
-  add_alias_cmd ("on", "double", class_support, 1, &mipsfpulist);
-  add_alias_cmd ("yes", "double", class_support, 1, &mipsfpulist);
-  add_alias_cmd ("1", "double", class_support, 1, &mipsfpulist);
-  add_cmd ("none", class_support, set_mipsfpu_none_command,
-	   _("Select no MIPS floating-point coprocessor."), &mipsfpulist);
-  add_alias_cmd ("off", "none", class_support, 1, &mipsfpulist);
-  add_alias_cmd ("no", "none", class_support, 1, &mipsfpulist);
-  add_alias_cmd ("0", "none", class_support, 1, &mipsfpulist);
+  cmd_list_element *set_mipsfpu_double_cmd
+    = add_cmd ("double", class_support, set_mipsfpu_double_command,
+	       _("Select double-precision MIPS floating-point coprocessor."),
+	       &mipsfpulist);
+  add_alias_cmd ("on", set_mipsfpu_double_cmd, class_support, 1, &mipsfpulist);
+  add_alias_cmd ("yes", set_mipsfpu_double_cmd, class_support, 1, &mipsfpulist);
+  add_alias_cmd ("1", set_mipsfpu_double_cmd, class_support, 1, &mipsfpulist);
+
+  cmd_list_element *set_mipsfpu_none_cmd
+    = add_cmd ("none", class_support, set_mipsfpu_none_command,
+	       _("Select no MIPS floating-point coprocessor."), &mipsfpulist);
+  add_alias_cmd ("off", set_mipsfpu_none_cmd, class_support, 1, &mipsfpulist);
+  add_alias_cmd ("no", set_mipsfpu_none_cmd, class_support, 1, &mipsfpulist);
+  add_alias_cmd ("0", set_mipsfpu_none_cmd, class_support, 1, &mipsfpulist);
   add_cmd ("auto", class_support, set_mipsfpu_auto_command,
 	   _("Select MIPS floating-point coprocessor automatically."),
 	   &mipsfpulist);
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 8daa87cf978f..7eba2993fb2e 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -3304,7 +3304,8 @@ current working language.  The result is printed and saved in the value\n\
 history, if it is not void."));
   set_cmd_completer_handle_brkchars (c, print_command_completer);
 
-  add_cmd ("variable", class_vars, set_command, _("\
+  cmd_list_element *set_variable_cmd
+    = add_cmd ("variable", class_vars, set_command, _("\
 Evaluate expression EXP and assign result to variable VAR.\n\
 Usage: set variable VAR = EXP\n\
 This uses assignment syntax appropriate for the current language\n\
@@ -3313,8 +3314,8 @@ VAR may be a debugger \"convenience\" variable (names starting\n\
 with $), a register (a few standard names starting with $), or an actual\n\
 variable in the program being debugged.  EXP is any valid expression.\n\
 This may usually be abbreviated to simply \"set\"."),
-	   &setlist);
-  add_alias_cmd ("var", "variable", class_vars, 0, &setlist);
+	       &setlist);
+  add_alias_cmd ("var", set_variable_cmd, class_vars, 0, &setlist);
 
   const auto print_opts = make_value_print_options_def_group (nullptr);
 
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index c04e1cde7218..00affb85d22e 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -3109,25 +3109,29 @@ void _initialize_record_btrace ();
 void
 _initialize_record_btrace ()
 {
-  add_prefix_cmd ("btrace", class_obscure, cmd_record_btrace_start,
-		  _("Start branch trace recording."), &record_btrace_cmdlist,
-		  0, &record_cmdlist);
-  add_alias_cmd ("b", "btrace", class_obscure, 1, &record_cmdlist);
-
-  add_cmd ("bts", class_obscure, cmd_record_btrace_bts_start,
-	   _("\
+  cmd_list_element *record_btrace_cmd
+    = add_prefix_cmd ("btrace", class_obscure, cmd_record_btrace_start,
+		      _("Start branch trace recording."),
+		      &record_btrace_cmdlist, 0, &record_cmdlist);
+  add_alias_cmd ("b", record_btrace_cmd, class_obscure, 1, &record_cmdlist);
+
+  cmd_list_element *record_btrace_bts_cmd
+    = add_cmd ("bts", class_obscure, cmd_record_btrace_bts_start,
+	       _("\
 Start branch trace recording in Branch Trace Store (BTS) format.\n\n\
 The processor stores a from/to record for each branch into a cyclic buffer.\n\
 This format may not be available on all processors."),
-	   &record_btrace_cmdlist);
-  add_alias_cmd ("bts", "btrace bts", class_obscure, 1, &record_cmdlist);
+	     &record_btrace_cmdlist);
+  add_alias_cmd ("bts", record_btrace_bts_cmd, class_obscure, 1,
+		 &record_cmdlist);
 
-  add_cmd ("pt", class_obscure, cmd_record_btrace_pt_start,
-	   _("\
+  cmd_list_element *record_btrace_pt_cmd
+    = add_cmd ("pt", class_obscure, cmd_record_btrace_pt_start,
+	       _("\
 Start branch trace recording in Intel Processor Trace format.\n\n\
 This format may not be available on all processors."),
-	   &record_btrace_cmdlist);
-  add_alias_cmd ("pt", "btrace pt", class_obscure, 1, &record_cmdlist);
+	     &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,
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 91da1076194f..03e39eeaf3a2 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2796,14 +2796,15 @@ _initialize_record_full ()
 		  _("Start full execution recording."), &record_full_cmdlist,
 		  0, &record_cmdlist);
 
-  c = add_cmd ("restore", class_obscure, cmd_record_full_restore,
+  cmd_list_element *record_full_restore_cmd
+    = add_cmd ("restore", class_obscure, cmd_record_full_restore,
 	       _("Restore the execution log from a file.\n\
 Argument is filename.  File must be created with 'record save'."),
 	       &record_full_cmdlist);
-  set_cmd_completer (c, filename_completer);
+  set_cmd_completer (record_full_restore_cmd, filename_completer);
 
   /* Deprecate the old version without "full" prefix.  */
-  c = add_alias_cmd ("restore", "full restore", class_obscure, 1,
+  c = add_alias_cmd ("restore", record_full_restore_cmd, class_obscure, 1,
 		     &record_cmdlist);
   set_cmd_completer (c, filename_completer);
   deprecate_cmd (c, "record full restore");
@@ -2817,61 +2818,67 @@ Argument is filename.  File must be created with 'record save'."),
 		       0, &show_record_cmdlist);
 
   /* Record instructions number limit command.  */
-  add_setshow_boolean_cmd ("stop-at-limit", no_class,
-			   &record_full_stop_at_limit, _("\
+  set_show_commands set_record_full_stop_at_limit_cmds
+    = add_setshow_boolean_cmd ("stop-at-limit", no_class,
+			       &record_full_stop_at_limit, _("\
 Set whether record/replay stops when record/replay buffer becomes full."), _("\
 Show whether record/replay stops when record/replay buffer becomes full."),
 			   _("Default is ON.\n\
 When ON, if the record/replay buffer becomes full, ask user what to do.\n\
 When OFF, if the record/replay buffer becomes full,\n\
 delete the oldest recorded instruction to make room for each new one."),
-			   NULL, NULL,
-			   &set_record_full_cmdlist, &show_record_full_cmdlist);
+			       NULL, NULL,
+			       &set_record_full_cmdlist,
+			       &show_record_full_cmdlist);
 
-  c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
+  c = add_alias_cmd ("stop-at-limit",
+		     set_record_full_stop_at_limit_cmds.set, no_class, 1,
 		     &set_record_cmdlist);
   deprecate_cmd (c, "set record full stop-at-limit");
 
-  c = add_alias_cmd ("stop-at-limit", "full stop-at-limit", no_class, 1,
+  c = add_alias_cmd ("stop-at-limit",
+		     set_record_full_stop_at_limit_cmds.show, no_class, 1,
 		     &show_record_cmdlist);
   deprecate_cmd (c, "show record full stop-at-limit");
 
-  add_setshow_uinteger_cmd ("insn-number-max", no_class,
-			    &record_full_insn_max_num,
-			    _("Set record/replay buffer limit."),
-			    _("Show record/replay buffer limit."), _("\
+  set_show_commands record_full_insn_number_max_cmds
+    = add_setshow_uinteger_cmd ("insn-number-max", no_class,
+				&record_full_insn_max_num,
+				_("Set record/replay buffer limit."),
+				_("Show record/replay buffer limit."), _("\
 Set the maximum number of instructions to be stored in the\n\
 record/replay buffer.  A value of either \"unlimited\" or zero means no\n\
 limit.  Default is 200000."),
-			    set_record_full_insn_max_num,
-			    NULL, &set_record_full_cmdlist,
-			    &show_record_full_cmdlist);
+				set_record_full_insn_max_num,
+				NULL, &set_record_full_cmdlist,
+				&show_record_full_cmdlist);
 
-  c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
-		     &set_record_cmdlist);
+  c = add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds.set,
+		     no_class, 1, &set_record_cmdlist);
   deprecate_cmd (c, "set record full insn-number-max");
 
-  c = add_alias_cmd ("insn-number-max", "full insn-number-max", no_class, 1,
-		     &show_record_cmdlist);
+  c = add_alias_cmd ("insn-number-max", record_full_insn_number_max_cmds.show,
+		     no_class, 1, &show_record_cmdlist);
   deprecate_cmd (c, "show record full insn-number-max");
 
-  add_setshow_boolean_cmd ("memory-query", no_class,
-			   &record_full_memory_query, _("\
+  set_show_commands record_full_memory_query_cmds
+    = add_setshow_boolean_cmd ("memory-query", no_class,
+			       &record_full_memory_query, _("\
 Set whether query if PREC cannot record memory change of next instruction."),
-			   _("\
+			       _("\
 Show whether query if PREC cannot record memory change of next instruction."),
-			   _("\
+			       _("\
 Default is OFF.\n\
 When ON, query if PREC cannot record memory change of next instruction."),
-			   NULL, NULL,
-			   &set_record_full_cmdlist,
-			   &show_record_full_cmdlist);
+			       NULL, NULL,
+			       &set_record_full_cmdlist,
+			       &show_record_full_cmdlist);
 
-  c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
-		     &set_record_cmdlist);
+  c = add_alias_cmd ("memory-query", record_full_memory_query_cmds.set,
+		     no_class, 1, &set_record_cmdlist);
   deprecate_cmd (c, "set record full memory-query");
 
-  c = add_alias_cmd ("memory-query", "full memory-query", no_class, 1,
-		     &show_record_cmdlist);
+  c = add_alias_cmd ("memory-query", record_full_memory_query_cmds.show,
+		     no_class, 1,&show_record_cmdlist);
   deprecate_cmd (c, "show record full memory-query");
 }
diff --git a/gdb/record.c b/gdb/record.c
index a09137b34feb..6968c30d930d 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -792,18 +792,24 @@ A size of \"unlimited\" means unlimited lines.  The default is 10."),
   set_cmd_completer (record_cmd, filename_completer);
 
   add_com_alias ("rec", record_cmd, class_obscure, 1);
-  add_basic_prefix_cmd ("record", class_support,
-			_("Set record options."), &set_record_cmdlist,
-			0, &setlist);
-  add_alias_cmd ("rec", "record", class_obscure, 1, &setlist);
-  add_show_prefix_cmd ("record", class_support,
-		       _("Show record options."), &show_record_cmdlist,
-		       0, &showlist);
-  add_alias_cmd ("rec", "record", class_obscure, 1, &showlist);
-  add_prefix_cmd ("record", class_support, info_record_command,
-		  _("Info record options."), &info_record_cmdlist,
-		  0, &infolist);
-  add_alias_cmd ("rec", "record", class_obscure, 1, &infolist);
+
+  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);
+
+  cmd_list_element *info_record_cmd
+    = add_prefix_cmd ("record", class_support, info_record_command,
+		      _("Info record options."), &info_record_cmdlist,
+		      0, &infolist);
+  add_alias_cmd ("rec", info_record_cmd, class_obscure, 1, &infolist);
 
   c = add_cmd ("save", class_obscure, cmd_record_save,
 	       _("Save the execution log to a file.\n\
@@ -812,26 +818,31 @@ Default filename is 'gdb_record.PROCESS_ID'."),
 	       &record_cmdlist);
   set_cmd_completer (c, filename_completer);
 
-  add_cmd ("delete", class_obscure, cmd_record_delete,
-	   _("Delete the rest of execution log and start recording it anew."),
-	   &record_cmdlist);
-  add_alias_cmd ("d", "delete", class_obscure, 1, &record_cmdlist);
-  add_alias_cmd ("del", "delete", class_obscure, 1, &record_cmdlist);
-
-  add_cmd ("stop", class_obscure, cmd_record_stop,
-	   _("Stop the record/replay target."),
-	   &record_cmdlist);
-  add_alias_cmd ("s", "stop", class_obscure, 1, &record_cmdlist);
+  cmd_list_element *record_delete_cmd
+    =  add_cmd ("delete", class_obscure, cmd_record_delete,
+		_("Delete the rest of execution log and start recording it \
+anew."),
+	    &record_cmdlist);
+  add_alias_cmd ("d", record_delete_cmd, class_obscure, 1, &record_cmdlist);
+  add_alias_cmd ("del", record_delete_cmd, class_obscure, 1, &record_cmdlist);
+
+  cmd_list_element *record_stop_cmd
+    = add_cmd ("stop", class_obscure, cmd_record_stop,
+	       _("Stop the record/replay target."),
+	       &record_cmdlist);
+  add_alias_cmd ("s", record_stop_cmd, class_obscure, 1, &record_cmdlist);
 
   add_prefix_cmd ("goto", class_obscure, cmd_record_goto, _("\
 Restore the program to its state at instruction number N.\n\
 Argument is instruction number, as shown by 'info record'."),
 		  &record_goto_cmdlist, 1, &record_cmdlist);
 
-  add_cmd ("begin", class_obscure, cmd_record_goto_begin,
-	   _("Go to the beginning of the execution log."),
-	   &record_goto_cmdlist);
-  add_alias_cmd ("start", "begin", class_obscure, 1, &record_goto_cmdlist);
+  cmd_list_element *record_goto_begin_cmd
+    = add_cmd ("begin", class_obscure, cmd_record_goto_begin,
+	       _("Go to the beginning of the execution log."),
+	       &record_goto_cmdlist);
+  add_alias_cmd ("start", record_goto_begin_cmd, class_obscure, 1,
+		 &record_goto_cmdlist);
 
   add_cmd ("end", class_obscure, cmd_record_goto_end,
 	   _("Go to the end of the execution log."),
diff --git a/gdb/remote.c b/gdb/remote.c
index f2cb35116c89..8379f514738a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1928,24 +1928,27 @@ add_packet_config_cmd (struct packet_config *config, const char *name,
 			 name, title);
   /* set/show TITLE-packet {auto,on,off} */
   cmd_name = xstrprintf ("%s-packet", title);
-  add_setshow_auto_boolean_cmd (cmd_name, class_obscure,
-				&config->detect, set_doc,
-				show_doc, NULL, /* help_doc */
-				NULL,
-				show_remote_protocol_packet_cmd,
-				&remote_set_cmdlist, &remote_show_cmdlist);
+  set_show_commands cmds
+    = add_setshow_auto_boolean_cmd (cmd_name, class_obscure,
+				    &config->detect, set_doc,
+				    show_doc, NULL, /* help_doc */
+				    NULL,
+				    show_remote_protocol_packet_cmd,
+				    &remote_set_cmdlist, &remote_show_cmdlist);
+
   /* The command code copies the documentation strings.  */
   xfree (set_doc);
   xfree (show_doc);
+
   /* set/show remote NAME-packet {auto,on,off} -- legacy.  */
   if (legacy)
     {
       char *legacy_name;
 
       legacy_name = xstrprintf ("%s-packet", name);
-      add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
+      add_alias_cmd (legacy_name, cmds.set, class_obscure, 0,
 		     &remote_set_cmdlist);
-      add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
+      add_alias_cmd (legacy_name, cmds.show, class_obscure, 0,
 		     &remote_show_cmdlist);
     }
 }
diff --git a/gdb/solib.c b/gdb/solib.c
index 5c8e6ca63662..2df521181438 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1585,20 +1585,21 @@ inferior.  Otherwise, symbols must be loaded manually, using \
 			   show_auto_solib_add,
 			   &setlist, &showlist);
 
-  add_setshow_optional_filename_cmd ("sysroot", class_support,
-				     &gdb_sysroot, _("\
+  set_show_commands sysroot_cmds
+    = add_setshow_optional_filename_cmd ("sysroot", class_support,
+					 &gdb_sysroot, _("\
 Set an alternate system root."), _("\
 Show the current system root."), _("\
 The system root is used to load absolute shared library symbol files.\n\
 For other (relative) files, you can add directories using\n\
 `set solib-search-path'."),
-				     gdb_sysroot_changed,
-				     NULL,
-				     &setlist, &showlist);
+					 gdb_sysroot_changed,
+					 NULL,
+					 &setlist, &showlist);
 
-  add_alias_cmd ("solib-absolute-prefix", "sysroot", class_support, 0,
+  add_alias_cmd ("solib-absolute-prefix", sysroot_cmds.set, class_support, 0,
 		 &setlist);
-  add_alias_cmd ("solib-absolute-prefix", "sysroot", class_support, 0,
+  add_alias_cmd ("solib-absolute-prefix", sysroot_cmds.show, class_support, 0,
 		 &showlist);
 
   add_setshow_optional_filename_cmd ("solib-search-path", class_support,
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index 3f9600f38793..4157594d1533 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -535,9 +535,10 @@ _initialize_sparc64_adi_tdep ()
   add_basic_prefix_cmd ("adi", class_support,
 			_("ADI version related commands."),
 			&sparc64adilist, 0, &cmdlist);
-  add_cmd ("examine", class_support, adi_examine_command,
-	   _("Examine ADI versions."), &sparc64adilist);
-  add_alias_cmd ("x", "examine", no_class, 1, &sparc64adilist);
+  cmd_list_element *adi_examine_cmd
+    = add_cmd ("examine", class_support, adi_examine_command,
+	       _("Examine ADI versions."), &sparc64adilist);
+  add_alias_cmd ("x", adi_examine_cmd, no_class, 1, &sparc64adilist);
   add_cmd ("assign", class_support, adi_assign_command,
 	   _("Assign ADI versions."), &sparc64adilist);
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 9555f94707de..655b3dabf62d 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -6897,11 +6897,12 @@ If zero then the symbol cache is disabled."),
 	   _("Print symbol cache statistics for each program space."),
 	   &maintenanceprintlist);
 
-  add_cmd ("symbol-cache", class_maintenance,
-	   maintenance_flush_symbol_cache,
-	   _("Flush the symbol cache for each program space."),
-	   &maintenanceflushlist);
-  c = add_alias_cmd ("flush-symbol-cache", "flush symbol-cache",
+  cmd_list_element *maintenance_flush_symbol_cache_cmd
+    = add_cmd ("symbol-cache", class_maintenance,
+	       maintenance_flush_symbol_cache,
+	       _("Flush the symbol cache for each program space."),
+	       &maintenanceflushlist);
+  c = add_alias_cmd ("flush-symbol-cache", maintenance_flush_symbol_cache_cmd,
 		     class_maintenance, 0, &maintenancelist);
   deprecate_cmd (c, "maintenancelist flush symbol-cache");
 
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index e7e0d7be70bd..e53c8b7dfcbb 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -4075,11 +4075,11 @@ Select a trace frame by PC.\n\
 Default is the current PC, or the PC of the current trace frame."),
 	   &tfindlist);
 
-  add_cmd ("end", class_trace, tfind_end_command, _("\
-De-select any trace frame and resume 'live' debugging."),
-	   &tfindlist);
+  cmd_list_element *tfind_end_cmd
+    = add_cmd ("end", class_trace, tfind_end_command, _("\
+De-select any trace frame and resume 'live' debugging."), &tfindlist);
 
-  add_alias_cmd ("none", "end", class_trace, 0, &tfindlist);
+  add_alias_cmd ("none", tfind_end_cmd, class_trace, 0, &tfindlist);
 
   add_cmd ("start", class_trace, tfind_start_command,
 	   _("Select the first trace frame in the trace buffer."),
diff --git a/gdb/valprint.c b/gdb/valprint.c
index e191c357fcae..fa2b64ef10ac 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -3143,18 +3143,20 @@ _initialize_valprint ()
 {
   cmd_list_element *cmd;
 
-  add_basic_prefix_cmd ("print", no_class,
-			_("Generic command for setting how things print."),
-			&setprintlist, 0, &setlist);
-  add_alias_cmd ("p", "print", no_class, 1, &setlist);
+  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);
   /* Prefer set print to set prompt.  */
-  add_alias_cmd ("pr", "print", no_class, 1, &setlist);
-
-  add_show_prefix_cmd ("print", no_class,
-		       _("Generic command for showing print settings."),
-		       &showprintlist, 0, &showlist);
-  add_alias_cmd ("p", "print", no_class, 1, &showlist);
-  add_alias_cmd ("pr", "print", no_class, 1, &showlist);
+  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,
 			      _("\
diff --git a/gdb/value.c b/gdb/value.c
index 9822cec209b2..9df035a50b3b 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -4231,7 +4231,8 @@ void _initialize_values ();
 void
 _initialize_values ()
 {
-  add_cmd ("convenience", no_class, show_convenience, _("\
+  cmd_list_element *show_convenience_cmd
+    = add_cmd ("convenience", no_class, show_convenience, _("\
 Debugger convenience (\"$foo\") variables and functions.\n\
 Convenience variables are created when you assign them values;\n\
 thus, \"set $foo=1\" gives \"$foo\" the value 1.  Values may be any type.\n\
@@ -4244,7 +4245,7 @@ A few convenience variables are given values automatically:\n\
 Convenience functions are defined via the Python API."
 #endif
 	   ), &showlist);
-  add_alias_cmd ("conv", "convenience", no_class, 1, &showlist);
+  add_alias_cmd ("conv", show_convenience_cmd, no_class, 1, &showlist);
 
   add_cmd ("values", no_set_class, show_values, _("\
 Elements of value history around item number IDX (or last ten)."),
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index e6644843a951..88601e106f57 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -1212,10 +1212,11 @@ _initialize_windows_tdep ()
     = gdbarch_data_register_post_init (init_windows_gdbarch_data);
 
   init_w32_command_list ();
-  add_cmd ("thread-information-block", class_info, display_tib,
-	   _("Display thread information block."),
-	   &info_w32_cmdlist);
-  add_alias_cmd ("tib", "thread-information-block", class_info, 1,
+  cmd_list_element *info_w32_thread_information_block_cmd
+    = add_cmd ("thread-information-block", class_info, display_tib,
+	       _("Display thread information block."),
+	       &info_w32_cmdlist);
+  add_alias_cmd ("tib", info_w32_thread_information_block_cmd, class_info, 1,
 		 &info_w32_cmdlist);
 
   add_setshow_boolean_cmd ("show-all-tib", class_maintenance,
-- 
2.31.1


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

* [PATCH 7/8] gdb: add make-init-c script
  2021-05-18 20:23 [PATCH 0/8] Change alias creation functions to accept target as cmd_list_element Simon Marchi
                   ` (5 preceding siblings ...)
  2021-05-18 20:23 ` [PATCH 6/8] gdb: remove add_alias_cmd overload that accepts a string Simon Marchi
@ 2021-05-18 20:23 ` Simon Marchi
  2021-05-19 15:52   ` Simon Marchi
  2021-05-18 20:23 ` [PATCH 8/8] gdb: add option to reverse order of _initialize function calls Simon Marchi
  7 siblings, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2021-05-18 20:23 UTC (permalink / raw)
  To: gdb-patches

I would like to modify how the init.c file is generated (its content).
But as it is, a bash script with multiple sed invocations in a Makefile
target, it's not very maintainable.  Replace that with a bash script
that does the same, but in a more readable way.

The Makefile rule uses the "-" prefix in front of the for loop, I
presume to ignore any error coming from the fact that xml-builtin.c and
cp-name-parser.c are not found in the srcdir (they are generated source
files).  I prefer not to blindly ignore errors, so filter these files
out of INIT_FILES instead (we already filter out other files).

There are no expected meaningful changes to the generated init.c file.
Just the _initialize_all_file declaration that is moved down and "void"
in parenthesis that is removed.

The new regular expression is a bit tighter than the existing one, it
requires the init function to be followed by exactly ` ()`.  Update
bpf-tdep.c accordingly.

I removed the use of stamp-init because... I am not sure if it's still
required.  I can't remember why it's needed in the first place.  If it
is still needed, please remind me why and I'll add it back.

gdb/ChangeLog:

	* Makefile.in (INIT_FILES_FILTER_OUT): New.
	(INIT_FILES): Use INIT_FILES_FILTER_OUT.
	(init.c): Use make-init-c.
	(stamp-init): Remove.
	(clean mostlyclean): Remove stamp-init.
	* bpf-tdep.c (_initialize_bpf_tdep): Remove "void".
	* silent-rules.mk (ECHO_INIT_C): Change.
	* make-init-c: New file.

Change-Id: I6d6b12cbccf24ab79d1219bff05df01624c684f9
---
 gdb/Makefile.in     | 51 +++++++++++++++++++++------------------------
 gdb/bpf-tdep.c      |  2 +-
 gdb/make-init-c     | 49 +++++++++++++++++++++++++++++++++++++++++++
 gdb/silent-rules.mk |  2 +-
 4 files changed, 75 insertions(+), 29 deletions(-)
 create mode 100755 gdb/make-init-c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index a9fade803b0d..3b166773f9af 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1837,8 +1837,15 @@ test-cp-name-parser$(EXEEXT): test-cp-name-parser.o $(LIBIBERTY)
 # maybe we could just require every .o file to have an initialization routine
 # of a given name (top.o -> _initialize_top, etc.).
 #
-# Formatting conventions:  The name of the _initialize_* routines must start
-# in column zero, and must not be inside #if.
+# Formatting conventions:  The name of the initialization routines must begin
+# with `_initialize_`, must start in column zero, and be followed with exactly
+# ` ()`.  For example:
+#
+# void
+# _initialize_foo ()
+# {
+#   ...
+# }
 #
 # Note that the set of files with init functions might change, or the names
 # of the functions might change, so this files needs to depend on all the
@@ -1846,33 +1853,23 @@ test-cp-name-parser$(EXEEXT): test-cp-name-parser.o $(LIBIBERTY)
 # this Makefile has generally been written, we do this indirectly, by
 # computing the list of source files from the list of object files.
 
+INIT_FILES_FILTER_OUT = \
+	cp-name-parser.o \
+	init.o \
+	version.o \
+	xml-builtin.o \
+	%_S.o \
+	%_U.o
+
 INIT_FILES = \
 	$(patsubst %.o,%.c, \
 	  $(patsubst %-exp.o,%-exp.y, \
-	    $(filter-out init.o version.o %_S.o %_U.o,\
-	      $(COMMON_OBS))))
-
-init.c: stamp-init; @true
-stamp-init: $(INIT_FILES) config.status
-	@$(ECHO_INIT_C) echo "Making init.c"
-	@rm -f init.c-tmp init.l-tmp
-	@touch init.c-tmp
-	@-for f in $(INIT_FILES); do \
-	    sed -n -e 's/^_initialize_\([a-z_0-9A-Z]*\).*/\1/p' \
-	        $(srcdir)/$$f 2>/dev/null; \
-	done > init.l-tmp
-	@echo '/* Do not modify this file.  */' >>init.c-tmp
-	@echo '/* It is created automatically by the Makefile.  */'>>init.c-tmp
-	@echo '#include "defs.h"      /* For initialize_file_ftype.  */' >>init.c-tmp
-	@echo 'extern void initialize_all_files(void);' >>init.c-tmp
-	@sed -e 's/\(.*\)/extern initialize_file_ftype _initialize_\1;/' <init.l-tmp >>init.c-tmp
-	@echo 'void' >>init.c-tmp
-	@echo 'initialize_all_files (void)' >>init.c-tmp
-	@echo '{' >>init.c-tmp
-	@sed -e 's/\(.*\)/  _initialize_\1 ();/' <init.l-tmp >>init.c-tmp
-	@echo '}' >>init.c-tmp
-	@$(SHELL) $(srcdir)/../move-if-change init.c-tmp init.c
-	@echo stamp > stamp-init
+	    $(filter-out $(INIT_FILES_FILTER_OUT), $(COMMON_OBS))))
+
+init.c: $(INIT_FILES) config.status $(srcdir)/make-init-c
+	$(ECHO_INIT_C)
+	$(SILENCE) $(srcdir)/make-init-c $(addprefix $(srcdir)/,$(INIT_FILES)) > init.c-tmp
+	$(SILENCE) $(SHELL) $(srcdir)/../move-if-change init.c-tmp init.c
 
 .PRECIOUS: init.c
 
@@ -1933,7 +1930,7 @@ tags: TAGS
 clean mostlyclean: $(CONFIG_CLEAN)
 	@$(MAKE) $(FLAGS_TO_PASS) DO=clean "DODIRS=$(CLEANDIRS)" subdir_do
 	rm -f *.o *.a *~ init.c-tmp init.l-tmp version.c-tmp
-	rm -f init.c stamp-init version.c stamp-version
+	rm -f init.c version.c stamp-version
 	rm -f gdb$(EXEEXT) core make.log
 	rm -f gdb[0-9]$(EXEEXT)
 	rm -f test-cp-name-parser$(EXEEXT)
diff --git a/gdb/bpf-tdep.c b/gdb/bpf-tdep.c
index 352a22198e96..a29cd90ba387 100644
--- a/gdb/bpf-tdep.c
+++ b/gdb/bpf-tdep.c
@@ -370,7 +370,7 @@ bpf_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
 void _initialize_bpf_tdep ();
 void
-_initialize_bpf_tdep (void)
+_initialize_bpf_tdep ()
 {
   register_gdbarch_init (bfd_arch_bpf, bpf_gdbarch_init);
 
diff --git a/gdb/make-init-c b/gdb/make-init-c
new file mode 100755
index 000000000000..227895f69078
--- /dev/null
+++ b/gdb/make-init-c
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2013-2021 Free Software Foundation, Inc.
+#
+# This file is part of GDB.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Usage:
+#
+#    ./make-init-c source-files > init.c-tmp
+#
+# Where SOURCE-FILES is the list of source files to extract init functions from.
+
+# Abort on command error.
+set -e
+
+init_files=("$@")
+functions=($(sed -n -e 's/^\(_initialize_[a-zA-Z0-9_]*\) ()$/\1/p' "${init_files[@]}"))
+
+echo "/* Do not modify this file.  */"
+echo "/* It is created automatically by the Makefile.  */"
+echo "#include \"defs.h\"      /* For initialize_file_ftype.  */"
+
+for f in "${functions[@]}"; do
+  echo "extern initialize_file_ftype $f;"
+done
+
+echo "void initialize_all_files ();"
+echo "void"
+echo "initialize_all_files ()"
+echo "{"
+
+for f in "${functions[@]}"; do
+  echo "  $f ();"
+done
+
+echo "}"
diff --git a/gdb/silent-rules.mk b/gdb/silent-rules.mk
index 7ed73a767c68..f7b959f8390c 100644
--- a/gdb/silent-rules.mk
+++ b/gdb/silent-rules.mk
@@ -9,7 +9,7 @@ ECHO_GEN_XML_BUILTIN = \
               @echo "  GEN    xml-builtin.c";
 ECHO_GEN_XML_BUILTIN_GENERATED = \
               @echo "  GEN    xml-builtin-generated.c";
-ECHO_INIT_C =  echo "  GEN    init.c" ||
+ECHO_INIT_C = @echo "  GEN    init.c"
 ECHO_SIGN =   @echo "  SIGN   gdb";
 ECHO_YACC =   @echo "  YACC   $@";
 ECHO_LEX  =   @echo "  LEX    $@";
-- 
2.31.1


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

* [PATCH 8/8] gdb: add option to reverse order of _initialize function calls
  2021-05-18 20:23 [PATCH 0/8] Change alias creation functions to accept target as cmd_list_element Simon Marchi
                   ` (6 preceding siblings ...)
  2021-05-18 20:23 ` [PATCH 7/8] gdb: add make-init-c script Simon Marchi
@ 2021-05-18 20:23 ` Simon Marchi
  7 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2021-05-18 20:23 UTC (permalink / raw)
  To: gdb-patches

An earlier patch in this series fixed a dependency problem between two
_initialize functions.  That problem was uncovered by reversing the
order of the initialize function calls.

In short, symtab.c tried to add the alias "maintenance
flush-symbol-cache" for the command "maintenance flush symbol-cache".
Because the "maintenance flush" prefix command was not yet created (it
happens in maint.c, initialized later in this reversed order), the
add_alias_cmd function returned NULL.  That result was passed to
deprecate_cmd, which didn't expected that value, and that caused a
segfault.  This was fixed by changing alias creation functions to take
the target command as a cmd_list_element, instead of by name.

This patch adds a runtime option to reverse the order of the initialize
calls at will.  I chose to use an environment variable for this, over a
parameter (even a "maintenance" one), because:

 - The init functions are called before the early init commands are
   executed, so we could use -iex to turn this mode on early enough.
   This is obvious when you remember that commands / parameters are
   created by initialize funcitions :).

 - This is not something anybody would want to tweak after startup
   anyway.

gdb/ChangeLog:

	* make-init-c: Add option to reverse function calls.

gdb/testsuite/ChangeLog:

	* gdb.base/reverse-init-functions.exp: New.

Change-Id: I543e609cf526e7cb145a006a794d0e6851b63f45
---
 gdb/make-init-c                               | 16 +++++++++-
 .../gdb.base/reverse-init-functions.exp       | 29 +++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.base/reverse-init-functions.exp

diff --git a/gdb/make-init-c b/gdb/make-init-c
index 227895f69078..104397e92f31 100755
--- a/gdb/make-init-c
+++ b/gdb/make-init-c
@@ -32,6 +32,8 @@ functions=($(sed -n -e 's/^\(_initialize_[a-zA-Z0-9_]*\) ()$/\1/p' "${init_files
 echo "/* Do not modify this file.  */"
 echo "/* It is created automatically by the Makefile.  */"
 echo "#include \"defs.h\"      /* For initialize_file_ftype.  */"
+echo ""
+echo "#include <algorithm>"
 
 for f in "${functions[@]}"; do
   echo "extern initialize_file_ftype $f;"
@@ -41,9 +43,21 @@ echo "void initialize_all_files ();"
 echo "void"
 echo "initialize_all_files ()"
 echo "{"
+echo "  std::vector<initialize_file_ftype *> functions ="
+echo "    {"
 
 for f in "${functions[@]}"; do
-  echo "  $f ();"
+  echo "      $f,"
 done
 
+echo "    };"
+echo ""
+echo "  /* If GDB_REVERSE_INIT_FUNCTIONS is set (any value), reverse the"
+echo "     order in which initialization functions are called.  This is"
+echo "     used by the testsuite.  */"
+echo "  if (getenv (\"GDB_REVERSE_INIT_FUNCTIONS\") != nullptr)"
+echo "    std::reverse (functions.begin (), functions.end ());"
+echo ""
+echo "  for (initialize_file_ftype *function : functions)"
+echo "    function ();"
 echo "}"
diff --git a/gdb/testsuite/gdb.base/reverse-init-functions.exp b/gdb/testsuite/gdb.base/reverse-init-functions.exp
new file mode 100644
index 000000000000..76fa793acb3e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/reverse-init-functions.exp
@@ -0,0 +1,29 @@
+# Copyright 2020-2021 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test reversing the order of initialize functions calls, during GDB startup.
+#
+# The intent is to catch possible unintended dependencies between two
+# initialize functions, where one depends on the other running before it.
+
+standard_testfile
+
+save_vars { env(GDB_REVERSE_INIT_FUNCTIONS) } {
+    setenv GDB_REVERSE_INIT_FUNCTIONS 1
+    clean_restart
+}
+
+# Verify that GDB has started and is ready to accept commands.
+gdb_test "print 12321" " = 12321"
-- 
2.31.1


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

* Re: [PATCH 7/8] gdb: add make-init-c script
  2021-05-18 20:23 ` [PATCH 7/8] gdb: add make-init-c script Simon Marchi
@ 2021-05-19 15:52   ` Simon Marchi
  2021-05-24 15:15     ` Tom Tromey
  0 siblings, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2021-05-19 15:52 UTC (permalink / raw)
  To: gdb-patches

On 2021-05-18 4:23 p.m., Simon Marchi wrote:
> I removed the use of stamp-init because... I am not sure if it's still
> required.  I can't remember why it's needed in the first place.  If it
> is still needed, please remind me why and I'll add it back.

I can now answer myself for this.  Because of the move-if-changed, if a
dependency (e.g. infcmd.c) is more recent than init.c, the rule will
run.  move-if-changed will see that the content has not changed, so
won't update the output file init.c (and its timestamp).  Running make
again and again will run the rule again and again, for nothing.  So if
everything's built, you'll still get:

    $ make
      GEN    init.c
    make[1]: Entering directory '/home/simark/build/binutils-gdb/gdb'
    make[2]: Entering directory '/home/simark/build/binutils-gdb/gdb/doc'
    make[2]: Nothing to be done for 'all'.
    make[2]: Leaving directory '/home/simark/build/binutils-gdb/gdb/doc'
    make[2]: Entering directory '/home/simark/build/binutils-gdb/gdb/data-directory'
    make[2]: Nothing to be done for 'all'.
    make[2]: Leaving directory '/home/simark/build/binutils-gdb/gdb/data-directory'
    make[1]: Leaving directory '/home/simark/build/binutils-gdb/gdb'

I re-introduced stamp-init, here's the updated patch:


From 568ae14c5989385babf26ef87511339fa8ffeaeb Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Tue, 18 May 2021 14:55:56 -0400
Subject: [PATCH] gdb: add make-init-c script

I would like to modify how the init.c file is generated (its content).
But as it is, a bash script with multiple sed invocations in a Makefile
target, it's not very maintainable.  Replace that with a bash script
that does the same, but in a more readable way.

The Makefile rule uses the "-" prefix in front of the for loop, I
presume to ignore any error coming from the fact that xml-builtin.c and
cp-name-parser.c are not found in the srcdir (they are generated source
files).  I prefer not to blindly ignore errors, so filter these files
out of INIT_FILES instead (we already filter out other files).

There are no expected meaningful changes to the generated init.c file.
Just the _initialize_all_file declaration that is moved down and "void"
in parenthesis that is removed.

The new regular expression is a bit tighter than the existing one, it
requires the init function to be followed by exactly ` ()`.  Update
bpf-tdep.c accordingly.

gdb/ChangeLog:

	* Makefile.in (INIT_FILES_FILTER_OUT): New.
	(INIT_FILES): Use INIT_FILES_FILTER_OUT.
	(stamp-init): Use make-initc.
	(clean mostlyclean): Remove stamp-init.
	* bpf-tdep.c (_initialize_bpf_tdep): Remove "void".
	* silent-rules.mk (ECHO_INIT_C): Change.
	* make-init-c: New file.

Change-Id: I6d6b12cbccf24ab79d1219bff05df01624c684f9
---
 gdb/Makefile.in     | 49 ++++++++++++++++++++++-----------------------
 gdb/bpf-tdep.c      |  2 +-
 gdb/make-init-c     | 49 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/silent-rules.mk |  2 +-
 4 files changed, 75 insertions(+), 27 deletions(-)
 create mode 100755 gdb/make-init-c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index a9fade803b0d..31c72b559ccb 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1837,8 +1837,15 @@ test-cp-name-parser$(EXEEXT): test-cp-name-parser.o $(LIBIBERTY)
 # maybe we could just require every .o file to have an initialization routine
 # of a given name (top.o -> _initialize_top, etc.).
 #
-# Formatting conventions:  The name of the _initialize_* routines must start
-# in column zero, and must not be inside #if.
+# Formatting conventions:  The name of the initialization routines must begin
+# with `_initialize_`, must start in column zero, and be followed with exactly
+# ` ()`.  For example:
+#
+# void
+# _initialize_foo ()
+# {
+#   ...
+# }
 #
 # Note that the set of files with init functions might change, or the names
 # of the functions might change, so this files needs to depend on all the
@@ -1846,33 +1853,25 @@ test-cp-name-parser$(EXEEXT): test-cp-name-parser.o $(LIBIBERTY)
 # this Makefile has generally been written, we do this indirectly, by
 # computing the list of source files from the list of object files.
 
+INIT_FILES_FILTER_OUT = \
+	cp-name-parser.o \
+	init.o \
+	version.o \
+	xml-builtin.o \
+	%_S.o \
+	%_U.o
+
 INIT_FILES = \
 	$(patsubst %.o,%.c, \
 	  $(patsubst %-exp.o,%-exp.y, \
-	    $(filter-out init.o version.o %_S.o %_U.o,\
-	      $(COMMON_OBS))))
+	    $(filter-out $(INIT_FILES_FILTER_OUT), $(COMMON_OBS))))
 
 init.c: stamp-init; @true
-stamp-init: $(INIT_FILES) config.status
-	@$(ECHO_INIT_C) echo "Making init.c"
-	@rm -f init.c-tmp init.l-tmp
-	@touch init.c-tmp
-	@-for f in $(INIT_FILES); do \
-	    sed -n -e 's/^_initialize_\([a-z_0-9A-Z]*\).*/\1/p' \
-	        $(srcdir)/$$f 2>/dev/null; \
-	done > init.l-tmp
-	@echo '/* Do not modify this file.  */' >>init.c-tmp
-	@echo '/* It is created automatically by the Makefile.  */'>>init.c-tmp
-	@echo '#include "defs.h"      /* For initialize_file_ftype.  */' >>init.c-tmp
-	@echo 'extern void initialize_all_files(void);' >>init.c-tmp
-	@sed -e 's/\(.*\)/extern initialize_file_ftype _initialize_\1;/' <init.l-tmp >>init.c-tmp
-	@echo 'void' >>init.c-tmp
-	@echo 'initialize_all_files (void)' >>init.c-tmp
-	@echo '{' >>init.c-tmp
-	@sed -e 's/\(.*\)/  _initialize_\1 ();/' <init.l-tmp >>init.c-tmp
-	@echo '}' >>init.c-tmp
-	@$(SHELL) $(srcdir)/../move-if-change init.c-tmp init.c
-	@echo stamp > stamp-init
+stamp-init: $(INIT_FILES) config.status $(srcdir)/make-init-c
+	$(ECHO_INIT_C)
+	$(SILENCE) $(srcdir)/make-init-c $(addprefix $(srcdir)/,$(INIT_FILES)) > init.c-tmp
+	$(SILENCE) $(SHELL) $(srcdir)/../move-if-change init.c-tmp init.c
+	$(SILENCE) echo stamp > stamp-init
 
 .PRECIOUS: init.c
 
@@ -1933,7 +1932,7 @@ tags: TAGS
 clean mostlyclean: $(CONFIG_CLEAN)
 	@$(MAKE) $(FLAGS_TO_PASS) DO=clean "DODIRS=$(CLEANDIRS)" subdir_do
 	rm -f *.o *.a *~ init.c-tmp init.l-tmp version.c-tmp
-	rm -f init.c stamp-init version.c stamp-version
+	rm -f init.c version.c stamp-version
 	rm -f gdb$(EXEEXT) core make.log
 	rm -f gdb[0-9]$(EXEEXT)
 	rm -f test-cp-name-parser$(EXEEXT)
diff --git a/gdb/bpf-tdep.c b/gdb/bpf-tdep.c
index 352a22198e96..a29cd90ba387 100644
--- a/gdb/bpf-tdep.c
+++ b/gdb/bpf-tdep.c
@@ -370,7 +370,7 @@ bpf_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
 void _initialize_bpf_tdep ();
 void
-_initialize_bpf_tdep (void)
+_initialize_bpf_tdep ()
 {
   register_gdbarch_init (bfd_arch_bpf, bpf_gdbarch_init);
 
diff --git a/gdb/make-init-c b/gdb/make-init-c
new file mode 100755
index 000000000000..227895f69078
--- /dev/null
+++ b/gdb/make-init-c
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2013-2021 Free Software Foundation, Inc.
+#
+# This file is part of GDB.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Usage:
+#
+#    ./make-init-c source-files > init.c-tmp
+#
+# Where SOURCE-FILES is the list of source files to extract init functions from.
+
+# Abort on command error.
+set -e
+
+init_files=("$@")
+functions=($(sed -n -e 's/^\(_initialize_[a-zA-Z0-9_]*\) ()$/\1/p' "${init_files[@]}"))
+
+echo "/* Do not modify this file.  */"
+echo "/* It is created automatically by the Makefile.  */"
+echo "#include \"defs.h\"      /* For initialize_file_ftype.  */"
+
+for f in "${functions[@]}"; do
+  echo "extern initialize_file_ftype $f;"
+done
+
+echo "void initialize_all_files ();"
+echo "void"
+echo "initialize_all_files ()"
+echo "{"
+
+for f in "${functions[@]}"; do
+  echo "  $f ();"
+done
+
+echo "}"
diff --git a/gdb/silent-rules.mk b/gdb/silent-rules.mk
index 7ed73a767c68..f7b959f8390c 100644
--- a/gdb/silent-rules.mk
+++ b/gdb/silent-rules.mk
@@ -9,7 +9,7 @@ ECHO_GEN_XML_BUILTIN = \
               @echo "  GEN    xml-builtin.c";
 ECHO_GEN_XML_BUILTIN_GENERATED = \
               @echo "  GEN    xml-builtin-generated.c";
-ECHO_INIT_C =  echo "  GEN    init.c" ||
+ECHO_INIT_C = @echo "  GEN    init.c"
 ECHO_SIGN =   @echo "  SIGN   gdb";
 ECHO_YACC =   @echo "  YACC   $@";
 ECHO_LEX  =   @echo "  LEX    $@";
-- 
2.31.1


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

* Re: [PATCH 1/8] gdb: make add_setshow commands return set_show_commands
  2021-05-18 20:23 ` [PATCH 1/8] gdb: make add_setshow commands return set_show_commands Simon Marchi
@ 2021-05-24 14:57   ` Tom Tromey
  0 siblings, 0 replies; 15+ messages in thread
From: Tom Tromey @ 2021-05-24 14:57 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches

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

Simon> Some add_set_show commands return a single cmd_list_element, the one for
Simon> the "set" command.  A subsequent patch will need to access the show
Simon> command's cmd_list_element as well.  Change these functions to return a
Simon> new structure type that holds both pointers.

Looks good.

Simon> I initially only modified add_setshow_boolean_cmd (the one I needed),
Simon> but I think it's better to change the whole chain to keep everything in
Simon> sync.

I agree.  Also, I feel like I've wanted this change before, so I wonder
if there's a hack somewhere in the code to work around the lack of it.
Maybe someday we'll trip over it.

Tom

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

* Re: [PATCH 7/8] gdb: add make-init-c script
  2021-05-19 15:52   ` Simon Marchi
@ 2021-05-24 15:15     ` Tom Tromey
  2021-05-25 16:38       ` Simon Marchi
  0 siblings, 1 reply; 15+ messages in thread
From: Tom Tromey @ 2021-05-24 15:15 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches

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

Simon> The Makefile rule uses the "-" prefix in front of the for loop, I
Simon> presume to ignore any error coming from the fact that xml-builtin.c and
Simon> cp-name-parser.c are not found in the srcdir (they are generated source
Simon> files).

I think it's more that the rule to convert *-exp.o to *-exp.y doesn't
work for cp-name-parser, so it was dropped because there was no need to
handle it.

Some of these files are generated in ordinary builds, but shipped in the
source tree for releases.  So, a bit of special care be needed there.

It's fine to continue dropping these, IMO.

Simon> -_initialize_bpf_tdep (void)
Simon> +_initialize_bpf_tdep ()

Funny that there's only one.

Simon> @@ -0,0 +1,49 @@
Simon> +#!/usr/bin/env bash

Historically the build system assumes a relatively plain 'sh' --
normally the most constrained sh found on systems in active use.
So, I don't think we can rely on the existence of 'bash'.

Simon> +init_files=("$@")
Simon> +functions=($(sed -n -e 's/^\(_initialize_[a-zA-Z0-9_]*\) ()$/\1/p' "${init_files[@]}"))

... also I'm not sure that advanced stuff like this is ok.

Could this be rewritten as a pipeline instead?  Like

sed ... | while read f; do
  process $f
done

Perhaps a temporary file would be needed.  Or the iteration could be
done twice.  Or even, the code could generate a C macro that is then
expanded twice, once for declarations and once in the array, like:

#define NAMES \
  NAME(A) \
  NAME(b) \
  ...

#define NAME(x) extern blah blah x;
NAMES

Simon> -	rm -f init.c stamp-init version.c stamp-version
Simon> +	rm -f init.c version.c stamp-version

I think this was left in by mistake.


I wonder if the comment about _initialize_X formatting should be stuck
in the new script.

thanks,
Tom

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

* Re: [PATCH 7/8] gdb: add make-init-c script
  2021-05-24 15:15     ` Tom Tromey
@ 2021-05-25 16:38       ` Simon Marchi
  2021-05-26 12:39         ` Tom Tromey
  0 siblings, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2021-05-25 16:38 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches

On 2021-05-24 11:15 a.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> The Makefile rule uses the "-" prefix in front of the for loop, I
> Simon> presume to ignore any error coming from the fact that xml-builtin.c and
> Simon> cp-name-parser.c are not found in the srcdir (they are generated source
> Simon> files).
> 
> I think it's more that the rule to convert *-exp.o to *-exp.y doesn't
> work for cp-name-parser, so it was dropped because there was no need to
> handle it.
> 
> Some of these files are generated in ordinary builds, but shipped in the
> source tree for releases.  So, a bit of special care be needed there.
> 
> It's fine to continue dropping these, IMO.

Ok.

> Simon> -_initialize_bpf_tdep (void)
> Simon> +_initialize_bpf_tdep ()
> 
> Funny that there's only one.

I removed them all in 6c2659886f70 ("gdb: add back declarations for
_initialize functions"), and the bpf one is the only one that crept back
in with the old style.

> Simon> @@ -0,0 +1,49 @@
> Simon> +#!/usr/bin/env bash
> 
> Historically the build system assumes a relatively plain 'sh' --
> normally the most constrained sh found on systems in active use.
> So, I don't think we can rely on the existence of 'bash'.

Arrg, right.  It's a bit annoying to consider bash as "too fancy".

> 
> Simon> +init_files=("$@")
> Simon> +functions=($(sed -n -e 's/^\(_initialize_[a-zA-Z0-9_]*\) ()$/\1/p' "${init_files[@]}"))
> 
> ... also I'm not sure that advanced stuff like this is ok.
> 
> Could this be rewritten as a pipeline instead?  Like
> 
> sed ... | while read f; do
>   process $f
> done
> 
> Perhaps a temporary file would be needed.  Or the iteration could be
> done twice.  Or even, the code could generate a C macro that is then
> expanded twice, once for declarations and once in the array, like:
> 
> #define NAMES \
>   NAME(A) \
>   NAME(b) \
>   ...
> 
> #define NAME(x) extern blah blah x;
> NAMES

I tried the #define trick.  It worked but made the code much less
readable.  I'll just sed twice, it's not the end of the world, it will
just take a few cycles more.

> 
> Simon> -	rm -f init.c stamp-init version.c stamp-version
> Simon> +	rm -f init.c version.c stamp-version
> 
> I think this was left in by mistake.

Indeed, fixed.

> I wonder if the comment about _initialize_X formatting should be stuck
> in the new script.

Indeed, given that the sed command that extracts them is there, it makes
sense.

Here's the updated version.


From f5f5a7ed3c63418bb8cc4ce26fc854f0ce519e72 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Tue, 18 May 2021 14:55:56 -0400
Subject: [PATCH] gdb: add make-init-c script

I would like to modify how the init.c file is generated (its content).
But as it is, a shell script with multiple sed invocations in a Makefile
target, it's not very maintainable.  Replace that with a shell script
that does the same, but in a more readable way.

The Makefile rule uses the "-" prefix in front of the for loop, I
presume to ignore any error coming from the fact that xml-builtin.c and
cp-name-parser.c are not found in the srcdir (they are generated source
files).  I prefer not to blindly ignore errors, so filter these files
out of INIT_FILES instead (we already filter out other files).

There are no expected meaningful changes to the generated init.c file.
Just the _initialize_all_file declaration that is moved down and "void"
in parenthesis that is removed.

The new regular expression is a bit tighter than the existing one, it
requires the init function to be followed by exactly ` ()`.  Update
bpf-tdep.c accordingly.

gdb/ChangeLog:

	* Makefile.in (INIT_FILES_FILTER_OUT): New.
	(INIT_FILES): Use INIT_FILES_FILTER_OUT.
	(stamp-init): Use make-init-c.
	* bpf-tdep.c (_initialize_bpf_tdep): Remove "void".
	* silent-rules.mk (ECHO_INIT_C): Change.
	* make-init-c: New file.

Change-Id: I6d6b12cbccf24ab79d1219bff05df01624c684f9
---
 gdb/Makefile.in     | 39 +++++++++++--------------------
 gdb/bpf-tdep.c      |  2 +-
 gdb/make-init-c     | 57 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/silent-rules.mk |  2 +-
 4 files changed, 73 insertions(+), 27 deletions(-)
 create mode 100755 gdb/make-init-c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index a9fade803b0d..bb6c5dfa7847 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1837,42 +1837,31 @@ test-cp-name-parser$(EXEEXT): test-cp-name-parser.o $(LIBIBERTY)
 # maybe we could just require every .o file to have an initialization routine
 # of a given name (top.o -> _initialize_top, etc.).
 #
-# Formatting conventions:  The name of the _initialize_* routines must start
-# in column zero, and must not be inside #if.
-#
 # Note that the set of files with init functions might change, or the names
 # of the functions might change, so this files needs to depend on all the
 # source files that will be linked into gdb.  However, due to the way
 # this Makefile has generally been written, we do this indirectly, by
 # computing the list of source files from the list of object files.
 
+INIT_FILES_FILTER_OUT = \
+	cp-name-parser.o \
+	init.o \
+	version.o \
+	xml-builtin.o \
+	%_S.o \
+	%_U.o
+
 INIT_FILES = \
 	$(patsubst %.o,%.c, \
 	  $(patsubst %-exp.o,%-exp.y, \
-	    $(filter-out init.o version.o %_S.o %_U.o,\
-	      $(COMMON_OBS))))
+	    $(filter-out $(INIT_FILES_FILTER_OUT), $(COMMON_OBS))))
 
 init.c: stamp-init; @true
-stamp-init: $(INIT_FILES) config.status
-	@$(ECHO_INIT_C) echo "Making init.c"
-	@rm -f init.c-tmp init.l-tmp
-	@touch init.c-tmp
-	@-for f in $(INIT_FILES); do \
-	    sed -n -e 's/^_initialize_\([a-z_0-9A-Z]*\).*/\1/p' \
-	        $(srcdir)/$$f 2>/dev/null; \
-	done > init.l-tmp
-	@echo '/* Do not modify this file.  */' >>init.c-tmp
-	@echo '/* It is created automatically by the Makefile.  */'>>init.c-tmp
-	@echo '#include "defs.h"      /* For initialize_file_ftype.  */' >>init.c-tmp
-	@echo 'extern void initialize_all_files(void);' >>init.c-tmp
-	@sed -e 's/\(.*\)/extern initialize_file_ftype _initialize_\1;/' <init.l-tmp >>init.c-tmp
-	@echo 'void' >>init.c-tmp
-	@echo 'initialize_all_files (void)' >>init.c-tmp
-	@echo '{' >>init.c-tmp
-	@sed -e 's/\(.*\)/  _initialize_\1 ();/' <init.l-tmp >>init.c-tmp
-	@echo '}' >>init.c-tmp
-	@$(SHELL) $(srcdir)/../move-if-change init.c-tmp init.c
-	@echo stamp > stamp-init
+stamp-init: $(INIT_FILES) config.status $(srcdir)/make-init-c
+	$(ECHO_INIT_C)
+	$(SILENCE) $(srcdir)/make-init-c $(addprefix $(srcdir)/,$(INIT_FILES)) > init.c-tmp
+	$(SILENCE) $(SHELL) $(srcdir)/../move-if-change init.c-tmp init.c
+	$(SILENCE) echo stamp > stamp-init
 
 .PRECIOUS: init.c
 
diff --git a/gdb/bpf-tdep.c b/gdb/bpf-tdep.c
index 352a22198e96..a29cd90ba387 100644
--- a/gdb/bpf-tdep.c
+++ b/gdb/bpf-tdep.c
@@ -370,7 +370,7 @@ bpf_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
 void _initialize_bpf_tdep ();
 void
-_initialize_bpf_tdep (void)
+_initialize_bpf_tdep ()
 {
   register_gdbarch_init (bfd_arch_bpf, bpf_gdbarch_init);
 
diff --git a/gdb/make-init-c b/gdb/make-init-c
new file mode 100755
index 000000000000..1588760112ed
--- /dev/null
+++ b/gdb/make-init-c
@@ -0,0 +1,57 @@
+#!/usr/bin/env sh
+
+# Copyright (C) 2013-2021 Free Software Foundation, Inc.
+#
+# This file is part of GDB.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Generate the init.c source file.
+#
+# Usage:
+#
+#    ./make-init-c source-files > init.c-tmp
+#
+# Where SOURCE-FILES is the list of source files to extract init functions from.
+#
+# Formatting conventions:  The name of the initialization routines must begin
+# with `_initialize_`, must start in column zero, and be followed with exactly
+# ` ()`.  For example:
+#
+# void
+# _initialize_foo ()
+# {
+#   ...
+# }
+#
+
+# Abort on command error.
+set -e
+
+echo "/* Do not modify this file.  */"
+echo "/* It is created automatically by the Makefile.  */"
+echo "#include \"defs.h\"      /* For initialize_file_ftype.  */"
+echo ""
+sed -n -e 's/^\(_initialize_[a-zA-Z0-9_]*\) ()$/\1/p' "$@" | while read -r name; do
+  echo "extern initialize_file_ftype $name;"
+done
+echo ""
+echo "void initialize_all_files ();"
+echo "void"
+echo "initialize_all_files ()"
+echo "{"
+sed -n -e 's/^\(_initialize_[a-zA-Z0-9_]*\) ()$/\1/p' "$@" | while read -r name; do
+  echo "  $name ();"
+done
+echo "}"
diff --git a/gdb/silent-rules.mk b/gdb/silent-rules.mk
index 7ed73a767c68..f7b959f8390c 100644
--- a/gdb/silent-rules.mk
+++ b/gdb/silent-rules.mk
@@ -9,7 +9,7 @@ ECHO_GEN_XML_BUILTIN = \
               @echo "  GEN    xml-builtin.c";
 ECHO_GEN_XML_BUILTIN_GENERATED = \
               @echo "  GEN    xml-builtin-generated.c";
-ECHO_INIT_C =  echo "  GEN    init.c" ||
+ECHO_INIT_C = @echo "  GEN    init.c"
 ECHO_SIGN =   @echo "  SIGN   gdb";
 ECHO_YACC =   @echo "  YACC   $@";
 ECHO_LEX  =   @echo "  LEX    $@";
-- 
2.31.1


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

* Re: [PATCH 7/8] gdb: add make-init-c script
  2021-05-25 16:38       ` Simon Marchi
@ 2021-05-26 12:39         ` Tom Tromey
  2021-05-27 18:01           ` Simon Marchi
  0 siblings, 1 reply; 15+ messages in thread
From: Tom Tromey @ 2021-05-26 12:39 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Tom Tromey, Simon Marchi

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

Simon> Here's the updated version.

Looks good.  Thank you.

Tom

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

* Re: [PATCH 7/8] gdb: add make-init-c script
  2021-05-26 12:39         ` Tom Tromey
@ 2021-05-27 18:01           ` Simon Marchi
  0 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2021-05-27 18:01 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches



On 2021-05-26 8:39 a.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> Here's the updated version.
> 
> Looks good.  Thank you.
> 
> Tom
> 

Thanks, I pushed the series.

Simon

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

end of thread, other threads:[~2021-05-27 18:01 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-18 20:23 [PATCH 0/8] Change alias creation functions to accept target as cmd_list_element Simon Marchi
2021-05-18 20:23 ` [PATCH 1/8] gdb: make add_setshow commands return set_show_commands Simon Marchi
2021-05-24 14:57   ` Tom Tromey
2021-05-18 20:23 ` [PATCH 2/8] gdb: remove unnecessary lookup_cmd when deprecating commands Simon Marchi
2021-05-18 20:23 ` [PATCH 3/8] gdb/python: use return values of add_setshow functions in add_setshow_generic Simon Marchi
2021-05-18 20:23 ` [PATCH 4/8] gdb: make add_com_alias accept target as a cmd_list_element Simon Marchi
2021-05-18 20:23 ` [PATCH 5/8] gdb: make add_info_alias " Simon Marchi
2021-05-18 20:23 ` [PATCH 6/8] gdb: remove add_alias_cmd overload that accepts a string Simon Marchi
2021-05-18 20:23 ` [PATCH 7/8] gdb: add make-init-c script Simon Marchi
2021-05-19 15:52   ` Simon Marchi
2021-05-24 15:15     ` Tom Tromey
2021-05-25 16:38       ` Simon Marchi
2021-05-26 12:39         ` Tom Tromey
2021-05-27 18:01           ` Simon Marchi
2021-05-18 20:23 ` [PATCH 8/8] gdb: add option to reverse order of _initialize function calls Simon Marchi

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