]> granicus.if.org Git - llvm/commitdiff
llvm-dwarfdump support --debug-frame=<offset> and --eh-frame=<offset>
authorAdrian Prantl <aprantl@apple.com>
Thu, 21 Sep 2017 18:52:03 +0000 (18:52 +0000)
committerAdrian Prantl <aprantl@apple.com>
Thu, 21 Sep 2017 18:52:03 +0000 (18:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313900 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
lib/DebugInfo/DWARF/DWARFContext.cpp
lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
test/tools/llvm-dwarfdump/X86/debug_frame_offset.test [new file with mode: 0644]

index f61b4e41229492bc9c2491e57b54932987c272c8..a711fb2954447be126ec78e135aac7010bf02d1b 100644 (file)
@@ -29,8 +29,8 @@ public:
   DWARFDebugFrame(bool IsEH);
   ~DWARFDebugFrame();
 
-  /// \brief Dump the section data into the given stream.
-  void dump(raw_ostream &OS) const;
+  /// Dump the section data into the given stream.
+  void dump(raw_ostream &OS, Optional<uint64_t> Offset) const;
 
   /// \brief Parse the section from raw data.
   /// data is assumed to be pointing to the beginning of the section.
@@ -39,6 +39,9 @@ public:
   /// Return whether the section has any entries.
   bool empty() const { return Entries.empty(); }
 
+  /// Return the entry at the given offset or nullptr.
+  FrameEntry *getEntryAtOffset(uint64_t Offset) const;
+
 private:
   std::vector<std::unique_ptr<FrameEntry>> Entries;
 };
index f20a7ca024b2a78ea28003f88077d17a439c0334..69a4fe64b754180412aad97187e0f999d6d2d4f9 100644 (file)
@@ -299,14 +299,12 @@ void DWARFContext::dump(
   }
 
   if (shouldDump(Explicit, ".debug_frame", DIDT_ID_DebugFrame,
-                 DObj->getDebugFrameSection())) {
-    getDebugFrame()->dump(OS);
-  }
+                 DObj->getDebugFrameSection()))
+    getDebugFrame()->dump(OS, DumpOffset);
 
   if (shouldDump(Explicit, ".eh_frame", DIDT_ID_DebugFrame,
-                 DObj->getEHFrameSection())) {
-    getEHFrame()->dump(OS);
-  }
+                 DObj->getEHFrameSection()))
+    getEHFrame()->dump(OS, DumpOffset);
 
   if (DumpType & DIDT_DebugMacro) {
     if (Explicit || !getDebugMacro()->empty()) {
index 6e8b5f4f4711cd5f1411eb6e4917f15c4b227b89..bceb0162b351577d6b86dfb4a77b42991c992d66 100644 (file)
@@ -11,7 +11,6 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -46,19 +45,26 @@ public:
   FrameKind getKind() const { return Kind; }
   virtual uint64_t getOffset() const { return Offset; }
 
-  /// \brief Parse and store a sequence of CFI instructions from Data,
+  /// Parse and store a sequence of CFI instructions from Data,
   /// starting at *Offset and ending at EndOffset. If everything
   /// goes well, *Offset should be equal to EndOffset when this method
   /// returns. Otherwise, an error occurred.
   virtual void parseInstructions(DataExtractor Data, uint32_t *Offset,
                                  uint32_t EndOffset);
 
-  /// \brief Dump the entry header to the given output stream.
+  /// Dump the entry header to the given output stream.
   virtual void dumpHeader(raw_ostream &OS) const = 0;
 
-  /// \brief Dump the entry's instructions to the given output stream.
+  /// Dump the entry's instructions to the given output stream.
   virtual void dumpInstructions(raw_ostream &OS) const;
 
+  /// Dump the entire entry to the given output stream.
+  void dump(raw_ostream &OS) const {
+    dumpHeader(OS);
+    dumpInstructions(OS);
+    OS << "\n";
+  }
+
 protected:
   const FrameKind Kind;
 
@@ -692,11 +698,24 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
   }
 }
 
-void DWARFDebugFrame::dump(raw_ostream &OS) const {
-  OS << "\n";
-  for (const auto &Entry : Entries) {
-    Entry->dumpHeader(OS);
-    Entry->dumpInstructions(OS);
-    OS << "\n";
+FrameEntry *DWARFDebugFrame::getEntryAtOffset(uint64_t Offset) const {
+  auto It =
+      std::lower_bound(Entries.begin(), Entries.end(), Offset,
+                       [](const std::unique_ptr<FrameEntry> &E,
+                          uint64_t Offset) { return E->getOffset() < Offset; });
+  if (It != Entries.end() && (*It)->getOffset() == Offset)
+    return It->get();
+  return nullptr;
+}
+
+void DWARFDebugFrame::dump(raw_ostream &OS, Optional<uint64_t> Offset) const {
+  if (Offset) {
+    if (auto *Entry = getEntryAtOffset(*Offset))
+      Entry->dump(OS);
+    return;
   }
+
+  OS << "\n";
+  for (const auto &Entry : Entries)
+    Entry->dump(OS);
 }
diff --git a/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test b/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
new file mode 100644 (file)
index 0000000..a441364
--- /dev/null
@@ -0,0 +1,14 @@
+RUN: llc -filetype=obj %p/../../dsymutil/Inputs/frame-dw2.ll -o - \
+RUN:   | llvm-dwarfdump -debug-frame=0x00000014 - | FileCheck %s
+CHECK: .debug_frame contents:
+CHECK-NEXT: 00000014 00000014 00000000 FDE cie=00000000 pc=00000000...0000001d
+CHECK-NEXT:   DW_CFA_advance_loc: 1
+CHECK-NOT: pc
+
+RUN: llvm-dwarfdump %p/../../dsymutil/Inputs/basic1.macho.x86_64.o \
+RUN:   -eh-frame=0x00000018 | FileCheck %s --check-prefix=EH
+EH: .eh_frame contents:
+EH-NEXT: 00000018 00000024 0000001c FDE cie=0000001c pc=fffffd00...fffffd24
+EH-NEXT:   DW_CFA_advance_loc: 1
+EH-NOT: pc
+EH-NOT: CIE