1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

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
This commit is contained in:
Adrian Prantl 2016-05-17 20:12:08 +00:00
parent 6fa4110be7
commit bed075aa5a
3 changed files with 15 additions and 7 deletions

View File

@ -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);
}

View File

@ -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 {

View File

@ -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>