#include "trace/StackTracer.h" #include "memory/Memory.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; while (frame && frame->instruction) { char symbol_name[512]; get_symbol_name(frame->instruction, symbol_name, sizeof(symbol_name)); printf("%lx: %s\n", frame->instruction, symbol_name); frame = frame->next; } } void StackTracer::trace_with_ip(uintptr_t ip) { char symbol_name[512]; get_symbol_name(ip, symbol_name, sizeof(symbol_name)); printf("%lx: %s\n", ip, symbol_name); trace(); } bool stack_trace_contains(uintptr_t address) { uintptr_t base_pointer; asm volatile("mov %%rbp, %0" : "=r"(base_pointer)); stackframe* frame = (stackframe*)base_pointer; while (Memory::is_kernel_address((uintptr_t)frame)) { if (frame->instruction == address) return true; frame = frame->next; } return false; }