2023-01-25 21:39:03 +02:00
|
|
|
#include <kernel/Debug.h>
|
|
|
|
#include <kernel/Serial.h>
|
2023-04-05 00:56:09 +03:00
|
|
|
#include <kernel/Terminal/TTY.h>
|
2023-01-25 21:39:03 +02:00
|
|
|
|
|
|
|
namespace Debug
|
|
|
|
{
|
|
|
|
|
2023-02-01 21:05:44 +02:00
|
|
|
void dump_stack_trace()
|
2023-01-25 22:28:18 +02:00
|
|
|
{
|
|
|
|
struct stackframe
|
|
|
|
{
|
2023-01-30 18:56:57 +02:00
|
|
|
stackframe* rbp;
|
|
|
|
uintptr_t rip;
|
2023-01-25 22:28:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
stackframe* frame = (stackframe*)__builtin_frame_address(0);
|
2023-01-30 18:56:57 +02:00
|
|
|
if (!frame)
|
|
|
|
{
|
|
|
|
dprintln("Could not get frame address");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uintptr_t first_rip = frame->rip;
|
|
|
|
|
2023-01-25 22:28:18 +02:00
|
|
|
BAN::Formatter::print(Debug::putchar, "\e[36mStack trace:\r\n");
|
|
|
|
while (frame)
|
|
|
|
{
|
2023-01-30 18:56:57 +02:00
|
|
|
BAN::Formatter::print(Debug::putchar, " {}\r\n", (void*)frame->rip);
|
|
|
|
frame = frame->rbp;
|
|
|
|
|
|
|
|
if (frame && frame->rip == first_rip)
|
|
|
|
{
|
|
|
|
derrorln("looping kernel panic :(");
|
|
|
|
return;
|
|
|
|
}
|
2023-01-25 22:28:18 +02:00
|
|
|
}
|
2023-03-08 01:21:17 +02:00
|
|
|
BAN::Formatter::print(Debug::putchar, "\e[m");
|
2023-01-25 22:28:18 +02:00
|
|
|
}
|
|
|
|
|
2023-01-25 21:39:03 +02:00
|
|
|
void putchar(char ch)
|
|
|
|
{
|
2023-02-01 21:05:44 +02:00
|
|
|
if (Serial::is_initialized())
|
2023-01-25 21:39:03 +02:00
|
|
|
return Serial::putchar(ch);
|
2023-04-05 00:56:09 +03:00
|
|
|
if (Kernel::TTY::is_initialized())
|
|
|
|
return Kernel::TTY::putchar_current(ch);
|
2023-01-25 21:39:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|