From 5ec60249edd4cc22c85b41fc93a64f958e847036 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 4 Sep 2024 09:54:07 -0700 Subject: [PATCH] x86: skip printing args when unwinding stack On 32-bit x86, it was supposed to print the first argument to the function during stack trace. However, it only works when code optimizations are totally disabled (i.e. -O0). As such, printing the args is not meaningful to aid with debugging. So change it to simply print the function address, the same as x86 64-bit. Also, since unwind_stack() has exactly one caller, make it ALWAYS_INLINE to skip a function call. Signed-off-by: Daniel Leung --- arch/x86/core/fatal.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/arch/x86/core/fatal.c b/arch/x86/core/fatal.c index 07bd2315b15..d43499a08d2 100644 --- a/arch/x86/core/fatal.c +++ b/arch/x86/core/fatal.c @@ -121,17 +121,12 @@ bool z_x86_check_guard_page(uintptr_t addr) #endif /* CONFIG_THREAD_STACK_MEM_MAPPED */ #if defined(CONFIG_ARCH_STACKWALK) -typedef bool (*x86_stacktrace_cb)(void *cookie, unsigned long addr, unsigned long arg); - struct stack_frame { uintptr_t next; uintptr_t ret_addr; -#ifndef CONFIG_X86_64 - uintptr_t args; -#endif }; -__pinned_func static void walk_stackframe(x86_stacktrace_cb cb, void *cookie, +__pinned_func static void walk_stackframe(stack_trace_callback_fn cb, void *cookie, const struct arch_esf *esf, int max_frames) { uintptr_t base_ptr; @@ -181,8 +176,7 @@ __pinned_func static void walk_stackframe(x86_stacktrace_cb cb, void *cookie, break; } - if (!cb(cookie, frame->ret_addr, - COND_CODE_1(CONFIG_X86_64, (0), (frame->args)))) { + if (!cb(cookie, frame->ret_addr)) { break; } @@ -195,27 +189,26 @@ void arch_stack_walk(stack_trace_callback_fn callback_fn, void *cookie, { ARG_UNUSED(thread); - walk_stackframe((x86_stacktrace_cb)callback_fn, cookie, esf, + walk_stackframe(callback_fn, cookie, esf, CONFIG_ARCH_STACKWALK_MAX_FRAMES); } #endif /* CONFIG_ARCH_STACKWALK */ #if defined(CONFIG_EXCEPTION_STACK_TRACE) -static bool print_trace_address(void *arg, unsigned long addr, unsigned long args) +static bool print_trace_address(void *arg, unsigned long addr) { int *i = arg; #ifdef CONFIG_X86_64 LOG_ERR(" %d: 0x%016lx", (*i)++, addr); #else - LOG_ERR(" %d: 0x%08lx (0x%lx)", (*i)++, addr, args); + LOG_ERR(" %d: 0x%08lx", (*i)++, addr); #endif return true; } -__pinned_func -static void unwind_stack(const struct arch_esf *esf) +static ALWAYS_INLINE void unwind_stack(const struct arch_esf *esf) { int i = 0;