[llvm] r313900 - llvm-dwarfdump support --debug-frame=<offset> and --eh-frame=<offset>

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 11:52:03 PDT 2017


Author: adrian
Date: Thu Sep 21 11:52:03 2017
New Revision: 313900

URL: http://llvm.org/viewvc/llvm-project?rev=313900&view=rev
Log:
llvm-dwarfdump support --debug-frame=<offset> and --eh-frame=<offset>

Added:
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h?rev=313900&r1=313899&r2=313900&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h Thu Sep 21 11:52:03 2017
@@ -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;
 };

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=313900&r1=313899&r2=313900&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Thu Sep 21 11:52:03 2017
@@ -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()) {

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp?rev=313900&r1=313899&r2=313900&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp Thu Sep 21 11:52:03 2017
@@ -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(DataExtracto
   }
 }
 
-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);
 }

Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test?rev=313900&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test (added)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test Thu Sep 21 11:52:03 2017
@@ -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




More information about the llvm-commits mailing list