我有一个用户定义的结构。
struct foo {
int bar1;
char *name;
user_type_t *tba;
}foo_t;
Run Code Online (Sandbox Code Playgroud)
在 gdb 中,我有一个指向 foo_t 类型的地址。例如0xfe83ba56指向内存中类型为foo_t的结构。
我可以通过类型转换将该地址转换为 foo_t,然后在需要时可以取消引用它。(gdb) p (foo_t *)0xfe83ba56
如何在 gdb 中使用 python 进行同样的操作?如果我有一个 gdb.Value 对象,它已经指向 foo_t 类型的对象,那么我可以得到它的地址。但在这里,我试图将原始地址转换为 gdb.Value 对象。
我查看了https://sourceware.org/gdb/onlinedocs/gdb/Values-From-Inferior.html#Values-From-Inferior以及SO“类似问题”部分的很多帖子,但找不到确切的答案。
要进行投射,请使用该Value.cast
方法。就像是:
t = gdb.lookup_type('foo_t').pointer()
value = value.cast(t)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2707 次 |
最近记录: |