From 31d20380ccb4abbc2188553144a5f068dbbfefcc Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Fri, 7 Dec 2007 14:12:35 -0200 Subject: [PATCH] [DWARVES]: Print the bit offset too Helps understanding how bitfields really work, and after all it is just confusing, not wrong. See this one: struct usb_bus { struct device * controller; /* 0 8 */ int busnum; /* 8 4 */ /* XXX 4 bytes hole, try to pack */ char * bus_name; /* 16 8 */ u8 uses_dma; /* 24 1 */ u8 otg_port; /* 25 1 */ /* WARNING: DWARF offset=24, real offset=26 */ unsigned int is_b_host:1; /* 24:15 4 */ unsigned int b_hnp_enable:1; /* 24:14 4 */ /* XXX 30 bits hole, try to pack */ int devnum_next; /* 28 4 */ }; So the bitfield _really_ is at offset 24 and the "WARNING:" above is just pahole not understanding how it works, i.e. it starts at 24 and since the bitfield has a 'unsigned int' as its base type it goes from 24 to 27, the offsets start at the end, i.e. from byte 27 back to byte 27, but as only two bits are used, it puts bit padding at the end, at bit offset 0, that is the last bit in byte 27 and uses the first bits of byte 26 at bit offset 14 and 15. Now to make libdwarves finally understand this convention. Signed-off-by: Arnaldo Carvalho de Melo --- dwarves.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dwarves.c b/dwarves.c index 44cfbbc..958b99d 100644 --- a/dwarves.c +++ b/dwarves.c @@ -1478,10 +1478,20 @@ static size_t struct_member__fprintf(struct class_member *self, printed += p; spacing -= p; } - if (!sconf.suppress_offset_comment) - printed += fprintf(fp, "%*s/* %5u %5u */", + if (!sconf.suppress_offset_comment) { + size_t size_spacing = 5; + + printed += fprintf(fp, "%*s/* %5u", spacing > 0 ? spacing : 0, " ", - offset, size); + offset); + + if (self->bit_size != 0) { + printed += fprintf(fp, ":%2d", self->bit_offset); + size_spacing -= 3; + } + + printed += fprintf(fp, " %*u */", size_spacing, size); + } } return printed; }