summaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-05-27 13:59:00 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-05-27 14:00:07 -0400
commit7bd22f56a3cf47c6743f7f7989a6fa07f935d31b (patch)
tree5d825ebce7ef9b3e2b75f1812451885946ae7e7e /gdb/python
parent9f26053690299e3a5d295d78c4ceeaf840344f0b (diff)
downloadbinutils-gdb-7bd22f56a3cf47c6743f7f7989a6fa07f935d31b.tar.gz
gdb/python: use return values of add_setshow functions in add_setshow_generic
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
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-param.c133
1 files changed, 66 insertions, 67 deletions
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 99a57960c05..d0a4850bdc0 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 ();