dwarfinterpret/include/dwarfinterpret/StackDump.hpp
Théophile Bastian 97032ee31b Actually able to unwind the stack
This is filled with debug prints, and is quite brutal: it saves the
whole stack. It has to be optimized a lot.

Also, needs a smooth stop when trying to unwind main.
2018-04-05 19:17:02 +02:00

29 lines
722 B
C++

#pragma once
#include <memory>
#include <cstdint>
#include <dwarfinterpret/MemoryMap.hpp>
class StackDump {
public:
static StackDump snapshot(uintptr_t rsp); ///< Take an instant snapshot
StackDump(const StackDump& oth); ///< copy
StackDump& operator=(const StackDump& oth); ///< copy
template <typename T> T deref(uintptr_t pos) const {
return *((T*)(stack.get() + pos - offset));
}
uintptr_t at(uintptr_t pos) const {
return deref<uintptr_t>(pos);
}
private:
StackDump();
typedef char cell_t;
std::shared_ptr<cell_t> stack;
uintptr_t offset; ///< such that stack[stack_addr - offset] is ok
};