I have an user defined struct.
struct foo {
int bar1;
char *name;
user_type_t *tba;
}foo_t;
While in gdb, I have an address that points to type foo_t. e.g 0xfe83ba56 points to a structure in the memory that is of type foo_t.
I can convert that address to foo_t by type casting, and then I can dereference it if needed. (gdb) p (foo_t *)0xfe83ba56
How do to the same with python inside gdb? If I have a gdb.Value object which already points to an object of type foo_t, then I can its address. but here, I'm trying to convert a raw address into a gdb.Value object.
I looked into https://sourceware.org/gdb/onlinedocs/gdb/Values-From-Inferior.html#Values-From-Inferior and lot of posts from the 'similar questions' section of SO, but couldn't find the exact answer.
To cast, use the Value.cast
method. Something like:
t = gdb.lookup_type('foo_t').pointer()
value = value.cast(t)
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