summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2016-05-17 20:12:08 +0000
committerAdrian Prantl <aprantl@apple.com>2016-05-17 20:12:08 +0000
commitf0a41089ff2a580ad6665f62e8198b5efaa1ede2 (patch)
treeb1c1f1a62d481f8840bb63c29839fa0d703a3f1f
parent18b61707e86ea69e5014adcbfbfaf7a12903722d (diff)
downloadbcm5719-llvm-f0a41089ff2a580ad6665f62e8198b5efaa1ede2.tar.gz
bcm5719-llvm-f0a41089ff2a580ad6665f62e8198b5efaa1ede2.zip
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. llvm-svn: 269827
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp17
-rw-r--r--llvm/test/DebugInfo/ARM/big-endian-bitfield.ll2
-rw-r--r--llvm/test/DebugInfo/X86/bitfields-dwarf4.ll3
3 files changed, 15 insertions, 7 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index f8c3f489ca4..ec4e8e1106f 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1390,10 +1390,14 @@ void DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
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 &Buffer, const DIDerivedType *DT) {
// 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 &Buffer, const DIDerivedType *DT) {
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);
}
diff --git a/llvm/test/DebugInfo/ARM/big-endian-bitfield.ll b/llvm/test/DebugInfo/ARM/big-endian-bitfield.ll
index ba89b1414bf..0153e99a3ff 100644
--- a/llvm/test/DebugInfo/ARM/big-endian-bitfield.ll
+++ b/llvm/test/DebugInfo/ARM/big-endian-bitfield.ll
@@ -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 {
diff --git a/llvm/test/DebugInfo/X86/bitfields-dwarf4.ll b/llvm/test/DebugInfo/X86/bitfields-dwarf4.ll
index cefe61663d4..5275fc64554 100644
--- a/llvm/test/DebugInfo/X86/bitfields-dwarf4.ll
+++ b/llvm/test/DebugInfo/X86/bitfields-dwarf4.ll
@@ -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>
OpenPOWER on IntegriCloud