- Once we got into a break-point and examined some variables, we might also wish to see "where we are".
- That is, what function is being executed now, which function called it, and so on. This can be done using the where command. At the gdb command prompt, just type "where", and you'll see something like this:
#0 main (argc=3, argv=0xbffff054) at debugme.c:16
This means the currently executing function is "main", at file "debugme.c", line 23.
- We also see which arguments each function had received. If there were more functions in the call chain, we'd see them listed in order. This list is also called "a stack trace", since it shows us the structure of the execution stack at this point in the program's life.
- Just as we can see contents of variables in the current function, we can see contents of variables local to the calling function, or to any other function on the stack. For example, if we want to see the contents of variable "i" in function "main", we can type the following two commands:
(gdb) frame 1
(gdb) print i
The "frame" command tells the debugger to switch to the given stack frame ('0' is the frame of the currently executing function). At that stage, any print command invoked will use the context of that stack frame.
- Of-course, if we issue a "step" or "next" command, the program will continue at the top frame, not at the frame we requested to see.
- After all, the debugger cannot "undo" all the calls and continue from there.
Cem Ozdogan
2011-02-14