diff options
author | Danny Holman <dholman@gymli.org> | 2024-06-24 02:09:07 -0500 |
---|---|---|
committer | Danny Holman <dholman@gymli.org> | 2024-06-24 02:09:07 -0500 |
commit | 3851af792ca7b4bb7fc998337c4aec05627cfa8f (patch) | |
tree | b07cc8debad6895f0a3e4cacd11dcf327265ef2e /kernel | |
parent | b09100f8b79b77f613f5d68fd661e3cbaf1f5c86 (diff) |
kernel: panic: generate a stack frame on panic
Add a function that generates and prints a stack trace to the screen.
This function relies on walk_stack() being implemented on the target
architecture.
Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/panic.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/kernel/panic.c b/kernel/panic.c index e7eb330..65279f0 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -5,8 +5,22 @@ static int panicked = 0; +void walk_stack(uintptr_t *addrs, size_t n); + +void stack_trace(void) { + kprintf("PRINTING STACK TRACE\n"); + uintptr_t strace[32]; + walk_stack(strace, 32); + for (int i = 0; i < 32; i++) { + if (strace[i] == 0) + break; + kprintf("#%d: %x\n", i, strace[i]); + } +} + void panic(const char *str) { - kprintf("KERNEL PANIC: %s\n", str); panicked = 1; + kprintf("KERNEL PANIC: %s\n", str); + stack_trace(); while (1); } |