]> granicus.if.org Git - llvm/commitdiff
llvm-dwarfdump: add support for .apple_types in --find
authorAdrian Prantl <aprantl@apple.com>
Fri, 29 Sep 2017 00:33:22 +0000 (00:33 +0000)
committerAdrian Prantl <aprantl@apple.com>
Fri, 29 Sep 2017 00:33:22 +0000 (00:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314479 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/DWARF/DWARFContext.h
lib/DebugInfo/DWARF/DWARFContext.cpp
test/tools/llvm-dwarfdump/X86/find.test
tools/llvm-dwarfdump/llvm-dwarfdump.cpp

index 471fb4c971f83cc5d6aaa1ffd1b2c09198fcf41b..9a1da73c20c7605ca4d288223aa0e10d10878dc8 100644 (file)
@@ -70,6 +70,7 @@ class DWARFContext : public DIContext {
   std::unique_ptr<DWARFDebugFrame> EHFrame;
   std::unique_ptr<DWARFDebugMacro> Macro;
   std::unique_ptr<DWARFAcceleratorTable> AppleNames;
+  std::unique_ptr<DWARFAcceleratorTable> AppleTypes;
 
   DWARFUnitSection<DWARFCompileUnit> DWOCUs;
   std::deque<DWARFUnitSection<DWARFTypeUnit>> 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);
 
index 4a5253a0404b9eb87b3cfa137219970f9979ea09..a48f5c41b67e4bb7d5f7bfacec78a2e393f04967 100644 (file)
@@ -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)
index b6e91b9a14c2491dc2d68dd0ea65ae5b700eb174..e6a40b07736760963969f6f7aedef23a6756ff00 100644 (file)
@@ -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: {{:}}
index 9c4a7c88bb36db2a785f02cbe7cd343e6e58b8c4..a36926d109755efaa346fa3109bdbb69486921cc 100644 (file)
@@ -247,11 +247,20 @@ static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename,
   // Handle the --find option and lower it to --debug-info=<offset>.
   if (!Find.empty()) {
     DumpOffsets[DIDT_ID_DebugInfo] = [&]() -> llvm::Optional<uint64_t> {
-      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<uint64_t> {
+          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.