Is there a way to look at memory content from GDB if I know the memory location?
Namely, I'm debugging a x86 assembly program I wrote for my Operating Systems Course. Now, I'm trying to write a user level thread library for Linux on x86 with C and gas (GNU assembler). I allocated my own stacks and I made the esp register point to that memory location. Now what I want read the memory to see what is in that stack I allocated.
I would try something like the following commands (under gdb
)
p (int*)$esp
x /20x $esp
p ((int*)$esp)[3]
Use x addr
for more details take a look at https://visualgdb.com/gdbreference/commands/x
x command
Displays the memory contents at a given address using the specified format.
Syntax
x [Address expression]
x /[Format] [Address expression]
x /[Length][Format] [Address expression]
x
Parameters
Address expression
Specifies the memory address which contents will be displayed. This can be the address itself or any C/C++ expression evaluating to address. The expression can include registers (e.g. $eip) and pseudoregisters (e.g. $pc). If the address expression is not specified, the command will continue displaying memory contents from the address where the previous instance of this command has finished.
Format
If specified, allows overriding the output format used by the command. Valid format specifiers are:
o - octal
x - hexadecimal
d - decimal
u - unsigned decimal
t - binary
f - floating point
a - address
c - char
s - string
i - instruction
The following size modifiers are supported:
b - byte
h - halfword (16-bit value)
w - word (32-bit value)
g - giant word (64-bit value)
Length
Specifies the number of elements that will be displayed by this command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With