Add add_cmd function overloads

This adds two add_cmd overloads: one whose callback takes a const char *,
and one that doesn't accept a function at all.  The no-function overload
was introduced to avoid ambiguity when NULL was passed as the function.

Long term the goal is for all commands to take const arguments, and
for the non-const variants to be removed entirely.

gdb/ChangeLog
2017-09-27  Tom Tromey  <tom@tromey.com>

	* cli/cli-decode.c (add_cmd, set_cmd_cfunc): New function
	overloads.
	(do_add_cmd): Rename from add_cmd.  Don't call set_cmd_cfunc.
	(do_const_cfunc): New function.
	(cmd_cfunc_eq): New overload.
	(cli_user_command_p): Check do_const_cfunc.
	* cli/cli-decode.h (struct cmd_list_element) <function>: New field
	const_cfunc.
	* command.h (add_cmd): Add const overload and no-function
	overload.
	(set_cmd_cfunc): Add const overload.
	(cmd_const_cfunc_ftype): Declare.
	(cmd_cfunc_eq): Add const overload.
	* breakpoint.c, cli-cmds.c, cli-dump.c, guile/scm-cmd.c,
	python/py-cmd.c, target.c, tracepoint.c: Use no-function add_cmd
	overload.
This commit is contained in:
Tom Tromey
2017-09-09 20:51:33 -06:00
parent a9bbfbd85f
commit 0450cc4ce8
11 changed files with 124 additions and 31 deletions

View File

@ -1693,28 +1693,28 @@ _initialize_cli_cmds (void)
/* Define the classes of commands.
They will appear in the help list in alphabetical order. */
add_cmd ("internals", class_maintenance, NULL, _("\
add_cmd ("internals", class_maintenance, _("\
Maintenance commands.\n\
Some gdb commands are provided just for use by gdb maintainers.\n\
These commands are subject to frequent change, and may not be as\n\
well documented as user commands."),
&cmdlist);
add_cmd ("obscure", class_obscure, NULL, _("Obscure features."), &cmdlist);
add_cmd ("aliases", class_alias, NULL,
add_cmd ("obscure", class_obscure, _("Obscure features."), &cmdlist);
add_cmd ("aliases", class_alias,
_("Aliases of other commands."), &cmdlist);
add_cmd ("user-defined", class_user, NULL, _("\
add_cmd ("user-defined", class_user, _("\
User-defined commands.\n\
The commands in this class are those defined by the user.\n\
Use the \"define\" command to define a command."), &cmdlist);
add_cmd ("support", class_support, NULL, _("Support facilities."), &cmdlist);
add_cmd ("support", class_support, _("Support facilities."), &cmdlist);
if (!dbx_commands)
add_cmd ("status", class_info, NULL, _("Status inquiries."), &cmdlist);
add_cmd ("files", class_files, NULL, _("Specifying and examining files."),
add_cmd ("status", class_info, _("Status inquiries."), &cmdlist);
add_cmd ("files", class_files, _("Specifying and examining files."),
&cmdlist);
add_cmd ("breakpoints", class_breakpoint, NULL,
add_cmd ("breakpoints", class_breakpoint,
_("Making program stop at certain points."), &cmdlist);
add_cmd ("data", class_vars, NULL, _("Examining data."), &cmdlist);
add_cmd ("stack", class_stack, NULL, _("\
add_cmd ("data", class_vars, _("Examining data."), &cmdlist);
add_cmd ("stack", class_stack, _("\
Examining the stack.\n\
The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
counting from zero for the innermost (currently executing) frame.\n\n\
@ -1723,7 +1723,7 @@ Variable lookups are done with respect to the selected frame.\n\
When the program being debugged stops, gdb selects the innermost frame.\n\
The commands below can be used to select other frames by number or address."),
&cmdlist);
add_cmd ("running", class_run, NULL, _("Running the program."), &cmdlist);
add_cmd ("running", class_run, _("Running the program."), &cmdlist);
/* Define general commands. */