How can one see content of stack with GDB?

user478571 picture user478571 · Oct 21, 2011 · Viewed 181.3k times · Source

I am new to GDB, so I have some questions:

  • How can I look at content of the stack? Example: to see content of register, I type info registers. For the stack, what should it be?

  • How can I see the content of $0x4(%esp)? When I type print /d $0x4(%esp), GDB gives an error.

Platform: Linux and GDB

Answer

DipSwitch picture DipSwitch · Oct 21, 2011

info frame to show the stack frame info

To read the memory at given addresses you should take a look at x

x/x $esp for hex x/d $esp for signed x/u $esp for unsigned etc. x uses the format syntax, you could also take a look at the current instruction via x/i $eip etc.