Suppose EAX contains a pointer to some value (doubleword).
What I'd like to do is to examine this value, i.e. writing an expression like x /1wx [eax].
However, GDB complains when writing [eax] in expressions, saying that syntax is wrong.
How would I deference a pointer in GDB?
As the other answer noted, you can the $eax to look at that specific register.
(gdb) x /1wx $eax
0x400523d <main>: 0xe5894855
'info reg' will give a register dump that contains lots of useful information.
You can also cast in gdb to dereference a pointer.
(gdb) print /x *(int*)0x400523d
$3 = 0xe5894855
I use this method often while debugging. It is useful when digging inside a complex class/structure for pointers. Following a chain of pointers is often simplified but just grabbing the address and looking at the dereference.
You can refer to registers by common names using $ before. For example
print $rax
to print rax value, or
print *$rax
to dereference value in rax as pointer.
https://sourceware.org/gdb/onlinedocs/gdb/Registers.html
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