How can I examine the stack frame with GDB?

2019-01-21 02:37发布

问题:

Right now I've been using GDB to disassemble a binary file and check out different registers and whatnot. Is there an easy command to examine everything on the stack? Can this be limited to everything in a function?

回答1:

For the current stack frame:

  • info frame lists general info about the frame (where things start in memory, etc.)
  • info args lists arguments to the function
  • info locals lists local variables stored in the frame


回答2:

You can view the contents of the stack with x/10x $sp

This will print the top 10 elements of the stack.



回答3:

  • bt (or backtrace) will give you a call stack.

  • frame <args> will give you information about a specific frame from the stack.

  • info locals can give you information about any local variables on the stack.



标签: gdb stack