2018-04-04 14:47:54 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <DwarfInterpret.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
volatile int optim_stopper = 0;
|
|
|
|
|
|
|
|
void dump_my_stack() {
|
|
|
|
DwarfInterpret& dw = DwarfInterpret::acquire();
|
|
|
|
|
2018-04-05 19:18:06 +02:00
|
|
|
DwarfInterpret::UnwindContext unw_context =
|
|
|
|
DwarfInterpret::get_current_unwind_context();
|
|
|
|
MemoryMap mmap;
|
|
|
|
|
2018-04-04 14:47:54 +02:00
|
|
|
while(true) {
|
2018-04-05 19:18:06 +02:00
|
|
|
printf(">> PC = %lX ", unw_context.rip);
|
|
|
|
MemoryMap::MapEntry cur_map_entry =
|
|
|
|
mmap[mmap.id_of_address(unw_context.rip)];
|
|
|
|
uintptr_t inelf_pc = unw_context.rip
|
|
|
|
- cur_map_entry.mem_region.begin + cur_map_entry.offset;
|
|
|
|
printf("(in ELF: %lX) <<\n", inelf_pc);
|
2018-04-04 14:47:54 +02:00
|
|
|
fflush(stdout);
|
2018-04-05 19:18:06 +02:00
|
|
|
unw_context = dw.unwind_context(unw_context);
|
2018-04-04 14:47:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fill_my_stack(int stack_depth) {
|
|
|
|
if(stack_depth == 0)
|
|
|
|
dump_my_stack();
|
|
|
|
|
|
|
|
fill_my_stack(stack_depth - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
MemoryMap mmap;
|
|
|
|
cout << "Dumping memory map… (" << mmap.size() << " entries)" << endl;
|
|
|
|
for(const auto& entry: mmap) {
|
|
|
|
entry.dump(cout);
|
|
|
|
}
|
|
|
|
cout << "End memory map" << endl;
|
|
|
|
int stack_depth = 5;
|
|
|
|
if(argc >= 2)
|
|
|
|
stack_depth = atoi(argv[1]);
|
|
|
|
|
|
|
|
fill_my_stack(stack_depth);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|