How to See the Call Stack in GDB
- 1). Start "gdb" for the program you wish to see the call stack of. For example, to start debugging the program "example," you would type the following into the Linux command prompt:
gdb example - 2). Run a backtrace on the program. This displays a list of active function calls in the program thread. This is the call stack, but there is more you can do than just view it. Type the following to initiate the backtrace:
backtrace - 3). Observe the list of active function calls. Each one is preceded by the pound sign "#" and a number. You can access their stack frames through this number.
- 4). Observe the stack frame of an active function call. For example, to view the stack frame for function call 3, write the following:
frame 3 - 5). List all the information contained in this frame. This gives you information about the subroutine, which may help you debug your program.
Source...