gdb: make add_com_alias accept target as a cmd_list_element

The alias creation functions currently accept a name to specify the
target command.  They pass this to add_alias_cmd, which needs to lookup
the target command by name.

Given that:

 - We don't support creating an alias for a command before that command
   exists.
 - We always use add_info_alias just after creating that target command,
   and therefore have access to the target command's cmd_list_element.

... change add_com_alias to accept the target command as a
cmd_list_element (other functions are done in subsequent patches).  This
ensures we don't create the alias before the target command, because you
need to get the cmd_list_element from somewhere when you call the alias
creation function.  And it avoids an unecessary command lookup.  So it
seems better to me in every aspect.

gdb/ChangeLog:

	* command.h (add_com_alias): Accept target as
	cmd_list_element.  Update callers.

Change-Id: I24bed7da57221cc77606034de3023fedac015150
This commit is contained in:
Simon Marchi
2021-05-27 13:59:01 -04:00
parent 7bd22f56a3
commit 3947f654ea
22 changed files with 219 additions and 173 deletions

View File

@ -3329,22 +3329,24 @@ An argument says how many frames up to go."));
Same as the `up' command, but does not print anything.\n\
This is useful in command scripts."));
add_com ("down", class_stack, down_command, _("\
cmd_list_element *down_cmd
= add_com ("down", class_stack, down_command, _("\
Select and print stack frame called by this one.\n\
An argument says how many frames down to go."));
add_com_alias ("do", "down", class_stack, 1);
add_com_alias ("dow", "down", class_stack, 1);
add_com_alias ("do", down_cmd, class_stack, 1);
add_com_alias ("dow", down_cmd, class_stack, 1);
add_com ("down-silently", class_support, down_silently_command, _("\
Same as the `down' command, but does not print anything.\n\
This is useful in command scripts."));
add_prefix_cmd ("frame", class_stack,
&frame_cmd.base_command, _("\
cmd_list_element *frame_cmd_el
= add_prefix_cmd ("frame", class_stack,
&frame_cmd.base_command, _("\
Select and print a stack frame.\n\
With no argument, print the selected stack frame. (See also \"info frame\").\n\
A single numerical argument specifies the frame to select."),
&frame_cmd_list, 1, &cmdlist);
add_com_alias ("f", "frame", class_stack, 1);
&frame_cmd_list, 1, &cmdlist);
add_com_alias ("f", frame_cmd_el, class_stack, 1);
#define FRAME_APPLY_OPTION_HELP "\
Prints the frame location information followed by COMMAND output.\n\
@ -3498,14 +3500,14 @@ For backward compatibility, the following qualifiers are supported:\n\
With a negative COUNT, print outermost -COUNT frames."),
backtrace_opts);
cmd_list_element *c = add_com ("backtrace", class_stack,
backtrace_command,
backtrace_help.c_str ());
set_cmd_completer_handle_brkchars (c, backtrace_command_completer);
cmd_list_element *backtrace_cmd
= add_com ("backtrace", class_stack, backtrace_command,
backtrace_help.c_str ());
set_cmd_completer_handle_brkchars (backtrace_cmd, backtrace_command_completer);
add_com_alias ("bt", "backtrace", class_stack, 0);
add_com_alias ("bt", backtrace_cmd, class_stack, 0);
add_com_alias ("where", "backtrace", class_stack, 0);
add_com_alias ("where", backtrace_cmd, class_stack, 0);
add_info ("stack", backtrace_command,
_("Backtrace of the stack, or innermost COUNT frames."));
add_info_alias ("s", "stack", 1);