You can customize your gdb(1) environment in two ways:
If they exist, gdb reads two files when it starts up: .gdbinit from your home directory and .gdbinit from the current directory. Both files have command-line options. Subsequent options take precedence over earlier options. With this arrangement, commands in your home directory startup file can affect the processing of options, and commands in the current directory startup file can be specific to the local directory.
If you use the -nx or -n option, the initialization files are not read.
In a command file, such as on of the startup files, any line beginning with a number-sign character (#) is ignored as a comment. All other lines are gdb commands.
You can specify other command files with the -x option. Since options are processed in the order in which they appear, a command specified with an -x can be counteracted by a subsequent command in the same file or in a called file (a file specified with the -x option).
You can change the gdb prompt from (gdb) to one of your choosing. The command is set prompt string where string is the new gdb prompt.
You can define your own commands in gdb with the define command. A user-defined command is a named sequence of gdb commands. When used in a user-defined command, most gdb commands do not ask for confirmation, and most do not display status messages. The print command, however, still prints.
The following table describes the basic syntax for creating user-defined commands. Although user-defined commands are not too sophisticated (they are essentially macros), they can include conditional statements (if) and control loops (while). You can also create text-based help files for your commands.
Command | Description |
---|---|
|
Creates a user-defined command with the name cmd_name. The body of the command consists of commands, one to a line. The user-defined command ends with the end command. |
|
Creates a conditional statement. If the condition is true, it executes the first set of commands, one to a line. If the condition does not evaluate to true, the second set of commands (if present) is executed. |
|
Creates a control loop. While the condition is true, executes the commands, one to a line. |
|
Used for creating help files. Stores the description as help information for the user-defined command. The first line of the description is displayed when you enter the command help user-defined [cmd_name]. Before you can use the document command, you must have already defined the command with the define command. |
|
Displays the first line of the description of the user-defined command called cmd_name, or, if no command name is specified, displays the first line for all user-defined commands. You can display the entire help text for cmd_name by typing the command help. cmd_name. |
|
Displays help information for cmd_name. If cmd_name is a user-defined command, it must have already been documented with the document command. |
|
Shows the definitions for the user-defined cmd_name. If no cmd_name is specified, displays the definitions for all of the user-defined commands. |