简体   繁体   English

如何编写一个表达式来干扰GDB中的指针?

[英]How do I write an expression that deference a pointer in GDB?

Suppose EAX contains a pointer to some value (doubleword). 假设EAX包含指向某个值的指针(双字)。

What I'd like to do is to examine this value, ie writing an expression like x /1wx [eax] . 我想做的是检查这个值,即写一个像x /1wx [eax]这样的表达式。

However, GDB complains when writing [eax] in expressions, saying that syntax is wrong. 但是,在表达式中编写[eax]时,GDB抱怨说语法错误。

How would I deference a pointer in GDB? 我如何在GDB中使用指针?

As the other answer noted, you can the $eax to look at that specific register. 正如另一个答案所指出的那样,你可以通过$ eax查看该特定寄存器。

(gdb) x /1wx $eax
0x400523d <main>:  0xe5894855

'info reg' will give a register dump that contains lots of useful information. 'info reg'将提供包含大量有用信息的注册转储。

You can also cast in gdb to dereference a pointer. 您还可以在gdb中强制取消引用指针。

(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. 您可以使用$ before通过常用名称引用寄存器。 For example 例如

print $rax

to print rax value, or 打印rax值,或

print *$rax

to dereference value in rax as pointer. rax值取消引用为指针。

https://sourceware.org/gdb/onlinedocs/gdb/Registers.html https://sourceware.org/gdb/onlinedocs/gdb/Registers.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM