I'm using gdb and libbfd to retrieve global variables information from an elf file and show it. I can get the following data from libbfd: Global Variable name, address and size. I retrieve the type of the variables and its children using gdb and gdb\MI (ptype, whatis, -var-create & -var-list-children).
How can I get the address\size\offset from parent of all the children?
e.g
type = struct {\n"
unsigned char count;\n"
unsigned char time;\n
}\n
If a variable A of this type is in address 0x000100, I want to show that A.count is in 0x000100 with size 0x1 and A.time is in 0x000101 with size 0x1.
EDIT: I've read that gdb can read the DWARF info, but I can't figure out how can I get this information from gdb.
Here's what I did eventually. To get the size, I used:
p sizeof(A.time)
and to get the address I used:
p /a &A.time
NOTE: This only applies for variable of a size bigger then 1 byte. To be able to get bitfields size and offset in bits, I had to recompile GDB according to the suggestion offered in nabble: Address of bitfield element bug?