Aliases allow you to define alternate spellings for existing commands. For example, if a new GDB command defined in Python (see Python) has a long name, 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 ‘show’.
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’ command.
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 underscores.
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.
The ‘-a’ option specifies that the new alias is an abbreviation of the command. Abbreviations are not used in command completion.
The ‘--’ option specifies the end of options, and is useful when alias begins with a dash.
You can specify default-args for your alias. These 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 Default Arguments.
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 ‘disassemble’ command and you wanted an even shorter version named ‘di’. 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 ‘document’ command. 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 200 (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 ‘set’ command, and you want to have an alias for the corresponding ‘show’ command, then you need to define the latter separately.
Unambiguously abbreviated commands are allowed in command and 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
|• Command aliases default args:||Default arguments for aliases|