Displaying information

The gdb(1) debugger displays information about the process being debugged, about the environment, and about gdb itself.

The help command displays information about gdb commands.

Variables in gdb

The gdb debugger uses three types of variables: program variables, convenience variables, and register variables. You can use the print command to display the value of a variable.

Program variables

Program variables are variables that are set and used from within the program that is currently being debugged. You can display information about these variables with the commands whatis and ptype, both of which describe the variable type.

Convenience variables

Convenience variables are variables that are defined in gdb to help in debugging. All convenience variables have names starting with a dollar sign ($). Predefined convenience variables and macros are described in the following table.
Convenience variables and macros Description
$_ The last examined address.
$_ _ The value found in the last examined address.
$cwd The current working directory (macro).
$cdir The source directory determined from the object file (macro).
$ The value printed in the last print command.
$$ The value printed in the second-to-last print command.
$bpnum The number of the last break-point set.

Register variables

Register variables are a special class of convenience variable that shows the contents of the system registers. The names of the register variables vary according to the computer platform. The Interix port of gdb includes the following register variables:
Register variable Description
$fp Frame pointer
$pc Program counter
$ps Processor status
$sp Stack pointer

In gdb, objects other than variables can use the dollar sign ($) prefix. Usually they are run-time macros. For example, the entries in the command history use this notation, as do the macros $cwd (current working directory) and $cdir (C source directory).

You can set the value of a variable with either set or print. The print command sets the value of a variable as a byproduct of its evaluation an expression. The set command sets the value of the variable but does not echo the value of the variable to the screen.

The set command also includes a number of subcommands, including args, print, verbose, and write. If you set a program variable whose name is identical to a set subcommand name, you can explicitly name the variable by using the command set variable varname [=value].

The call stack

You can display the call stack with the backtrace command. The commands bt and where are equivalent to backtrace. You can see abbreviated information about your current frame with the frame command.