From f60ab15600bc58233eec659eb3a76c5432fde69a Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 9 Jun 2021 20:12:53 +0200 Subject: Better stack tracing --- libs/libc/inc/print.h | 3 ++- libs/libc/print.c | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'libs') diff --git a/libs/libc/inc/print.h b/libs/libc/inc/print.h index bc1b7b0..6997796 100644 --- a/libs/libc/inc/print.h +++ b/libs/libc/inc/print.h @@ -24,7 +24,8 @@ NORETURN void err(int code, const char *format, ...) NONNULL; #else #include int print_prefix(void); -void print_trace(u32 count); +void print_trace_custom(u32 stack, u32 count); +void print_trace(void); #endif #endif diff --git a/libs/libc/print.c b/libs/libc/print.c index 7c40a8b..091df82 100644 --- a/libs/libc/print.c +++ b/libs/libc/print.c @@ -207,20 +207,30 @@ int print(const char *str) return strlen(str); } -void print_trace(u32 count) +void print_trace_custom(u32 stack, u32 count) { + stac(); struct frame { struct frame *ebp; u32 eip; - } * stk; - __asm__ volatile("movl %%ebp, %0;" : "=r"(stk)); - print("EBP\tEIP\n"); + } *stk = (void *)stack; + printf("Stack trace for 0x%x\n", stack); + print("\tEBP\tEIP\n"); for (u32 i = 0; stk && memory_readable(stk) && i < count; i++) { if (!stk->ebp || !stk->eip) break; - printf("0x%x\t0x%x\n", stk->ebp, stk->eip); + printf("\t0x%x\t0x%x\n", stk->ebp, stk->eip); stk = stk->ebp; } + print("Stack trace end\n"); + clac(); +} + +void print_trace(void) +{ + u32 ebp; + __asm__ volatile("movl %%ebp, %0;" : "=r"(ebp)); + print_trace_custom(ebp, 10); } #endif @@ -235,7 +245,7 @@ void panic(const char *format, ...) #ifdef KERNEL print("--- DON'T PANIC! ---\n"); print(buf); - print_trace(10); + print_trace(); while (1) __asm__ volatile("cli\nhlt"); #else -- cgit v1.2.3