3. How do I use the call stack?
The call stack is where we find the stack frames that control program flow. When a function is called, it creates a stack frame that tells the computer how to return control to its caller after it has finished executing. Stack frames are also where local variables and function arguments are 'stored'. We can look at these stack frames to determine how our program is running. Finding the list of stack frames below the current frame is called a backtrace.
How do I ...?
Use the gdb command backtrace. In the backtrace below, we can
see that we are currently inside
Use the gdb command frame. Notice in the backtrace above that each frame has a number beside it. Pass the number of the frame you want as an argument to the command.
To look at the contents of the current frame, there are 3 useful gdb commands. info frame displays information about the current stack frame. info locals displays the list of local variables and their values for the current stack frame, and info args displays the list of arguments.
[contents] [usage] [execution] [stack] [breakpoints] [watchpoints] [advanced]
Questions? Comments? Flames? email email@example.com