Skip to content

Commit

Permalink
DebugInfo: Generalize rnglist emission as a precursor to reusing it f…
Browse files Browse the repository at this point in the history
…or loclist emission

llvm-svn: 373663
  • Loading branch information
dwblaikie committed Oct 3, 2019
1 parent 350147c commit 2ac586c
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2556,23 +2556,24 @@ void DwarfDebug::emitDebugARanges() {
}
}

/// Emit a single range list. We handle both DWARF v5 and earlier.
static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm,
const RangeSpanList &List) {

template <typename Ranges>
static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm, MCSymbol *Sym,
const Ranges &R, const DwarfCompileUnit &CU,
unsigned BaseAddressx, unsigned OffsetPair,
unsigned StartxLength, unsigned EndOfList,
StringRef (*StringifyEnum)(unsigned)) {
auto DwarfVersion = DD.getDwarfVersion();
// Emit our symbol so we can find the beginning of the range.
Asm->OutStreamer->EmitLabel(List.getSym());
Asm->OutStreamer->EmitLabel(Sym);
// Gather all the ranges that apply to the same section so they can share
// a base address entry.
MapVector<const MCSection *, std::vector<const RangeSpan *>> SectionRanges;
// Size for our labels.
auto Size = Asm->MAI->getCodePointerSize();

for (const RangeSpan &Range : List.getRanges())
for (const RangeSpan &Range : R)
SectionRanges[&Range.Begin->getSection()].push_back(&Range);

const DwarfCompileUnit &CU = List.getCU();
const MCSymbol *CUBase = CU.getBaseAddress();
bool BaseIsSet = false;
for (const auto &P : SectionRanges) {
Expand All @@ -2588,8 +2589,8 @@ static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm,
BaseIsSet = true;
Base = DD.getSectionLabel(&P.second.front()->Begin->getSection());
if (DwarfVersion >= 5) {
Asm->OutStreamer->AddComment("DW_RLE_base_addressx");
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_base_addressx, 1);
Asm->OutStreamer->AddComment(StringifyEnum(BaseAddressx));
Asm->OutStreamer->EmitIntValue(BaseAddressx, 1);
Asm->OutStreamer->AddComment(" base address index");
Asm->EmitULEB128(DD.getAddressPool().getIndex(Base));
} else {
Expand All @@ -2612,8 +2613,8 @@ static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm,
if (Base) {
if (DwarfVersion >= 5) {
// Emit DW_RLE_offset_pair when we have a base.
Asm->OutStreamer->AddComment("DW_RLE_offset_pair");
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_offset_pair, 1);
Asm->OutStreamer->AddComment(StringifyEnum(OffsetPair));
Asm->emitInt8(OffsetPair);
Asm->OutStreamer->AddComment(" starting offset");
Asm->EmitLabelDifferenceAsULEB128(Begin, Base);
Asm->OutStreamer->AddComment(" ending offset");
Expand All @@ -2623,8 +2624,8 @@ static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm,
Asm->EmitLabelDifference(End, Base, Size);
}
} else if (DwarfVersion >= 5) {
Asm->OutStreamer->AddComment("DW_RLE_startx_length");
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_startx_length, 1);
Asm->OutStreamer->AddComment(StringifyEnum(StartxLength));
Asm->emitInt8(StartxLength);
Asm->OutStreamer->AddComment(" start index");
Asm->EmitULEB128(DD.getAddressPool().getIndex(Begin));
Asm->OutStreamer->AddComment(" length");
Expand All @@ -2636,15 +2637,24 @@ static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm,
}
}
if (DwarfVersion >= 5) {
Asm->OutStreamer->AddComment("DW_RLE_end_of_list");
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_end_of_list, 1);
Asm->OutStreamer->AddComment(StringifyEnum(EndOfList));
Asm->emitInt8(EndOfList);
} else {
// Terminate the list with two 0 values.
Asm->OutStreamer->EmitIntValue(0, Size);
Asm->OutStreamer->EmitIntValue(0, Size);
}
}

/// Emit a single range list. We handle both DWARF v5 and earlier.
static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm,
const RangeSpanList &List) {
emitRangeList(DD, Asm, List.getSym(), List.getRanges(), List.getCU(),
dwarf::DW_RLE_base_addressx, dwarf::DW_RLE_offset_pair,
dwarf::DW_RLE_startx_length, dwarf::DW_RLE_end_of_list,
llvm::dwarf::RangeListEncodingString);
}

static void emitDebugRangesImpl(DwarfDebug &DD, AsmPrinter *Asm,
const DwarfFile &Holder, MCSymbol *TableEnd) {
for (const RangeSpanList &List : Holder.getRangeLists())
Expand Down

0 comments on commit 2ac586c

Please sign in to comment.