Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 36375ee

Browse files
author
Devang Patel
committed
Emit debug info for bitfields.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64815 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f163a95 commit 36375ee

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

include/llvm/Analysis/DebugInfo.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ namespace llvm {
118118
/// code generator accepts maximum one main compile unit per module. If a
119119
/// module does not contain any main compile unit then the code generator
120120
/// will emit multiple compile units in the output object file.
121-
bool isMain() const { return getUnsignedField(6); }
122-
bool isOptimized() const { return getUnsignedField(7); }
123-
std::string getFlags() const { return getStringField(8); }
121+
bool isMain() const { return getUnsignedField(6); }
122+
bool isOptimized() const { return getUnsignedField(7); }
123+
std::string getFlags() const { return getStringField(8); }
124124

125125
/// Verify - Verify that a compile unit is well formed.
126126
bool Verify() const;
@@ -217,6 +217,9 @@ namespace llvm {
217217
explicit DIDerivedType(GlobalVariable *GV);
218218
DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
219219

220+
/// getOriginalTypeSize - If this type is derived from a base type then
221+
/// return base type size.
222+
uint64_t getOriginalTypeSize() const;
220223
/// dump - print derived type.
221224
void dump() const;
222225
};

lib/Analysis/DebugInfo.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ bool DIVariable::isVariable(unsigned Tag) {
169169
}
170170
}
171171

172-
DIVariable::DIVariable(GlobalVariable *GV) : DIDescriptor(GV) {
173-
if (GV && !isVariable(getTag()))
172+
DIVariable::DIVariable(GlobalVariable *gv) : DIDescriptor(gv) {
173+
if (gv && !isVariable(getTag()))
174174
GV = 0;
175175
}
176176

@@ -273,7 +273,16 @@ bool DIVariable::Verify() const {
273273
return true;
274274
}
275275

276-
276+
/// getOriginalTypeSize - If this type is derived from a base type then
277+
/// return base type size.
278+
uint64_t DIDerivedType::getOriginalTypeSize() const {
279+
if (getTag() != dwarf::DW_TAG_member)
280+
return getSizeInBits();
281+
DIType BT = getTypeDerivedFrom();
282+
if (BT.getTag() != dwarf::DW_TAG_base_type)
283+
return getSizeInBits();
284+
return BT.getSizeInBits();
285+
}
277286

278287
//===----------------------------------------------------------------------===//
279288
// DIFactory: Basic Helpers

lib/CodeGen/AsmPrinter/DwarfWriter.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,24 @@ class DwarfDebug : public Dwarf {
18731873

18741874
AddSourceLine(MemberDie, &DT);
18751875

1876-
// FIXME _ Handle bitfields
1876+
uint64_t Size = DT.getSizeInBits();
1877+
uint64_t FieldSize = DT.getOriginalTypeSize();
1878+
1879+
if (Size != FieldSize) {
1880+
// Handle bitfield.
1881+
AddUInt(MemberDie, DW_AT_byte_size, 0, DT.getOriginalTypeSize() >> 3);
1882+
AddUInt(MemberDie, DW_AT_bit_size, 0, DT.getSizeInBits());
1883+
1884+
uint64_t Offset = DT.getOffsetInBits();
1885+
uint64_t FieldOffset = Offset;
1886+
uint64_t AlignMask = ~(DT.getAlignInBits() - 1);
1887+
uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1888+
FieldOffset = (HiMark - FieldSize);
1889+
Offset -= FieldOffset;
1890+
// Maybe we need to work from the other end.
1891+
if (TD->isLittleEndian()) Offset = FieldSize - (Offset + Size);
1892+
AddUInt(MemberDie, DW_AT_bit_offset, 0, Offset);
1893+
}
18771894
DIEBlock *Block = new DIEBlock();
18781895
AddUInt(Block, 0, DW_FORM_data1, DW_OP_plus_uconst);
18791896
AddUInt(Block, 0, DW_FORM_udata, DT.getOffsetInBits() >> 3);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Check bitfields.
2+
// RUN: %llvmgcc -S -O0 -g %s -o - | llvm-as | \
3+
// RUN: llc --disable-fp-elim -o 2009-02-17-BitField-dbg.s -f
4+
// RUN: %compile_c 2009-02-17-BitField-dbg.s -o 2009-02-17-BitField-dbg.o
5+
// RUN: echo {ptype mystruct} > %t2
6+
// RUN: gdb -q -batch -n -x %t2 2009-02-17-BitField-dbg.o | \
7+
// RUN: tee 2009-02-17-BitField-dbg.out | grep "int a : 4"
8+
9+
struct {
10+
int a:4;
11+
int b:2;
12+
} mystruct;
13+

0 commit comments

Comments
 (0)