From e98b0e466fd0298c3faae6cc82a2bcd273c0ed19 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 11 Mar 2014 23:18:15 +0000 Subject: [PATCH] DebugInfo: Refactor emitDebugPubNames/Types into a common implementation I could fold the callers into their one call site, but the indirection (given how verbose choosing the section is) seemed helpful. The use of a member function pointer's a bit "tricky", but seems limited enough, the call sites are simple/clean/clear, and there's only one use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203619 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 67 ++++------------------ lib/CodeGen/AsmPrinter/DwarfDebug.h | 5 ++ test/DebugInfo/X86/dwarf-pubnames-split.ll | 2 +- 3 files changed, 17 insertions(+), 57 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index f4eb787adbf..93cd89e77a2 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2204,6 +2204,12 @@ void DwarfDebug::emitDebugPubNames(bool GnuStyle) { GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection() : Asm->getObjFileLowering().getDwarfPubNamesSection(); + emitDebugPubSection(GnuStyle, PSec, "Names", &DwarfUnit::getGlobalNames); +} + +void DwarfDebug::emitDebugPubSection( + bool GnuStyle, const MCSection *PSec, StringRef Name, + const StringMap &(DwarfUnit::*Accessor)() const) { for (const auto &NU : CUMap) { DwarfCompileUnit *TheU = NU.second; if (auto Skeleton = static_cast(TheU->getSkeleton())) @@ -2214,9 +2220,9 @@ void DwarfDebug::emitDebugPubNames(bool GnuStyle) { Asm->OutStreamer.SwitchSection(PSec); // Emit the header. - Asm->OutStreamer.AddComment("Length of Public Names Info"); - MCSymbol *BeginLabel = Asm->GetTempSymbol("pubnames_begin", ID); - MCSymbol *EndLabel = Asm->GetTempSymbol("pubnames_end", ID); + Asm->OutStreamer.AddComment("Length of Public " + Name + " Info"); + MCSymbol *BeginLabel = Asm->GetTempSymbol("pub" + Name + "_begin", ID); + MCSymbol *EndLabel = Asm->GetTempSymbol("pub" + Name + "_end", ID); Asm->EmitLabelDifference(EndLabel, BeginLabel, 4); Asm->OutStreamer.EmitLabel(BeginLabel); @@ -2231,7 +2237,7 @@ void DwarfDebug::emitDebugPubNames(bool GnuStyle) { Asm->EmitLabelDifference(TheU->getLabelEnd(), TheU->getLabelBegin(), 4); // Emit the pubnames for this compilation unit. - for (const auto &GI : getUnits()[ID]->getGlobalNames()) { + for (const auto &GI : (getUnits()[ID]->*Accessor)()) { const char *Name = GI.getKeyData(); const DIE *Entity = GI.second; @@ -2261,58 +2267,7 @@ void DwarfDebug::emitDebugPubTypes(bool GnuStyle) { GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubTypesSection() : Asm->getObjFileLowering().getDwarfPubTypesSection(); - for (const auto &NU : CUMap) { - DwarfCompileUnit *TheU = NU.second; - if (auto Skeleton = static_cast(TheU->getSkeleton())) - TheU = Skeleton; - unsigned ID = TheU->getUniqueID(); - - // Start the dwarf pubtypes section. - Asm->OutStreamer.SwitchSection(PSec); - - // Emit the header. - Asm->OutStreamer.AddComment("Length of Public Types Info"); - MCSymbol *BeginLabel = Asm->GetTempSymbol("pubtypes_begin", ID); - MCSymbol *EndLabel = Asm->GetTempSymbol("pubtypes_end", ID); - Asm->EmitLabelDifference(EndLabel, BeginLabel, 4); - - Asm->OutStreamer.EmitLabel(BeginLabel); - - Asm->OutStreamer.AddComment("DWARF Version"); - Asm->EmitInt16(dwarf::DW_PUBTYPES_VERSION); - - Asm->OutStreamer.AddComment("Offset of Compilation Unit Info"); - Asm->EmitSectionOffset(TheU->getLabelBegin(), TheU->getSectionSym()); - - Asm->OutStreamer.AddComment("Compilation Unit Length"); - Asm->EmitLabelDifference(TheU->getLabelEnd(), TheU->getLabelBegin(), 4); - - // Emit the pubtypes. - for (const auto &GI : getUnits()[ID]->getGlobalTypes()) { - const char *Name = GI.getKeyData(); - const DIE *Entity = GI.second; - - Asm->OutStreamer.AddComment("DIE offset"); - Asm->EmitInt32(Entity->getOffset()); - - if (GnuStyle) { - dwarf::PubIndexEntryDescriptor Desc = computeIndexValue(TheU, Entity); - Asm->OutStreamer.AddComment( - Twine("Kind: ") + dwarf::GDBIndexEntryKindString(Desc.Kind) + ", " + - dwarf::GDBIndexEntryLinkageString(Desc.Linkage)); - Asm->EmitInt8(Desc.toBits()); - } - - Asm->OutStreamer.AddComment("External Name"); - - // Emit the name with a terminating null byte. - Asm->OutStreamer.EmitBytes(StringRef(Name, GI.getKeyLength() + 1)); - } - - Asm->OutStreamer.AddComment("End Mark"); - Asm->EmitInt32(0); - Asm->OutStreamer.EmitLabel(EndLabel); - } + emitDebugPubSection(GnuStyle, PSec, "Types", &DwarfUnit::getGlobalTypes); } // Emit strings into a string section. diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index d76ba490cb9..bd1d304b71d 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -585,6 +585,11 @@ class DwarfDebug : public AsmPrinterHandler { /// index. void emitDebugPubTypes(bool GnuStyle = false); + void + emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name, + const StringMap &(DwarfUnit::*Accessor)() + const); + /// \brief Emit visible names into a debug str section. void emitDebugStr(); diff --git a/test/DebugInfo/X86/dwarf-pubnames-split.ll b/test/DebugInfo/X86/dwarf-pubnames-split.ll index 683aac5ef02..65c46d368d1 100644 --- a/test/DebugInfo/X86/dwarf-pubnames-split.ll +++ b/test/DebugInfo/X86/dwarf-pubnames-split.ll @@ -7,7 +7,7 @@ ; Check that we get a symbol off of the debug_info section when using split dwarf and pubnames. -; CHECK: .Lpubtypes_begin0: +; CHECK: .LpubTypes_begin0: ; CHECK-NEXT: .short 2 # DWARF Version ; CHECK-NEXT: .long .L.debug_info_begin0 # Offset of Compilation Unit Info -- 2.34.1