Let's say I have a type MyStruct. I would like to check if 40 bytes from the structs start, there is a pointer. If there is, I would like to get the type of that pointer. Is there a way to do that ?
I have debug symbols. In GDB I could try to use ptype /o but I want to do this quickly and I don't want all the other struct info and I would like the pointer type in a reusable format to then plug in.
gdb.lookup_type
with your type name (gdb.lookup_type('MyStruct')
), then call.fields()
on the result. This'll give you a list of the fields, which then allows you to use the ".bitpos" and ".bitsize" properties of each one to locate the one overlapping the (40) bytes that you want (in bits, so divide by 8). Once you have a field, use.is_scalar
to confirm it's not an array, and then.target
to get its type (it'll raise an exception if not a pointer). Docs are at sourceware.org/gdb/current/onlinedocs/gdb.html/….