12.2. Backtraces

A backtrace is a summary of how your program got where it is. It shows one line per frame, for many frames, starting with the currently executing frame (frame zero), followed by its caller (frame one), and on up the stack.

backtrace, bt

Print a backtrace of the entire stack: one line per frame for all frames in the stack.

You can stop the backtrace at any time by typing the system interrupt character, normally Ctrl-C.

backtrace n, bt n

Similar, but print only the innermost n frames.

backtrace -n, bt -n

Similar, but print only the outermost n frames.

The names where and info stack (abbreviated info s) are additional aliases for backtrace.

Each line in the backtrace shows the frame number and the function name. The program counter value is also shown — unless you use set print address off. The backtrace also shows the source file name and line number, as well as the arguments to the function. The program counter value is omitted if it is at the beginning of the code for that line number.

Here is an example of a backtrace. It was made with the command bt 3, so it shows the innermost three frames.

(gdb) bt 3
#0  log10 (x=0.75) at whetstone.c:226
#1  0x1039a in log (..) at whetstone.c:259
#2  0x108cc in main (..) at whetstone.c:470
(gdb)

The display for frame zero does not begin with a program counter value, indicating that your program has stopped at the beginning of the code for line 226 of whetstone.c.