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.
/// 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;
};
}
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()) {
#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"
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;
}
}
-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);
}
--- /dev/null
+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