AsmPrinter: Don't emit empty .debug_loc entries

If we don't know how to represent a .debug_loc entry, skip the entry
entirely rather than emitting an empty one.  Similarly, if a .debug_loc
list has no entries, don't create the list.

We still want to create the variables, just in an optimized-out form
that doesn't have a DW_AT_location.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240244 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-06-21 16:54:56 +00:00
parent 01a8dc8ca6
commit f1c527b5c1
6 changed files with 188 additions and 14 deletions

View File

@@ -908,15 +908,15 @@ void DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU,
const MachineInstr *MInsn = Ranges.front().first;
assert(MInsn->isDebugValue() && "History must begin with debug value");
RegVar->initializeDbgValue(MInsn);
// Check if the first DBG_VALUE is valid for the rest of the function.
if (Ranges.size() == 1 && Ranges.front().second == nullptr)
if (Ranges.size() == 1 && Ranges.front().second == nullptr) {
RegVar->initializeDbgValue(MInsn);
continue;
}
// Handle multiple DBG_VALUE instructions describing one variable.
RegVar->setDebugLocListIndex(
DebugLocs.startList(&TheCU, Asm->createTempSymbol("debug_loc")));
DebugLocStream::ListBuilder List(DebugLocs, TheCU, *Asm, *RegVar, *MInsn);
// Build the location list for this variable.
SmallVector<DebugLocEntry, 8> Entries;
@@ -930,7 +930,7 @@ void DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU,
// Finalize the entry by lowering it into a DWARF bytestream.
for (auto &Entry : Entries)
Entry.finalize(*Asm, DebugLocs, BT);
Entry.finalize(*Asm, List, BT);
}
// Collect info for variables that were optimized out.
@@ -1504,10 +1504,11 @@ static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
// FIXME: ^
}
void DebugLocEntry::finalize(const AsmPrinter &AP, DebugLocStream &Locs,
void DebugLocEntry::finalize(const AsmPrinter &AP,
DebugLocStream::ListBuilder &List,
const DIBasicType *BT) {
Locs.startEntry(Begin, End);
BufferByteStreamer Streamer = Locs.getStreamer();
DebugLocStream::EntryBuilder Entry(List, Begin, End);
BufferByteStreamer Streamer = Entry.getStreamer();
const DebugLocEntry::Value &Value = Values[0];
if (Value.isBitPiece()) {
// Emit all pieces that belong to the same variable and range.