mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
panic: print backtrace on panic
Panics currently lack backtraces, which are a very useful thing to have. Make the profiling backtrace function generic and print backtraces using it.
This commit is contained in:
@@ -3,6 +3,18 @@
|
||||
#include <arch/smp.h>
|
||||
#include <printf.h>
|
||||
#include <kernel/interrupt.h>
|
||||
#include <arch/backtrace.h>
|
||||
|
||||
static bool paniced = false;
|
||||
|
||||
static bool step_backtrace(void *, void *ip) {
|
||||
printf("%p\n", ip);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void print_backtrace(context_t *context, void *) {
|
||||
arch_get_backtrace(context, step_backtrace, NULL);
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) void _panic(char *msg, context_t *ctx) {
|
||||
interrupt_set(false);
|
||||
@@ -17,5 +29,16 @@ __attribute__((noreturn)) void _panic(char *msg, context_t *ctx) {
|
||||
if (ctx)
|
||||
PRINT_CTX(ctx);
|
||||
|
||||
if (!paniced) {
|
||||
paniced = true;
|
||||
printf("backtrace:\n");
|
||||
if (ctx == NULL)
|
||||
arch_context_saveandcall(print_backtrace, NULL, NULL);
|
||||
else
|
||||
print_backtrace(ctx, NULL);
|
||||
} else {
|
||||
printf("!! DOUBLE PANIC !!\n");
|
||||
}
|
||||
|
||||
for (;;);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user