diff --git a/include/dwarfinterpret/DwarfInterpret.hpp b/include/dwarfinterpret/DwarfInterpret.hpp index 60c6333..6fef6fe 100644 --- a/include/dwarfinterpret/DwarfInterpret.hpp +++ b/include/dwarfinterpret/DwarfInterpret.hpp @@ -107,6 +107,9 @@ class DwarfInterpret { uintptr_t rip; uintptr_t rsp; uintptr_t rbp; + + /// This context's `RIP` minus its ELF file load offset + uintptr_t elf_local_rip() const; }; public: // methods @@ -180,6 +183,12 @@ class DwarfInterpret { */ UnwindContext unwind_context(const UnwindContext& ctx); + /** Get the offset for the instruction pointer. + * + * This offset is such that `actual_rip - pc_offset` is the ELF-local + * PC (ie. what readelf gives). */ + uintptr_t get_pc_offset() const { return pc_offset; } + private: DwarfInterpret(const MemoryMap::MapEntry& memory_object); diff --git a/src/DwarfInterpret.cpp b/src/DwarfInterpret.cpp index 9420064..e40dd0a 100644 --- a/src/DwarfInterpret.cpp +++ b/src/DwarfInterpret.cpp @@ -36,6 +36,11 @@ using namespace dwarf; MemoryMap DwarfInterpret::memory_map; map > DwarfInterpret::instances; +uintptr_t DwarfInterpret::UnwindContext::elf_local_rip() const { + return rip - DwarfInterpret::acquire(rip).get_pc_offset(); +} + + DwarfInterpret::DwarfInterpret(const MemoryMap::MapEntry& memory_object) : map_entry(memory_object) {