As noted in Section 2.2, GDB's command
handling is extensible. Commands are grouped into a number of command
lists (of type struct cmd_list_element),
pointed to by a number of global variables (defined in
cli-cmds.h
). Of these, cmdlist
is the list of all defined commands, with separate lists defined for
sub-commands of various top level commands. For example
infolist
is the list of all info
sub-commands.
Each command (or sub-command) is associated with a callback function which implements the behavior of the functions. There are additional requirements for functions which set or show values within GDB. Each function also takes a documentation string (used by the help command). Functions for adding commands all return a pointer to the struct cmd_list_element for the command added (which is not necessarily the head of its command list). The most useful functions are:
add_cmd
. Add a function to a command list.
add_com
. Add a function to the main command
list, cmdlist
. This is a convenience wrapper
for add_cmd
.
add_prefix_cmd
. Add a new prefix
command. This command should have its own function for use if it
is called on its own, and a global command list pointer specific
to the prefix command to which all its sub-commands will be
added. If a prefix command is called with an unknown sub-command,
it can either give an error or call the function of the prefix
command itself. Which of these is used is specified by a flag in
the call to add_prefix_cmd
.
add_alias_cmd
. Add an alias for a command
already defined.
add_info
. Add a sub-command to the
info. A convenience wrapper for
add_cmd
.
New commands are usually added in the
_initialize_arch
function after the struct gdbarch
has been defined.