aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-06-25 21:38:20 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-06-25 21:39:29 -0400
commit6a72dbb692efa28ac732e7a5584229dad3aeb317 (patch)
tree934c53fb48cb32fc59c9c61a3c851e3a47848bd3 /gdb/guile
parent4c0ba02a749d84a7e569e010fca9f640c30d17df (diff)
downloadgdb-6a72dbb692efa28ac732e7a5584229dad3aeb317.zip
gdb-6a72dbb692efa28ac732e7a5584229dad3aeb317.tar.gz
gdb-6a72dbb692efa28ac732e7a5584229dad3aeb317.tar.bz2
gdb/guile: use return values of add_setshow functions in add_setshow_generic
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
Diffstat (limited to 'gdb/guile')
-rw-r--r--gdb/guile/scm-param.c154
1 files changed, 66 insertions, 88 deletions
diff --git a/gdb/guile/scm-param.c b/gdb/guile/scm-param.c
index 86f6105..c052d04 100644
--- a/gdb/guile/scm-param.c
+++ b/gdb/guile/scm-param.c
@@ -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;
}
/* 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)
{