Next: , Previous: , Up: Controlling GDB   [Contents][Index]


22.3 Command History

GDB can keep track of the commands you type during your debugging sessions, so that you can be certain of precisely what happened. Use these commands to manage the GDB command history facility.

GDB uses the GNU History library, a part of the Readline package, to provide the history facility. See Using History Interactively, for the detailed description of the History library.

To issue a command to GDB without affecting certain aspects of the state which is seen by users, prefix it with ‘server ’ (see Server Prefix). This means that this command will not affect the command history, nor will it affect GDB’s notion of which command to repeat if RET is pressed on a line by itself.

The server prefix does not affect the recording of values into the value history; to print a value without recording it into the value history, use the output command instead of the print command.

Here is the description of GDB commands related to command history.

set history filename [fname]

Set the name of the GDB command history file to fname. This is the file where GDB reads an initial command history list, and where it writes the command history from this session when it exits. You can access this list through history expansion or through the history command editing characters listed below. This file defaults to the value of the environment variable GDBHISTFILE, or to ./.gdb_history (./_gdb_history on MS-DOS) if this variable is not set.

The GDBHISTFILE environment variable is read after processing any GDB initialization files (see Startup) and after processing any commands passed using command line options (for example, -ex).

If the fname argument is not given, or if the GDBHISTFILE is the empty string then GDB will neither try to load an existing history file, nor will it try to save the history on exit.

set history save
set history save on

Record command history in a file, whose name may be specified with the set history filename command. By default, this option is disabled. The command history will be recorded when GDB exits. If set history filename is set to the empty string then history saving is disabled, even when set history save is on.

set history save off

Don’t record the command history into the file specified by set history filename when GDB exits.

set history size size
set history size unlimited

Set the number of commands which GDB keeps in its history list. This defaults to the value of the environment variable GDBHISTSIZE, or to 256 if this variable is not set. Non-numeric values of GDBHISTSIZE are ignored. If size is unlimited or if GDBHISTSIZE is either a negative number or the empty string, then the number of commands GDB keeps in the history list is unlimited.

The GDBHISTSIZE environment variable is read after processing any GDB initialization files (see Startup) and after processing any commands passed using command line options (for example, -ex).

set history remove-duplicates count
set history remove-duplicates unlimited

Control the removal of duplicate history entries in the command history list. If count is non-zero, GDB will look back at the last count history entries and remove the first entry that is a duplicate of the current entry being added to the command history list. If count is unlimited then this lookbehind is unbounded. If count is 0, then removal of duplicate history entries is disabled.

Only history entries added during the current session are considered for removal. This option is set to 0 by default.

History expansion assigns special meaning to the character !. See Event Designators, for more details.

Since ! is also the logical not operator in C, history expansion is off by default. If you decide to enable history expansion with the set history expansion on command, you may sometimes need to follow ! (when it is used as logical not, in an expression) with a space or a tab to prevent it from being expanded. The readline history facilities do not attempt substitution on the strings != and !(, even when history expansion is enabled.

The commands to control history expansion are:

set history expansion on
set history expansion

Enable history expansion. History expansion is off by default.

set history expansion off

Disable history expansion.

show history
show history filename
show history save
show history size
show history expansion

These commands display the state of the GDB history parameters. show history by itself displays all four states.

show commands

Display the last ten commands in the command history.

show commands n

Print ten commands centered on command number n.

show commands +

Print ten commands just after the commands last printed.


Next: , Previous: , Up: Controlling GDB   [Contents][Index]