From 89b7f16204afa25325c28edeaa9973853f2e6796 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 1 Nov 2019 14:50:12 -0700 Subject: [PATCH] DebugInfo: Streamline debug_ranges/rnglists/rnglists.dwo emission code More code reuse, better basis for modelling debug_loc/loclists/loclists.dwo emission support. --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 69 +++++++--------------- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h | 1 + 2 files changed, 23 insertions(+), 47 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 2f7025945a15..97ef439b8a5f 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2655,10 +2655,23 @@ static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm, [](auto) {}); } -static void emitDebugRangesImpl(DwarfDebug &DD, AsmPrinter *Asm, - const DwarfFile &Holder, MCSymbol *TableEnd) { +void DwarfDebug::emitDebugRangesImpl(const DwarfFile &Holder, MCSection *Section) { + if (Holder.getRangeLists().empty()) + return; + + assert(useRangesSection()); + assert(!CUMap.empty()); + assert(llvm::any_of(CUMap, [](const decltype(CUMap)::value_type &Pair) { + return !Pair.second->getCUNode()->isDebugDirectivesOnly(); + })); + + Asm->OutStreamer->SwitchSection(Section); + + MCSymbol *TableEnd = + getDwarfVersion() < 5 ? nullptr : emitRnglistsTableHeader(Asm, Holder); + for (const RangeSpanList &List : Holder.getRangeLists()) - emitRangeList(DD, Asm, List); + emitRangeList(*this, Asm, List); if (TableEnd) Asm->OutStreamer->EmitLabel(TableEnd); @@ -2667,55 +2680,17 @@ static void emitDebugRangesImpl(DwarfDebug &DD, AsmPrinter *Asm, /// Emit address ranges into the .debug_ranges section or into the DWARF v5 /// .debug_rnglists section. void DwarfDebug::emitDebugRanges() { - if (CUMap.empty()) - return; - const auto &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder; - if (Holder.getRangeLists().empty()) - return; - - assert(useRangesSection()); - assert(llvm::none_of(CUMap, [](const decltype(CUMap)::value_type &Pair) { - return Pair.second->getCUNode()->isDebugDirectivesOnly(); - })); - - // Start the dwarf ranges section. - MCSymbol *TableEnd = nullptr; - if (getDwarfVersion() >= 5) { - Asm->OutStreamer->SwitchSection( - Asm->getObjFileLowering().getDwarfRnglistsSection()); - TableEnd = emitRnglistsTableHeader(Asm, Holder); - } else - Asm->OutStreamer->SwitchSection( - Asm->getObjFileLowering().getDwarfRangesSection()); - - emitDebugRangesImpl(*this, Asm, Holder, TableEnd); + emitDebugRangesImpl(Holder, + getDwarfVersion() >= 5 + ? Asm->getObjFileLowering().getDwarfRnglistsSection() + : Asm->getObjFileLowering().getDwarfRangesSection()); } void DwarfDebug::emitDebugRangesDWO() { - assert(useSplitDwarf()); - - if (CUMap.empty()) - return; - - const auto &Holder = InfoHolder; - - if (Holder.getRangeLists().empty()) - return; - - assert(getDwarfVersion() >= 5); - assert(useRangesSection()); - assert(llvm::none_of(CUMap, [](const decltype(CUMap)::value_type &Pair) { - return Pair.second->getCUNode()->isDebugDirectivesOnly(); - })); - - // Start the dwarf ranges section. - Asm->OutStreamer->SwitchSection( - Asm->getObjFileLowering().getDwarfRnglistsDWOSection()); - MCSymbol *TableEnd = emitRnglistsTableHeader(Asm, Holder); - - emitDebugRangesImpl(*this, Asm, Holder, TableEnd); + emitDebugRangesImpl(InfoHolder, + Asm->getObjFileLowering().getDwarfRnglistsDWOSection()); } void DwarfDebug::handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U) { diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index c8c511f67c2a..85016074e251 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -504,6 +504,7 @@ class DwarfDebug : public DebugHandlerBase { /// Emit address ranges into a debug ranges section. void emitDebugRanges(); void emitDebugRangesDWO(); + void emitDebugRangesImpl(const DwarfFile &Holder, MCSection *Section); /// Emit macros into a debug macinfo section. void emitDebugMacinfo();