dwarfinterpret/src/StackDump.cpp
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

41 lines
983 B
C++

#include <dwarfinterpret/StackDump.hpp>
#include <dwarfinterpret/MemoryMap.hpp>
#include <cassert>
#include <iostream> // FIXME
#include <cstring>
using namespace std;
StackDump StackDump::snapshot(uintptr_t rsp) {
StackDump stack;
MemoryMap memory_map;
const MemoryMap::MapEntry& stack_region =
memory_map[memory_map.id_of_address(rsp)];
assert(stack_region.pathname == "[stack]");
size_t stack_size = stack_region.mem_region.end - rsp;
stack.stack = std::shared_ptr<cell_t>(new cell_t[stack_size]);
cerr << "memcpy'ing " << stack_size << " bytes" << endl;
memcpy(stack.stack.get(), (void*)rsp, stack_size); // FIXME way too brutal
stack.offset = rsp;
return stack;
}
StackDump::StackDump()
: stack(nullptr), offset(0)
{}
StackDump::StackDump(const StackDump& oth) {
this->operator=(oth);
}
StackDump& StackDump::operator=(const StackDump& oth) {
stack = oth.stack;
offset = oth.offset;
return *this;
}