Got a stack tracer working!!
This commit is contained in:
parent
9d3030763b
commit
ee8c2759a6
12
kernel/include/trace/StackTracer.h
Normal file
12
kernel/include/trace/StackTracer.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct StackTracer
|
||||||
|
{
|
||||||
|
StackTracer();
|
||||||
|
StackTracer(uintptr_t base_pointer);
|
||||||
|
void trace();
|
||||||
|
|
||||||
|
private:
|
||||||
|
uintptr_t m_base_pointer;
|
||||||
|
};
|
@ -5,6 +5,7 @@
|
|||||||
#include "log/Log.h"
|
#include "log/Log.h"
|
||||||
#include "panic/hang.h"
|
#include "panic/hang.h"
|
||||||
#include "std/stdio.h"
|
#include "std/stdio.h"
|
||||||
|
#include "trace/StackTracer.h"
|
||||||
|
|
||||||
extern "C" void common_handler(SavedContext* context)
|
extern "C" void common_handler(SavedContext* context)
|
||||||
{
|
{
|
||||||
@ -15,14 +16,23 @@ extern "C" void common_handler(SavedContext* context)
|
|||||||
}
|
}
|
||||||
if (context->number == 13)
|
if (context->number == 13)
|
||||||
{
|
{
|
||||||
kerrorln("General protection fault at RIP %lx, cs %ld, ss %ld, RSP %lx, error code %ld\n", context->rip,
|
kerrorln("General protection fault at RIP %lx, cs %ld, ss %ld, RSP %lx, error code %ld", context->rip,
|
||||||
context->cs, context->ss, context->rsp, context->error_code);
|
context->cs, context->ss, context->rsp, context->error_code);
|
||||||
|
kinfoln("Stack trace:");
|
||||||
|
|
||||||
|
StackTracer tracer(context->rbp);
|
||||||
|
tracer.trace();
|
||||||
while (1) halt();
|
while (1) halt();
|
||||||
}
|
}
|
||||||
if (context->number == 14)
|
if (context->number == 14)
|
||||||
{
|
{
|
||||||
kerrorln("Page fault in %s (RIP %lx), while trying to access %lx, error code %ld\n",
|
kerrorln("Page fault in %s (RIP %lx), while trying to access %lx, error code %ld",
|
||||||
context->cs == 8 ? "ring 0" : "ring 3", context->rip, context->cr2, context->error_code);
|
context->cs == 8 ? "ring 0" : "ring 3", context->rip, context->cr2, context->error_code);
|
||||||
|
kinfoln("Stack trace:");
|
||||||
|
|
||||||
|
StackTracer tracer(context->rbp);
|
||||||
|
tracer.trace();
|
||||||
|
|
||||||
hang();
|
hang();
|
||||||
}
|
}
|
||||||
if (context->number == 8)
|
if (context->number == 8)
|
||||||
|
30
kernel/src/trace/StackTracer.cpp
Normal file
30
kernel/src/trace/StackTracer.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#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;
|
||||||
|
while (frame)
|
||||||
|
{
|
||||||
|
char symbol_name[512];
|
||||||
|
get_symbol_name(frame->instruction, symbol_name);
|
||||||
|
printf("%lx: %s\n", frame->instruction, symbol_name);
|
||||||
|
frame = frame->next;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user