I am trying to explore datatypes' memory layout using GDB-Python Type API (gdb.types). Specifically, I would like to find a way to get the absolute Offsets of all members of a nested struct which is defined inside a parent struct.
In C, I have defined:
typedef struct
{
int a;
short bf1:2;
char b:4;
struct //nested struct
{
long x;
long y;
};
} a_struct;
Using ptype command in gdb, I get:
(gdb) ptype /o a_struct
/* offset | size */ type = struct a_struct {
/* 0 | 4 */ int a;
/* 4:14 | 2 */ short bf1 : 2;
/* 4: 2 | 1 */ char b : 4;
/* XXX 2-bit hole */
/* XXX 3-byte hole */
/* 8 | 16 */ struct {
/* 8 | 8 */ long x;
/* 16 | 8 */ long y;
/* total size (bytes): 16 */
};
/* total size (bytes): 24 */
}
The above output shows the offsets of the fields of the nested anonymous struct as absolute values from the beginning of the parent struct, that is x is at byte 8 and y at byte 16.
I am trying to get the same results using the GDB Python Type API but without success. In particular, I am using gdb.types.deep_items(lookup_type) method which returns the relative offsets of the fields of the nested struct, that is 0 for the first field (x) and 8 for the second field (y).
Is there any way to get 8 for x and 16 for y (as ptype output shows) using the GDB Python API?
Thank you