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?
-
3This should be of some help to you : cs.nyu.edu/courses/spring07/V22.0474-001/misc/gdb-refcard.pdf. You can always use "frame" command to jump between the frames.– dicaprioCommented May 5, 2010 at 5:58
-
The link requires login now. Here's an archived link: web.archive.org/web/20141222091304/http://cs.nyu.edu/courses/…– thyuCommented Dec 6, 2022 at 4:49
4 Answers
You can view the contents of the stack with x/10x $sp
This will print the top 10 elements of the stack.
-
What version of GDB is this? I can't get gdb to use registers as command arguments on GDB 7.7-0ubuntu3.1 Commented Nov 14, 2014 at 16:36
-
This is answer tells you how actually look at the bytes on the stack frame, which I've had some trouble finding out how to do. Thanks!– user3853034Commented Sep 12, 2017 at 11:35
-
But this will print the element pointed by
$sp
and the 9 elements after it, that is (if the stack grows downwards like for example in x86) 9 elements that are not actually used by the program yet. Right?– cYrusCommented Nov 19, 2018 at 15:26 -
@cYrus $sp points to the top of the stack, i.e. the lower address. You're probably thinking of $bp which stores the bottom address of the stack.– raphaelCommented Feb 14, 2019 at 14:56
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
-
-
1@Jeoker
info frame
is always going to tell you about the frame. If you want info about a variable you'd have to use other subcommands likeinfo locals <name>
, or other commands entirely likeprint
Commented May 25, 2021 at 3:05
bt
(orbacktrace
) will give you a call stack.frame <args>
will select a frame on the call stack for inspectioninfo frame <args>
will give you information about a specific frame from the stack. When called without arguments it will display the currently selected frameinfo locals
can give you information about any local variables on the stack.
-
2frame <args> also selects a frame.
info frame <addr>
is used to examine the frame without selecting it Commented May 17, 2018 at 7:32
- 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.
-
Hello and welcome to SO! Please read the tour, and How do I write a good answer? For example adding a link to what is process address space and elaborate how it can help to solve this question might be helpful. Commented Jan 11, 2021 at 11:06