It is often useful to define alternate spellings of existing commands. For example, if a new GDB command defined in Python has a long name to type, it is handy to have an abbreviated version of it that involves less typing.
GDB itself uses aliases. For example ‘
s’ is an alias
of the ‘
step’ command even though it is otherwise an ambiguous
abbreviation of other commands like ‘
set’ and ‘
Aliases are also used to provide shortened or more common versions
of multi-word commands. For example, GDB provides the
tty’ alias of the ‘
set inferior-tty’ command.
You can define a new alias with the ‘
alias [-a] [--] ALIAS = COMMAND [DEFAULT-ARGS...]
ALIAS specifies the name of the new alias.
Each word of
ALIAS must consist of letters, numbers, dashes and
COMMAND specifies the name of an existing command
that is being aliased.
COMMAND can also be the name of an existing alias. In this case,
COMMAND cannot be an alias that has default arguments.
-a’ option specifies that the new alias is an abbreviation
of the command. Abbreviations are not used in command completion.
--’ option specifies the end of options,
and is useful when
ALIAS begins with a dash.
You can specify
default-args for your alias.
default-args will be automatically added before the alias
arguments typed explicitly on the command line.
For example, the below defines an alias
btfullall that shows all local
variables and all frame arguments:
(gdb) alias btfullall = backtrace -full -frame-arguments all
For more information about
default-args, see Automatically prepend default arguments to user-defined aliases.
Here is a simple example showing how to make an abbreviation
of a command so that there is less to type.
Suppose you were tired of typing ‘
disas’, the current
shortest unambiguous abbreviation of the ‘
and you wanted an even shorter version named ‘
The following will accomplish this.
(gdb) alias -a di = disas
Note that aliases are different from user-defined commands.
With a user-defined command, you also need to write documentation
for it with the ‘
An alias automatically picks up the documentation of the existing command.
Here is an example where we make ‘
elms’ an abbreviation of
elements’ in the ‘
set print elements’ command.
This is to show that you can make an abbreviation of any part
of a command.
(gdb) alias -a set print elms = set print elements (gdb) alias -a show print elms = show print elements (gdb) set p elms 20 (gdb) show p elms Limit on string chars or array elements to print is 200.
Note that if you are defining an alias of a ‘
and you want to have an alias for the corresponding ‘
command, then you need to define the latter separately.
Unambiguously abbreviated commands are allowed in
ALIAS, just as they are normally.
(gdb) alias -a set pr elms = set p ele
Finally, here is an example showing the creation of a one word
alias for a more complex command.
This creates alias ‘
spe’ of the command ‘
set print elements’.
(gdb) alias spe = set print elements (gdb) spe 20