gdb/guile: use return values of add_setshow functions in add_setshow_generic
authorSimon Marchi <simon.marchi@polymtl.ca>
Sat, 26 Jun 2021 01:38:20 +0000 (21:38 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 26 Jun 2021 01:39:29 +0000 (21:39 -0400)
Use the set_show_commands objects returned by the add_setshow functions
in add_setshow_generic.  This lets us avoid looking up the commands
after creating them, instead using the return objects directly.

Make add_setshow_generic return a set_show_commands object, which is a
bit nicer than returning both commands by parameter.

Finally, store using that object in param_smob.

Equivalent of 7bd22f56a3cf ("gdb/python: use return values of
add_setshow functions in add_setshow_generic"), but for guile.

gdb/ChangeLog:

* guile/scm-param.c (struct param_smob) <set_command,
show_command>: Remove.
<commands>: New.
(pascm_is_valid): Adjust.
(add_setshow_generic): Use return values of add_setshow
functions, return a set_show_commands.
(gdbscm_register_parameter_x): Adjust.

Change-Id: I18ed9e7dd5646529491c86749a5cb20763acd1f0

gdb/ChangeLog
gdb/guile/scm-param.c

index 9acde122a2a8aa8edaab4d0fc00b716e0ec7bd6e..14d4a9ec226f9d7e96cb962eaed7fabf78a3af08 100644 (file)
@@ -1,3 +1,13 @@
+2021-06-25  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * guile/scm-param.c (struct param_smob) <set_command,
+       show_command>: Remove.
+       <commands>: New.
+       (pascm_is_valid): Adjust.
+       (add_setshow_generic): Use return values of add_setshow
+       functions, return a set_show_commands.
+       (gdbscm_register_parameter_x): Adjust.
+
 2021-06-25  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * command.h (add_setshow_enum_cmd): Remove context parameter.
index 86f61057a32f843c96921ee3102505fd6056bbbe..c052d04974ae2be57f105731f80c2276afc511a8 100644 (file)
@@ -89,8 +89,7 @@ struct param_smob
   /* The corresponding gdb command objects.
      These are NULL if the parameter has not been registered yet, or
      is no longer registered.  */
-  struct cmd_list_element *set_command;
-  struct cmd_list_element *show_command;
+  set_show_commands commands;
 
   /* The value of the parameter.  */
   union pascm_variable value;
@@ -232,7 +231,7 @@ pascm_get_param_smob_arg_unsafe (SCM self, int arg_pos, const char *func_name)
 static int
 pascm_is_valid (param_smob *p_smob)
 {
-  return p_smob->set_command != NULL;
+  return p_smob->commands.set != nullptr;
 }
 \f
 /* A helper function which return the default documentation string for
@@ -350,111 +349,100 @@ pascm_show_func (struct ui_file *file, int from_tty,
 /* A helper function that dispatches to the appropriate add_setshow
    function.  */
 
-static void
+static set_show_commands
 add_setshow_generic (enum var_types param_type, enum command_class cmd_class,
                     char *cmd_name, param_smob *self,
                     char *set_doc, char *show_doc, 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,
-                    struct cmd_list_element **set_cmd,
-                    struct cmd_list_element **show_cmd)
+                    struct cmd_list_element **show_list)
 {
-  struct cmd_list_element *param = NULL;
-  const char *tmp_name = NULL;
+  set_show_commands commands;
 
   switch (param_type)
     {
     case var_boolean:
-      add_setshow_boolean_cmd (cmd_name, cmd_class,
-                              &self->value.boolval,
-                              set_doc, show_doc, help_doc,
-                              set_func, show_func,
-                              set_list, show_list);
-
+      commands = add_setshow_boolean_cmd (cmd_name, cmd_class,
+                                         &self->value.boolval, set_doc,
+                                         show_doc, help_doc, set_func,
+                                         show_func, set_list, show_list);
       break;
 
     case var_auto_boolean:
-      add_setshow_auto_boolean_cmd (cmd_name, cmd_class,
-                                   &self->value.autoboolval,
-                                   set_doc, show_doc, help_doc,
-                                   set_func, show_func,
-                                   set_list, show_list);
+      commands = add_setshow_auto_boolean_cmd (cmd_name, cmd_class,
+                                              &self->value.autoboolval,
+                                              set_doc, show_doc, help_doc,
+                                              set_func, show_func, set_list,
+                                              show_list);
       break;
 
     case var_uinteger:
-      add_setshow_uinteger_cmd (cmd_name, cmd_class,
-                               &self->value.uintval,
-                               set_doc, show_doc, help_doc,
-                               set_func, show_func,
-                               set_list, show_list);
+      commands = add_setshow_uinteger_cmd (cmd_name, cmd_class,
+                                          &self->value.uintval, set_doc,
+                                          show_doc, help_doc, set_func,
+                                          show_func, set_list, show_list);
       break;
 
     case var_zinteger:
-      add_setshow_zinteger_cmd (cmd_name, cmd_class,
-                               &self->value.intval,
-                               set_doc, show_doc, help_doc,
-                               set_func, show_func,
-                               set_list, show_list);
+      commands = add_setshow_zinteger_cmd (cmd_name, cmd_class,
+                                          &self->value.intval, set_doc,
+                                          show_doc, help_doc, set_func,
+                                          show_func, set_list, show_list);
       break;
 
     case var_zuinteger:
-      add_setshow_zuinteger_cmd (cmd_name, cmd_class,
-                                &self->value.uintval,
-                                set_doc, show_doc, help_doc,
-                                set_func, show_func,
-                                set_list, show_list);
+      commands = add_setshow_zuinteger_cmd (cmd_name, cmd_class,
+                                           &self->value.uintval, set_doc,
+                                           show_doc, help_doc, set_func,
+                                           show_func, set_list, show_list);
       break;
 
     case var_zuinteger_unlimited:
-      add_setshow_zuinteger_unlimited_cmd (cmd_name, cmd_class,
-                                          &self->value.intval,
-                                          set_doc, show_doc, help_doc,
-                                          set_func, show_func,
-                                          set_list, show_list);
+      commands = add_setshow_zuinteger_unlimited_cmd (cmd_name, cmd_class,
+                                                     &self->value.intval,
+                                                     set_doc, show_doc,
+                                                     help_doc, set_func,
+                                                     show_func, set_list,
+                                                     show_list);
       break;
 
     case var_string:
-      add_setshow_string_cmd (cmd_name, cmd_class,
-                             &self->value.stringval,
-                             set_doc, show_doc, help_doc,
-                             set_func, show_func,
-                             set_list, show_list);
+      commands = add_setshow_string_cmd (cmd_name, cmd_class,
+                                        &self->value.stringval, set_doc,
+                                        show_doc, help_doc, set_func,
+                                        show_func, set_list, show_list);
       break;
 
     case var_string_noescape:
-      add_setshow_string_noescape_cmd (cmd_name, cmd_class,
-                                      &self->value.stringval,
-                                      set_doc, show_doc, help_doc,
-                                      set_func, show_func,
-                                      set_list, show_list);
+      commands = add_setshow_string_noescape_cmd (cmd_name, cmd_class,
+                                                 &self->value.stringval,
+                                                 set_doc, show_doc, help_doc,
+                                                 set_func, show_func, set_list,
+                                                 show_list);
 
       break;
 
     case var_optional_filename:
-      add_setshow_optional_filename_cmd (cmd_name, cmd_class,
-                                        &self->value.stringval,
-                                        set_doc, show_doc, help_doc,
-                                        set_func, show_func,
-                                        set_list, show_list);
+      commands = add_setshow_optional_filename_cmd (cmd_name, cmd_class,
+                                                   &self->value.stringval,
+                                                   set_doc, show_doc, help_doc,
+                                                   set_func, show_func,
+                                                   set_list, show_list);
       break;
 
     case var_filename:
-      add_setshow_filename_cmd (cmd_name, cmd_class,
-                               &self->value.stringval,
-                               set_doc, show_doc, help_doc,
-                               set_func, show_func,
-                               set_list, show_list);
+      commands = add_setshow_filename_cmd (cmd_name, cmd_class,
+                                          &self->value.stringval, set_doc,
+                                          show_doc, help_doc, set_func,
+                                          show_func, set_list, show_list);
       break;
 
     case var_enum:
-      add_setshow_enum_cmd (cmd_name, cmd_class,
-                           self->enumeration,
-                           &self->value.cstringval,
-                           set_doc, show_doc, help_doc,
-                           set_func, show_func,
-                           set_list, show_list);
+      commands = add_setshow_enum_cmd (cmd_name, cmd_class, self->enumeration,
+                                      &self->value.cstringval, set_doc,
+                                      show_doc, help_doc, set_func, show_func,
+                                      set_list, show_list);
       /* Initialize the value, just in case.  */
       self->value.cstringval = self->enumeration[0];
       break;
@@ -463,19 +451,12 @@ add_setshow_generic (enum var_types param_type, enum command_class cmd_class,
       gdb_assert_not_reached ("bad param_type value");
     }
 
-  /* Lookup created parameter, and register Scheme object against the
-     parameter context.  Perform this task against both lists.  */
-  tmp_name = cmd_name;
-  param = lookup_cmd (&tmp_name, *show_list, "", NULL, 0, 1);
-  gdb_assert (param != NULL);
-  param->set_context (self);
-  *set_cmd = param;
-
-  tmp_name = cmd_name;
-  param = lookup_cmd (&tmp_name, *set_list, "", NULL, 0, 1);
-  gdb_assert (param != NULL);
-  param->set_context (self);
-  *show_cmd = param;
+  /* Register Scheme object against the commandsparameter context.  Perform this
+     task against both lists.  */
+  commands.set->set_context (self);
+  commands.show->set_context (self);
+
+  return commands;
 }
 
 /* Return an array of strings corresponding to the enum values for
@@ -1012,15 +993,12 @@ gdbscm_register_parameter_x (SCM self)
   gdbscm_gdb_exception exc {};
   try
     {
-      add_setshow_generic (p_smob->type, p_smob->cmd_class,
-                          p_smob->cmd_name, p_smob,
-                          p_smob->set_doc, p_smob->show_doc, p_smob->doc,
-                          (gdbscm_is_procedure (p_smob->set_func)
-                           ? pascm_set_func : NULL),
-                          (gdbscm_is_procedure (p_smob->show_func)
-                           ? pascm_show_func : NULL),
-                          set_list, show_list,
-                          &p_smob->set_command, &p_smob->show_command);
+      p_smob->commands = add_setshow_generic
+       (p_smob->type, p_smob->cmd_class, p_smob->cmd_name, p_smob,
+        p_smob->set_doc, p_smob->show_doc, p_smob->doc,
+        (gdbscm_is_procedure (p_smob->set_func) ? pascm_set_func : NULL),
+        (gdbscm_is_procedure (p_smob->show_func) ? pascm_show_func : NULL),
+        set_list, show_list);
     }
   catch (const gdb_exception &except)
     {