+2021-05-27 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * 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.
+
2021-05-27 Tom de Vries <tdevries@suse.de>
PR symtab/27919
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,
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;
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
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,
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. */
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,
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. */
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,
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,
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,
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,
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,
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
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,
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,
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,
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,
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,
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
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. */
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."), _("\
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);
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."), _("\
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);
}
/* 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, _("\
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."), _("\