2022-09-19 19:11:43 +00:00
|
|
|
#include "trace/StackTracer.h"
|
|
|
|
#include "std/stdio.h"
|
|
|
|
#include "trace/Resolve.h"
|
|
|
|
|
|
|
|
StackTracer::StackTracer()
|
|
|
|
{
|
|
|
|
asm("mov %%rbp, %0" : "=r"(m_base_pointer));
|
|
|
|
}
|
|
|
|
|
|
|
|
StackTracer::StackTracer(uintptr_t base_pointer) : m_base_pointer(base_pointer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct stackframe
|
|
|
|
{
|
|
|
|
struct stackframe* next;
|
|
|
|
uintptr_t instruction;
|
|
|
|
} stackframe;
|
|
|
|
|
|
|
|
void StackTracer::trace()
|
|
|
|
{
|
|
|
|
stackframe* frame = (stackframe*)m_base_pointer;
|
2022-09-21 18:59:41 +00:00
|
|
|
while (frame && (uint64_t)frame > 0xfffffffff8000000)
|
2022-09-19 19:11:43 +00:00
|
|
|
{
|
|
|
|
char symbol_name[512];
|
|
|
|
get_symbol_name(frame->instruction, symbol_name);
|
|
|
|
printf("%lx: %s\n", frame->instruction, symbol_name);
|
|
|
|
frame = frame->next;
|
|
|
|
}
|
|
|
|
}
|