Skip to content

Commit

Permalink
debug: EXCEPTION_STACK_TRACE should depend on arch Kconfigs
Browse files Browse the repository at this point in the history
Fix the dependencies of `CONFIG_EXCEPTION_STACK_TRACE`:
- Architecture-specific Kconfig, i.e.
  `X86_EXCEPTION_STACK_TRACE`, will be enabled automatically
  when all the dependencies are met.
- `EXCEPTION_STACK_TRACE` depends on architecture-specific
  Kconfig to be enabled.
- The stack trace implementations should be compiled only if
  user enables `CONFIG_EXCEPTION_STACK_TRACE`.

Signed-off-by: Yong Cong Sin <[email protected]>
  • Loading branch information
ycsin authored and carlescufi committed Jun 3, 2024
1 parent 190777d commit 02770ad
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions arch/arm64/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void esf_dump(const z_arch_esf_t *esf)
LOG_ERR("x18: 0x%016llx lr: 0x%016llx", esf->x18, esf->lr);
}

#ifdef CONFIG_ARM64_EXCEPTION_STACK_TRACE
#ifdef CONFIG_EXCEPTION_STACK_TRACE
static void esf_unwind(const z_arch_esf_t *esf)
{
/*
Expand Down Expand Up @@ -363,9 +363,9 @@ void z_arm64_fatal_error(unsigned int reason, z_arch_esf_t *esf)
esf_dump(esf);
}

#ifdef CONFIG_ARM64_EXCEPTION_STACK_TRACE
#ifdef CONFIG_EXCEPTION_STACK_TRACE
esf_unwind(esf);
#endif /* CONFIG_ARM64_EXCEPTION_STACK_TRACE */
#endif /* CONFIG_EXCEPTION_STACK_TRACE */
#endif /* CONFIG_EXCEPTION_DEBUG */

z_fatal_error(reason, esf);
Expand Down
1 change: 0 additions & 1 deletion arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ config RISCV_ALWAYS_SWITCH_THROUGH_ECALL
config RISCV_EXCEPTION_STACK_TRACE
bool
default y
depends on EXCEPTION_STACK_TRACE
imply THREAD_STACK_INFO
help
Internal config to enable runtime stack traces on fatal exceptions.
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ zephyr_library_sources_ifdef(CONFIG_RISCV_PMP pmp.c pmp.S)
zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE tls.c)
zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S)
zephyr_library_sources_ifdef(CONFIG_SEMIHOST semihost.c)
zephyr_library_sources_ifdef(CONFIG_RISCV_EXCEPTION_STACK_TRACE stacktrace.c)
zephyr_library_sources_ifdef(CONFIG_EXCEPTION_STACK_TRACE stacktrace.c)
zephyr_linker_sources(ROM_START SORT_KEY 0x0vectors vector_table.ld)
2 changes: 1 addition & 1 deletion arch/riscv/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ FUNC_NORETURN void z_riscv_fatal_error_csf(unsigned int reason, const z_arch_esf
LOG_ERR("");
}

if (IS_ENABLED(CONFIG_RISCV_EXCEPTION_STACK_TRACE) && (esf != NULL)) {
if (IS_ENABLED(CONFIG_EXCEPTION_STACK_TRACE) && (esf != NULL)) {
z_riscv_unwind_stack(esf);
}

Expand Down
1 change: 0 additions & 1 deletion arch/x86/core/Kconfig.ia32
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ config X86_EXCEPTION_STACK_TRACE
bool
default y
select DEBUG_INFO
depends on EXCEPTION_STACK_TRACE
depends on !OMIT_FRAME_POINTER
help
Internal config to enable runtime stack traces on fatal exceptions.
Expand Down
1 change: 0 additions & 1 deletion arch/x86/core/Kconfig.intel64
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ config X86_EXCEPTION_STACK_TRACE
bool
default y
select DEBUG_INFO
depends on EXCEPTION_STACK_TRACE
depends on !OMIT_FRAME_POINTER
depends on NO_OPTIMIZATIONS
help
Expand Down
12 changes: 6 additions & 6 deletions arch/x86/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static inline uintptr_t esf_get_code(const z_arch_esf_t *esf)
#endif
}

#if defined(CONFIG_X86_EXCEPTION_STACK_TRACE)
#if defined(CONFIG_EXCEPTION_STACK_TRACE)
struct stack_frame {
uintptr_t next;
uintptr_t ret_addr;
Expand Down Expand Up @@ -186,7 +186,7 @@ static void unwind_stack(uintptr_t base_ptr, uint16_t cs)
base_ptr = frame->next;
}
}
#endif /* CONFIG_X86_EXCEPTION_STACK_TRACE */
#endif /* CONFIG_EXCEPTION_STACK_TRACE */

static inline uintptr_t get_cr3(const z_arch_esf_t *esf)
{
Expand Down Expand Up @@ -226,11 +226,11 @@ static void dump_regs(const z_arch_esf_t *esf)
LOG_ERR("RSP: 0x%016lx RFLAGS: 0x%016lx CS: 0x%04lx CR3: 0x%016lx",
esf->rsp, esf->rflags, esf->cs & 0xFFFFU, get_cr3(esf));

#ifdef CONFIG_X86_EXCEPTION_STACK_TRACE
#ifdef CONFIG_EXCEPTION_STACK_TRACE
LOG_ERR("call trace:");
#endif
LOG_ERR("RIP: 0x%016lx", esf->rip);
#ifdef CONFIG_X86_EXCEPTION_STACK_TRACE
#ifdef CONFIG_EXCEPTION_STACK_TRACE
unwind_stack(esf->rbp, esf->cs);
#endif
}
Expand All @@ -245,11 +245,11 @@ static void dump_regs(const z_arch_esf_t *esf)
LOG_ERR("EFLAGS: 0x%08x CS: 0x%04x CR3: 0x%08lx", esf->eflags,
esf->cs & 0xFFFFU, get_cr3(esf));

#ifdef CONFIG_X86_EXCEPTION_STACK_TRACE
#ifdef CONFIG_EXCEPTION_STACK_TRACE
LOG_ERR("call trace:");
#endif
LOG_ERR("EIP: 0x%08x", esf->eip);
#ifdef CONFIG_X86_EXCEPTION_STACK_TRACE
#ifdef CONFIG_EXCEPTION_STACK_TRACE
unwind_stack(esf->ebp, esf->cs);
#endif
}
Expand Down
3 changes: 3 additions & 0 deletions subsys/debug/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ config SYMTAB
config EXCEPTION_STACK_TRACE
bool "Attempt to print stack traces upon exceptions"
default y
depends on (X86_EXCEPTION_STACK_TRACE || \
ARM64_EXCEPTION_STACK_TRACE || \
RISCV_EXCEPTION_STACK_TRACE)
help
If the architecture fatal handling code supports it, attempt to
print a stack trace of function memory addresses when an
Expand Down

0 comments on commit 02770ad

Please sign in to comment.