diff --git a/arch/riscv/core/fatal.c b/arch/riscv/core/fatal.c index 7152da2066c..05d7f4c99c3 100644 --- a/arch/riscv/core/fatal.c +++ b/arch/riscv/core/fatal.c @@ -81,6 +81,10 @@ static void unwind_stack(const z_arch_esf_t *esf) uintptr_t ra; struct stackframe *frame; + if (esf == NULL) { + return; + } + LOG_ERR("call trace:"); for (int i = 0; (i < MAX_STACK_FRAMES) && (fp != 0U) && in_stack_bound((uintptr_t)fp);) { @@ -96,6 +100,8 @@ static void unwind_stack(const z_arch_esf_t *esf) } fp = frame->fp; } + + LOG_ERR(""); } #endif /* CONFIG_RISCV_EXCEPTION_STACK_TRACE */ @@ -144,9 +150,6 @@ FUNC_NORETURN void z_riscv_fatal_error_csf(unsigned int reason, const z_arch_esf LOG_ERR(" mepc: " PR_REG, esf->mepc); LOG_ERR("mstatus: " PR_REG, esf->mstatus); LOG_ERR(""); -#ifdef CONFIG_RISCV_EXCEPTION_STACK_TRACE - unwind_stack(esf); -#endif /* CONFIG_RISCV_EXCEPTION_STACK_TRACE */ } if (csf != NULL) { @@ -163,6 +166,11 @@ FUNC_NORETURN void z_riscv_fatal_error_csf(unsigned int reason, const z_arch_esf #endif /* CONFIG_RISCV_ISA_RV32E */ LOG_ERR(""); } + +#ifdef CONFIG_RISCV_EXCEPTION_STACK_TRACE + unwind_stack(esf); +#endif /* CONFIG_RISCV_EXCEPTION_STACK_TRACE */ + #endif /* CONFIG_EXCEPTION_DEBUG */ z_fatal_error(reason, esf); CODE_UNREACHABLE;