Previous: Python, Up: Extending GDB


23.3 Creating new spellings of existing commands

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 `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

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.

The `-a' option specifies that the new alias is an abbreviation of the command. Abbreviations are not shown in command lists displayed by the `help' command.

The `--' option specifies the end of options, and is useful when ALIAS begins with a dash.

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 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 `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