Go to the previous, next section.

User-defined commands

A user-defined command is a sequence of GDB commands to which you assign a new name as a command. This is done with the define command.

define commandname
Define a command named commandname. If there is already a command by that name, you are asked to confirm that you want to redefine it.

The definition of the command is made up of other GDB command lines, which are given following the define command. The end of these commands is marked by a line containing end.

document commandname
Give documentation to the user-defined command commandname. The command commandname must already be defined. This command reads lines of documentation just as define reads the lines of the command definition, ending with end. After the document command is finished, help on command commandname displays the documentation you have specified.

You may use the document command again to change the documentation of a command. Redefining the command with define does not change the documentation.

help user-defined
List all user-defined commands, with the first line of the documentation (if any) for each.

show user
show user commandname
Display the GDB commands used to define commandname (but not its documentation). If no commandname is given, display the definitions for all user-defined commands.

User-defined commands do not take arguments. When they are executed, the commands of the definition are not printed. An error in any command stops execution of the user-defined command.

Commands that would ask for confirmation if used interactively proceed without asking when used inside a user-defined command. Many GDB commands that normally print messages to say what they are doing omit the messages when used in a user-defined command.

Go to the previous, next section.