This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] fix debug information for bitfields


The attached patch fixes an issue with DWARF2's treatment of bitfields.
The existing field_byte_offset assumes PCC_BITFIELD_TYPE_MATTERS and so
does a fair amount of gymnastics to discover actual byte offsets of
fields by aligning bit offsets according to a field's type, etc.
However, if you're using m68k-linux (or h8300-coff or a very few other
ports), PCC_BITFIELD_TYPE_MATTERS == 0 and so type-based alignment
doesn't apply.

For a concrete example of how this patch changes things, when given the
following code:

struct bits
{
  short a : 10;
  long b : 10;
  char c;
  short d : 10;
  short e : 10;
};

mainline (and previous versions) generate the following for 'e':

 <2><9b>: Abbrev Number: 3 (DW_TAG_member)
     DW_AT_name        : e      
     DW_AT_decl_file   : 1      
     DW_AT_decl_line   : 7      
     DW_AT_type        : <ab>   
     DW_AT_byte_size   : 2      
     DW_AT_bit_size    : 10     
     DW_AT_bit_offset  : 10     
     DW_AT_data_member_location: 2 byte block: 23 4     (DW_OP_plus_uconst: 4)

whereas with the patch, we get:

 <2><9b>: Abbrev Number: 3 (DW_TAG_member)
     DW_AT_name        : e      
     DW_AT_decl_file   : 1      
     DW_AT_decl_line   : 7      
     DW_AT_type        : <ab>   
     DW_AT_byte_size   : 2      
     DW_AT_bit_size    : 10     
     DW_AT_bit_offset  : 2      
     DW_AT_data_member_location: 2 byte block: 23 5     (DW_OP_plus_uconst: 5)

The DWARF that mainline currently emits is inconsistent and causes one
commercial debugger internal heartburn.

Tested by bootstrapping a cross-compiler to m68k-linux and a native
x86_64-linux (which is a PCC_BITFIELD_TYPE_MATTERS == 1 target) compiler
and running the GCC testsuite with no regressions.  I also verified that
the patch does not change the debug output on x86_64 for the above
example.

OK to commit?

:ADDPATCH dwarf:

-Nathan

Attachment: dw2-bitfields.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]