diff --git a/kernel/kernel/Debug.cpp b/kernel/kernel/Debug.cpp index e55830e647..b3de7521d7 100644 --- a/kernel/kernel/Debug.cpp +++ b/kernel/kernel/Debug.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -10,6 +11,8 @@ namespace Debug void dump_stack_trace() { + using namespace Kernel; + struct stackframe { stackframe* rbp; @@ -24,26 +27,33 @@ namespace Debug } uintptr_t first_rip = frame->rip; uintptr_t last_rip = 0; + bool first = true; BAN::Formatter::print(Debug::putchar, "\e[36mStack trace:\r\n"); while (frame) { - BAN::Formatter::print(Debug::putchar, " {}\r\n", (void*)frame->rip); - frame = frame->rbp; + if (PageTable::current().is_page_free((vaddr_t)frame & PAGE_ADDR_MASK)) + { + derrorln(" {} not mapped", frame); + break; + } - if (frame && frame->rip == first_rip) + BAN::Formatter::print(Debug::putchar, " {}\r\n", (void*)frame->rip); + + if (!first && frame->rip == first_rip) { derrorln("looping kernel panic :("); break; } - - if (frame && frame->rip == last_rip) + else if (!first && frame->rip == last_rip) { - derrorln("repeating stack strace"); + derrorln("repeating stack trace"); break; } last_rip = frame->rip; + frame = frame->rbp; + first = false; } BAN::Formatter::print(Debug::putchar, "\e[m"); }