From: Adrian Prantl Date: Fri, 29 Sep 2017 00:33:22 +0000 (+0000) Subject: llvm-dwarfdump: add support for .apple_types in --find X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4d5765b0a51ed244780e1abe0212e7bbb222abf9;p=llvm llvm-dwarfdump: add support for .apple_types in --find git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314479 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/DebugInfo/DWARF/DWARFContext.h b/include/llvm/DebugInfo/DWARF/DWARFContext.h index 471fb4c971f..9a1da73c20c 100644 --- a/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -70,6 +70,7 @@ class DWARFContext : public DIContext { std::unique_ptr EHFrame; std::unique_ptr Macro; std::unique_ptr AppleNames; + std::unique_ptr AppleTypes; DWARFUnitSection DWOCUs; std::deque> DWOTUs; @@ -242,6 +243,9 @@ public: /// Get a reference to the parsed accelerator table object. const DWARFAcceleratorTable &getAppleNames(); + /// Get a reference to the parsed accelerator table object. + const DWARFAcceleratorTable &getAppleTypes(); + /// 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 4a5253a0404..a48f5c41b67 100644 --- a/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -457,8 +457,7 @@ void DWARFContext::dump( if (shouldDump(Explicit, ".apple_types", DIDT_ID_AppleTypes, DObj->getAppleTypesSection().Data)) - dumpAccelSection(OS, *DObj, DObj->getAppleTypesSection(), - DObj->getStringSection(), isLittleEndian()); + getAppleTypes().dump(OS); if (shouldDump(Explicit, ".apple_namespaces", DIDT_ID_AppleNamespaces, DObj->getAppleNamespacesSection().Data)) @@ -655,6 +654,11 @@ const DWARFAcceleratorTable &DWARFContext::getAppleNames() { DObj->getStringSection(), isLittleEndian()); } +const DWARFAcceleratorTable &DWARFContext::getAppleTypes() { + return getAccelTable(AppleTypes, *DObj, DObj->getAppleTypesSection(), + 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 b6e91b9a14c..e6a40b07736 100644 --- a/test/tools/llvm-dwarfdump/X86/find.test +++ b/test/tools/llvm-dwarfdump/X86/find.test @@ -26,3 +26,12 @@ MULTI: : DW_TAG_variable MULTI-NOT: {{: DW}} MULTI: DW_AT_name ("x86_64h_var") MULTI-NOT: {{: DW}} + +RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \ +RUN: | llvm-dwarfdump -find=int - | FileCheck %s --check-prefix=TYPES +TYPES: .debug_info contents: +TYPES-NOT: {{:}} +TYPES: : DW_TAG_base_type +TYPES-NOT: {{:}} +TYPES: DW_AT_name ("int") +TYPES-NOT: {{:}} diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 9c4a7c88bb3..a36926d1097 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -247,11 +247,20 @@ static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename, // Handle the --find option and lower it to --debug-info=. if (!Find.empty()) { DumpOffsets[DIDT_ID_DebugInfo] = [&]() -> llvm::Optional { - for (auto Name : Find) - for (auto Entry : DICtx.getAppleNames().equal_range(Name)) - for (auto Atom : Entry) - if (auto Offset = Atom.getAsSectionOffset()) - return DumpOffsets[DIDT_ID_DebugInfo] = *Offset; + for (auto Name : Find) { + auto find = [&](const DWARFAcceleratorTable &Accel) + -> llvm::Optional { + for (auto Entry : Accel.equal_range(Name)) + for (auto Atom : Entry) + if (auto Offset = Atom.getAsSectionOffset()) + return Offset; + return None; + }; + if (auto Offset = find(DICtx.getAppleNames())) + return DumpOffsets[DIDT_ID_DebugInfo] = *Offset; + if (auto Offset = find(DICtx.getAppleTypes())) + return DumpOffsets[DIDT_ID_DebugInfo] = *Offset; + } return None; }(); // Early exit if --find was specified but the current file doesn't have it.