[llvm] r269827 - Debug Info: Don't emit bitfields in the DWARF4 format when tuning for GDB.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 28 12:42:52 PDT 2016


> On Jul 28, 2016, at 9:24 AM, Francois Pichet <pichet2000 at gmail.com> wrote:
> 
> 
> 
> On Tue, May 17, 2016 at 4:12 PM, Adrian Prantl via llvm-commits <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>> wrote:
> Author: adrian
> Date: Tue May 17 15:12:08 2016
> New Revision: 269827
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=269827&view=rev <http://llvm.org/viewvc/llvm-project?rev=269827&view=rev>
> Log:
> Debug Info: Don't emit bitfields in the DWARF4 format when tuning for GDB.
> As discovered in PR27758, GDB does not fully support the DWARF 4 format.
> This patch ensures we always emit bitfields in the DWARF 2 when tuning for GDB.
> 
> Modified:
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
>     llvm/trunk/test/DebugInfo/ARM/big-endian-bitfield.ll
>     llvm/trunk/test/DebugInfo/X86/bitfields-dwarf4.ll
> 
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=269827&r1=269826&r2=269827&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=269827&r1=269826&r2=269827&view=diff>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Tue May 17 15:12:08 2016
> @@ -1390,10 +1390,14 @@ void DwarfUnit::constructMemberDIE(DIE &
>      uint64_t Size = DT->getSizeInBits();
>      uint64_t FieldSize = getBaseTypeSize(DD, DT);
>      uint64_t OffsetInBytes;
> +
> +    // GDB does not fully support the DWARF 4 representation for bitfields.
> +    bool EmitDWARF2Bitfields = (DD->getDwarfVersion() < 4) || (DD->tuneForGDB());
>      bool IsBitfield = FieldSize && Size != FieldSize;
> +
>      if (IsBitfield) {
>        // Handle bitfield, assume bytes are 8 bits.
> -      if (DD->getDwarfVersion() < 4)
> +      if (EmitDWARF2Bitfields)
>          addUInt(MemberDie, dwarf::DW_AT_byte_size, None, FieldSize/8);
>        addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size);
> 
> @@ -1405,9 +1409,7 @@ void DwarfUnit::constructMemberDIE(DIE &
>        // The byte offset of the field's aligned storage unit inside the struct.
>        OffsetInBytes = (Offset - StartBitOffset) / 8;
> 
> -      if (DD->getDwarfVersion() >= 4)
> -        addUInt(MemberDie, dwarf::DW_AT_data_bit_offset, None, Offset);
> -      else {
> +      if (EmitDWARF2Bitfields) {
>          uint64_t HiMark = (Offset + FieldSize) & AlignMask;
>          uint64_t FieldOffset = (HiMark - FieldSize);
>          Offset -= FieldOffset;
> @@ -1418,17 +1420,20 @@ void DwarfUnit::constructMemberDIE(DIE &
> 
>          addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, Offset);
>          OffsetInBytes = FieldOffset >> 3;
> +      } else {
> +        addUInt(MemberDie, dwarf::DW_AT_data_bit_offset, None, Offset);
>        }
> 
> I tested this on a big endian system and it doesn't work.
> 
> The dwarf spec say that the DW_AT_data_bit_offset value must be the same for big or litttle endian. LLDB will do the appropriate calculation.

That is correct. That said, I also see that test/DebugInfo/ARM/big-endian-bitfield.ll is the exact same testcase as in the big-endian example in the DWARF (v5) specification Fig. D23.

> But at the point Offset wont have the same value on little or big endian system.

Would you mind filing a PR about this and assigning it to me? And can you give an example of where we are emitting wrong values?
I'll try to look at this soon.

thanks for reporting!
Adrian
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160728/a548c2ca/attachment.html>


More information about the llvm-commits mailing list