How can I examine the stack frame with GDB?

GdbStack

Gdb Problem Overview


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?

Gdb Solutions


Solution 1 - Gdb

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

This will print the top 10 elements of the stack.

Solution 2 - Gdb

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

Solution 3 - Gdb

  • 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.

Solution 4 - Gdb

  • 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGetOffMyLawnView Question on Stackoverflow
Solution 1 - GdbFlowView Answer on Stackoverflow
Solution 2 - GdbMichael MrozekView Answer on Stackoverflow
Solution 3 - GdbdlanodView Answer on Stackoverflow
Solution 4 - GdbkdbrebootView Answer on Stackoverflow