From 547ff0af111be00931edb9e76e26037021fa20ba Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 29 Sep 2017 00:52:33 +0000 Subject: [PATCH] llvm-dwarfdump: support .apple-namespaces in --find git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314481 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/DebugInfo/DWARF/DWARFContext.h | 8 ++++++ lib/DebugInfo/DWARF/DWARFContext.cpp | 28 ++++++++++----------- test/tools/llvm-dwarfdump/X86/find.test | 7 ++++++ tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 2 ++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/include/llvm/DebugInfo/DWARF/DWARFContext.h b/include/llvm/DebugInfo/DWARF/DWARFContext.h index 9a1da73c20c..4cecd22d450 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -71,6 +71,8 @@ class DWARFContext : public DIContext { std::unique_ptr Macro; std::unique_ptr AppleNames; std::unique_ptr AppleTypes; + std::unique_ptr AppleNamespaces; + std::unique_ptr AppleObjC; DWARFUnitSection DWOCUs; std::deque> DWOTUs; @@ -246,6 +248,12 @@ public: /// Get a reference to the parsed accelerator table object. const DWARFAcceleratorTable &getAppleTypes(); + /// Get a reference to the parsed accelerator table object. + const DWARFAcceleratorTable &getAppleNamespaces(); + + /// Get a reference to the parsed accelerator table object. + const DWARFAcceleratorTable &getAppleObjC(); + /// Get a pointer to a parsed line table corresponding to a compile unit. const DWARFDebugLine::LineTable *getLineTableForUnit(DWARFUnit *cu); diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp index a48f5c41b67..bf0c4b01dc0 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -68,17 +68,6 @@ DWARFContext::DWARFContext(std::unique_ptr DObj, DWARFContext::~DWARFContext() = default; -static void dumpAccelSection(raw_ostream &OS, const DWARFObject &Obj, - const DWARFSection &Section, - StringRef StringSection, bool LittleEndian) { - DWARFDataExtractor AccelSection(Obj, Section, LittleEndian, 0); - DataExtractor StrData(StringSection, LittleEndian, 0); - DWARFAcceleratorTable Accel(AccelSection, StrData); - if (!Accel.extract()) - return; - Accel.dump(OS); -} - /// Dump the UUID load command. static void dumpUUID(raw_ostream &OS, const ObjectFile &Obj) { auto *MachO = dyn_cast(&Obj); @@ -461,13 +450,11 @@ void DWARFContext::dump( if (shouldDump(Explicit, ".apple_namespaces", DIDT_ID_AppleNamespaces, DObj->getAppleNamespacesSection().Data)) - dumpAccelSection(OS, *DObj, DObj->getAppleNamespacesSection(), - DObj->getStringSection(), isLittleEndian()); + getAppleNamespaces().dump(OS); if (shouldDump(Explicit, ".apple_objc", DIDT_ID_AppleObjC, DObj->getAppleObjCSection().Data)) - dumpAccelSection(OS, *DObj, DObj->getAppleObjCSection(), - DObj->getStringSection(), isLittleEndian()); + getAppleObjC().dump(OS); } DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) { @@ -659,6 +646,17 @@ const DWARFAcceleratorTable &DWARFContext::getAppleTypes() { DObj->getStringSection(), isLittleEndian()); } +const DWARFAcceleratorTable &DWARFContext::getAppleNamespaces() { + return getAccelTable(AppleNamespaces, *DObj, + DObj->getAppleNamespacesSection(), + DObj->getStringSection(), isLittleEndian()); +} + +const DWARFAcceleratorTable &DWARFContext::getAppleObjC() { + return getAccelTable(AppleObjC, *DObj, DObj->getAppleObjCSection(), + DObj->getStringSection(), isLittleEndian()); +} + const DWARFLineTable * DWARFContext::getLineTableForUnit(DWARFUnit *U) { if (!Line) diff --git a/test/tools/llvm-dwarfdump/X86/find.test b/test/tools/llvm-dwarfdump/X86/find.test index e6a40b07736..2d308b7973d 100644 --- a/test/tools/llvm-dwarfdump/X86/find.test +++ b/test/tools/llvm-dwarfdump/X86/find.test @@ -35,3 +35,10 @@ TYPES: : DW_TAG_base_type TYPES-NOT: {{:}} TYPES: DW_AT_name ("int") TYPES-NOT: {{:}} + +RUN: llvm-dwarfdump %S/../../dsymutil/Inputs/odr-anon-namespace/1.o \ +RUN: -find="(anonymous namespace)" \ +RUN: | FileCheck %s --check-prefix=NAMESPACE +NAMESPACE-NOT: {{: DW}} +NAMESPACE: 0x0000005b: DW_TAG_namespace +NAMESPACE-NOT: {{: DW}} diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index a36926d1097..c5584b81d3c 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -260,6 +260,8 @@ static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename, return DumpOffsets[DIDT_ID_DebugInfo] = *Offset; if (auto Offset = find(DICtx.getAppleTypes())) return DumpOffsets[DIDT_ID_DebugInfo] = *Offset; + if (auto Offset = find(DICtx.getAppleNamespaces())) + return DumpOffsets[DIDT_ID_DebugInfo] = *Offset; } return None; }(); -- 2.49.0