Kernel: Move dump_stacktrace from panic -> debug

This commit is contained in:
Bananymous 2023-01-25 22:28:18 +02:00
parent e87026f01d
commit aa0757e135
5 changed files with 20 additions and 28 deletions

View File

@ -40,7 +40,6 @@ kernel/Input.o \
kernel/InterruptController.o \
kernel/kernel.o \
kernel/kmalloc.o \
kernel/Panic.o \
kernel/PIC.o \
kernel/PIT.o \
kernel/RTC.o \

View File

@ -28,5 +28,6 @@
namespace Debug
{
void DumpStackTrace();
void putchar(char);
}

View File

@ -8,15 +8,13 @@
namespace Kernel
{
void dump_stacktrace();
template<typename... Args>
__attribute__((__noreturn__))
static void PanicImpl(const char* file, int line, const char* message, Args... args)
{
kprintln("\e[31mKernel panic at {}:{}\e[m", file, line);
derrorln("Kernel panic at {}:{}", file, line);
derrorln(message, args...);
dump_stacktrace();
Debug::DumpStackTrace();
asm volatile("cli");
for (;;)
asm volatile("hlt");

View File

@ -5,6 +5,23 @@
namespace Debug
{
void DumpStackTrace()
{
struct stackframe
{
stackframe* ebp;
uintptr_t eip;
};
stackframe* frame = (stackframe*)__builtin_frame_address(0);
BAN::Formatter::print(Debug::putchar, "\e[36mStack trace:\r\n");
while (frame)
{
BAN::Formatter::print(Debug::putchar, " {}\r\n", (void*)frame->eip);
frame = frame->ebp;
}
}
void putchar(char ch)
{
if (Serial::IsInitialized())

View File

@ -1,23 +0,0 @@
#include <kernel/Panic.h>
namespace Kernel
{
void dump_stacktrace()
{
struct stackframe
{
stackframe* ebp;
uintptr_t eip;
};
stackframe* frame = (stackframe*)__builtin_frame_address(0);
BAN::Formatter::print(Debug::putchar, "\e[36mStack trace:\r\n");
while (frame)
{
BAN::Formatter::print(Debug::putchar, " {}\r\n", (void*)frame->eip);
frame = frame->ebp;
}
}
}