如何使用 GDB 检查堆栈帧?

现在,我一直在使用 GDB 来反汇编一个二进制文件,检查不同的寄存器和诸如此类的东西。是否有一个简单的命令可以检查堆栈上的所有内容?这可以局限于函数中的所有内容吗?

134207 次浏览

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
  • bt (or backtrace) will give you a call stack.

  • frame <args> will select a frame on the call stack for inspection

  • info frame <args> will give you information about a specific frame from the stack. When called without arguments it will display the currently selected frame

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

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

This will print the top 10 elements of the stack.

  • just try bt full, and you will get all frames and locals
  • input frame x, to enter the x frame

by the way, you should know about process address space and what it is composed: linux virtual address space, this will help you understand how the frame is used.