[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
Tue May 17 13:55:46 PDT 2016


> On May 17, 2016, at 1:54 PM, Robinson, Paul <paul.robinson at sony.com> wrote:
> 
> 
> 
>> -----Original Message-----
>> From: llvm-commits [mailto:llvm-commits-bounces at lists.llvm.org] On Behalf
>> Of Adrian Prantl via llvm-commits
>> Sent: Tuesday, May 17, 2016 1:12 PM
>> To: llvm-commits at lists.llvm.org
>> Subject: [llvm] r269827 - Debug Info: Don't emit bitfields in the DWARF4
>> format when tuning for GDB.
>> 
>> Author: adrian
>> Date: Tue May 17 15:12:08 2016
>> New Revision: 269827
>> 
>> URL: 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=2698
>> 26&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());
> 
> Up to now, all tuneForXXX() queries have been in the DwarfDebug ctor
> and a flag like EmitDWARF2Bitfields would have been a DwarfDebug bool.
> The idea was that tuning should unpack into other flags, and we would
> not have a proliferating set of tuning checks all over everywhere.
> Would you mind making EmitDWARF2Bitfields work this way?

Will do so right away.
> 
> Probably I should have made the tuneForXXX() methods private, to
> reinforce the principle.

Sounds like a good idea to do this (as soon as I landed my change).

-- adrian

> Thanks,
> --paulr
> 
>>     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);
>>       }
>> -    } else
>> +    } else {
>>       // This is not a bitfield.
>>       OffsetInBytes = DT->getOffsetInBits() / 8;
>> +    }
>> 
>>     if (DD->getDwarfVersion() <= 2) {
>>       DIELoc *MemLocationDie = new (DIEValueAllocator) DIELoc;
>>       addUInt(*MemLocationDie, dwarf::DW_FORM_data1,
>> dwarf::DW_OP_plus_uconst);
>>       addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
>>       addBlock(MemberDie, dwarf::DW_AT_data_member_location,
>> MemLocationDie);
>> -    } else if (!IsBitfield || DD->getDwarfVersion() < 4)
>> +    } else if (!IsBitfield || EmitDWARF2Bitfields)
>>       addUInt(MemberDie, dwarf::DW_AT_data_member_location, None,
>>               OffsetInBytes);
>>   }
>> 
>> Modified: llvm/trunk/test/DebugInfo/ARM/big-endian-bitfield.ll
>> URL: http://llvm.org/viewvc/llvm-
>> project/llvm/trunk/test/DebugInfo/ARM/big-endian-
>> bitfield.ll?rev=269827&r1=269826&r2=269827&view=diff
>> ==========================================================================
>> ====
>> --- llvm/trunk/test/DebugInfo/ARM/big-endian-bitfield.ll (original)
>> +++ llvm/trunk/test/DebugInfo/ARM/big-endian-bitfield.ll Tue May 17
>> 15:12:08 2016
>> @@ -1,4 +1,4 @@
>> -; RUN: llc -O0 -filetype=obj -mtriple=armeb-none-linux %s -o - \
>> +; RUN: llc -O0 -filetype=obj -mtriple=armeb-none-freebsd -debugger-
>> tune=lldb %s -o - \
>> ; RUN: | llvm-dwarfdump --debug-dump=info - | FileCheck %s
>> ; Generated from:
>> ;   struct S {
>> 
>> Modified: llvm/trunk/test/DebugInfo/X86/bitfields-dwarf4.ll
>> URL: http://llvm.org/viewvc/llvm-
>> project/llvm/trunk/test/DebugInfo/X86/bitfields-
>> dwarf4.ll?rev=269827&r1=269826&r2=269827&view=diff
>> ==========================================================================
>> ====
>> --- llvm/trunk/test/DebugInfo/X86/bitfields-dwarf4.ll (original)
>> +++ llvm/trunk/test/DebugInfo/X86/bitfields-dwarf4.ll Tue May 17 15:12:08
>> 2016
>> @@ -1,5 +1,8 @@
>> ; RUN: llc -mtriple x86_64-apple-macosx -O0 -filetype=obj -o - %s \
>> ; RUN: | llvm-dwarfdump -debug-dump=info - | FileCheck %s
>> +; RUN: llc -mtriple x86_64-gnu-linux -O0 -filetype=obj -o - %s \
>> +; RUN: | llvm-dwarfdump -debug-dump=info - | FileCheck %s --check-
>> prefix=LINUX
>> +; LINUX-NOT: DW_AT_data_bit_offset
>> ;
>> ; Generated from:
>> ;   #include <stdint.h>
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list