From: Simon Marchi Date: Thu, 27 May 2021 17:59:00 +0000 (-0400) Subject: gdb/python: use return values of add_setshow functions in add_setshow_generic X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7bd22f56a3cf;p=binutils-gdb.git 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 --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 354384a3937..7e06361ac6f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-05-27 Simon Marchi + + * python/py-param.c (add_setshow_generic): Use return values of + add_setshow functions. + 2021-05-27 Simon Marchi * mi/mi-main.c (_initialize_mi_main): 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 ();