Skip to content

Commit

Permalink
x86: skip printing args when unwinding stack
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dcpleung authored and nashif committed Sep 9, 2024
1 parent 968f674 commit 5ec6024
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions arch/x86/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;

Expand Down

0 comments on commit 5ec6024

Please sign in to comment.