Debugging with GDB (September 2007)
Chapter 6: Examining the Stack 53
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.
#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
at builtin.c:993
#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
at macro.c:71
(More stack frames follow...)
The display for frame zero does not begin with a program counter value, indicating that
your program has stopp ed at the beginning of the code for line 993 of builtin.c.
6.5 Selecting a frame
Most commands for examining the stack and other data in your program work on
whichever stack frame is selected at the moment.
The following commands are used for selecting a stack frame; all of them finish by
printing a brief description of the stack frame selec ted.
frame n
f n Select frame number n. Recall that frame zero is the innermost (currently
executing) frame, frame one is the frame that called the innermost one, and so
on. The highest-numbered frame is the one for main.
frame addr
f addr
Select the frame at address addr. This is useful mainly if the chaining of stack
frames has been damaged by a bug, making it impossible for GDB to assign
numb e rs properly to all frames. In addition, this can be useful when your
program has multiple stacks and switches between them.
Note:
• On the SPARC architecture, frame needs two addresses to select an arbi-
trary frame: a frame pointer and a stack pointer.
• On the MIPS and Alpha architecture, it nee ds two addresses: a stack
pointer and a program counter.
• On the 29k architecture, it needs three addresses: a register stack pointer,
a program counter, and a memory stack pointer.
up n Move n frames up the stack. For positive numbers n, this advances toward the
outermost frame, to higher frame numbers, to frames that have existed longer.
n defaults to one.
down n Move n frames down the stack. For positive numbers n, this advances toward
the innermost frame, to lower frame numbers, to frames that were created more
recently. n defaults to one. You may abbreviate down as do.