diff options
author | 2021-06-29 23:10:32 -0400 | |
---|---|---|
committer | 2021-07-23 15:38:54 -0400 | |
commit | 5538b03c98e77756b1e1d3e3be86f997a78e6d11 (patch) | |
tree | a5cfc5baadd65eb9bfed28fff143687c425a2b94 /gdb/cli | |
parent | gdb: rename cfunc to simple_func (diff) | |
download | binutils-gdb-5538b03c98e77756b1e1d3e3be86f997a78e6d11.tar.gz binutils-gdb-5538b03c98e77756b1e1d3e3be86f997a78e6d11.tar.bz2 binutils-gdb-5538b03c98e77756b1e1d3e3be86f997a78e6d11.zip |
gdb: remove cmd_list_element::function::sfunc
I don't understand what the sfunc function type in
cmd_list_element::function is for. Compared to cmd_simple_func_ftype,
it has an extra cmd_list_element parameter, giving the callback access
to the cmd_list_element for the command being invoked. This allows
registering the same callback with many commands, and alter the behavior
using the cmd_list_element's context.
From the comment in cmd_list_element, it sounds like at some point it
was the callback function type for set and show functions, hence the
"s". But nowadays, it's used for many more commands that need to access
the cmd_list_element object (see add_catch_command for example).
I don't really see the point of having sfunc at all, since do_sfunc is
just a trivial shim that changes the order of the arguments. All
commands using sfunc could just as well set cmd_list_element::func to
their callback directly.
Therefore, remove the sfunc field in cmd_list_element and everything
that goes with it. Rename cmd_const_sfunc_ftype to cmd_func_ftype and
use it for cmd_list_element::func, as well as for the add_setshow
commands.
Change-Id: I1eb96326c9b511c293c76996cea0ebc51c70fac0
Diffstat (limited to 'gdb/cli')
-rw-r--r-- | gdb/cli/cli-decode.c | 66 | ||||
-rw-r--r-- | gdb/cli/cli-decode.h | 8 | ||||
-rw-r--r-- | gdb/cli/cli-dump.c | 2 | ||||
-rw-r--r-- | gdb/cli/cli-setshow.c | 5 |
4 files changed, 28 insertions, 53 deletions
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 3c39e47ac69..06f3de0f038 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -91,13 +91,8 @@ static void print_help_for_command (struct cmd_list_element *c, bool recurse, struct ui_file *stream); - -/* Set the callback function for the specified command. For each both - the commands callback and func() are set. The latter set to a - bounce function (unless simple_func / sfunc is NULL that is). */ - static void -do_simple_func (struct cmd_list_element *c, const char *args, int from_tty) +do_simple_func (const char *args, int from_tty, cmd_list_element *c) { c->function.simple_func (args, from_tty); } @@ -113,22 +108,6 @@ set_cmd_simple_func (struct cmd_list_element *cmd, cmd_simple_func_ftype *simple cmd->function.simple_func = simple_func; } -static void -do_sfunc (struct cmd_list_element *c, const char *args, int from_tty) -{ - c->function.sfunc (args, from_tty, c); -} - -void -set_cmd_sfunc (struct cmd_list_element *cmd, cmd_const_sfunc_ftype *sfunc) -{ - if (sfunc == NULL) - cmd->func = NULL; - else - cmd->func = do_sfunc; - cmd->function.sfunc = sfunc; -} - int cmd_simple_func_eq (struct cmd_list_element *cmd, cmd_simple_func_ftype *simple_func) { @@ -401,7 +380,7 @@ add_basic_prefix_cmd (const char *name, enum command_class theclass, struct cmd_list_element *cmd = add_prefix_cmd (name, theclass, nullptr, doc, subcommands, allow_unknown, list); - set_cmd_sfunc (cmd, do_prefix_cmd); + cmd->func = do_prefix_cmd; return cmd; } @@ -424,7 +403,7 @@ add_show_prefix_cmd (const char *name, enum command_class theclass, struct cmd_list_element *cmd = add_prefix_cmd (name, theclass, nullptr, doc, subcommands, allow_unknown, list); - set_cmd_sfunc (cmd, do_show_prefix_cmd); + cmd->func = do_show_prefix_cmd; return cmd; } @@ -468,10 +447,10 @@ not_just_help_class_command (const char *args, int from_tty) { } -/* This is an empty "sfunc". */ +/* This is an empty cmd func. */ static void -empty_sfunc (const char *args, int from_tty, struct cmd_list_element *c) +empty_func (const char *args, int from_tty, cmd_list_element *c) { } @@ -500,7 +479,7 @@ add_set_or_show_cmd (const char *name, c->var = var; /* This needs to be something besides NULL so that this isn't treated as a help class. */ - set_cmd_sfunc (c, empty_sfunc); + c->func = empty_func; return c; } @@ -519,7 +498,7 @@ add_setshow_cmd_full (const char *name, var_types var_type, void *var, const char *set_doc, const char *show_doc, const char *help_doc, - cmd_const_sfunc_ftype *set_func, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -544,7 +523,7 @@ add_setshow_cmd_full (const char *name, set->doc_allocated = 1; if (set_func != NULL) - set_cmd_sfunc (set, set_func); + set->func = set_func; show = add_set_or_show_cmd (name, show_cmd, theclass, var_type, var, full_show_doc, show_list); @@ -570,7 +549,7 @@ add_setshow_enum_cmd (const char *name, const char *set_doc, const char *show_doc, const char *help_doc, - cmd_const_sfunc_ftype *set_func, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -598,7 +577,7 @@ add_setshow_auto_boolean_cmd (const char *name, enum auto_boolean *var, const char *set_doc, const char *show_doc, const char *help_doc, - cmd_const_sfunc_ftype *set_func, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -627,7 +606,7 @@ 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, - cmd_const_sfunc_ftype *set_func, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -651,7 +630,7 @@ 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, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -675,7 +654,7 @@ 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, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -700,7 +679,7 @@ 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, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -725,7 +704,7 @@ 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, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -769,7 +748,7 @@ 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, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -795,7 +774,7 @@ 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, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -821,7 +800,7 @@ 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, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -839,7 +818,7 @@ add_setshow_zuinteger_unlimited_cmd (const char *name, const char *set_doc, const char *show_doc, const char *help_doc, - cmd_const_sfunc_ftype *set_func, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -865,7 +844,7 @@ 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, + cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list) @@ -2159,7 +2138,7 @@ cmd_func (struct cmd_list_element *cmd, const char *args, int from_tty) if (cmd->suppress_notification != NULL) restore_suppress.emplace (cmd->suppress_notification, 1); - (*cmd->func) (cmd, args, from_tty); + cmd->func (args, from_tty, cmd); } else error (_("Invalid command")); @@ -2168,6 +2147,5 @@ cmd_func (struct cmd_list_element *cmd, const char *args, int from_tty) int cli_user_command_p (struct cmd_list_element *cmd) { - return (cmd->theclass == class_user - && (cmd->func == do_simple_func || cmd->func == do_sfunc)); + return cmd->theclass == class_user && cmd->func == do_simple_func; } diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h index 4cbdf7ff6d1..651d1ef8abb 100644 --- a/gdb/cli/cli-decode.h +++ b/gdb/cli/cli-decode.h @@ -168,8 +168,8 @@ struct cmd_list_element cagney/2002-02-02: This function signature is evolving. For the moment suggest sticking with either set_cmd_cfunc() or set_cmd_sfunc(). */ - void (*func) (struct cmd_list_element *c, const char *args, int from_tty) - = nullptr; + cmd_func_ftype *func; + /* The command's real callback. At present func() bounces through to one of the below. */ union @@ -179,10 +179,6 @@ struct cmd_list_element cmd_list_element parameter. do_simple_func is installed as FUNC, and acts as a shim between the two. */ cmd_simple_func_ftype *simple_func; - - /* If type is set_cmd or show_cmd, first set the variables, - and then call this: */ - cmd_const_sfunc_ftype *sfunc; } function; diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c index efb40041804..6f7688ad58f 100644 --- a/gdb/cli/cli-dump.c +++ b/gdb/cli/cli-dump.c @@ -331,7 +331,7 @@ struct dump_context }; static void -call_dump_func (struct cmd_list_element *c, const char *args, int from_tty) +call_dump_func (const char *args, int from_tty, cmd_list_element *c) { struct dump_context *d = (struct dump_context *) c->context (); diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index 5fd5fd15c6a..0290acede7f 100644 --- a/gdb/cli/cli-setshow.c +++ b/gdb/cli/cli-setshow.c @@ -517,7 +517,8 @@ do_set_command (const char *arg, int from_tty, struct cmd_list_element *c) default: error (_("gdb internal error: bad var_type in do_setshow_command")); } - c->func (c, NULL, from_tty); + + c->func (NULL, from_tty, c); if (notify_command_param_changed_p (option_changed, c)) { @@ -723,7 +724,7 @@ do_show_command (const char *arg, int from_tty, struct cmd_list_element *c) deprecated_show_value_hack (gdb_stdout, from_tty, c, val.c_str ()); } - c->func (c, NULL, from_tty); + c->func (NULL, from_tty, c); } /* Show all the settings in a list of show commands. */ |