Skip to content

Commit ee0cc5a

Browse files
Jyri Sarhastephanosio
authored andcommitted
arch: xtensa: Add XTENSA_BACKTRACE_EXCEPTION_DUMP_HOOK Kconfig option
Add XTENSA_BACKTRACE_EXCEPTION_DUMP_HOOK Kconfig option for sending backtrace through exception dump hook. This commit also disables the printk backtrace dumping if Kconfig option EXCEPTION_DUMP_HOOK_ONLY is set. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 8655e64 commit ee0cc5a

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

arch/xtensa/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ config XTENSA_ENABLE_BACKTRACE
3636
help
3737
Enable this config option to print backtrace on panic exception
3838

39+
config XTENSA_BACKTRACE_EXCEPTION_DUMP_HOOK
40+
bool "Send backtrace to exception dump hook"
41+
depends on XTENSA_ENABLE_BACKTRACE && EXCEPTION_DUMP_HOOK
42+
default y if EXCEPTION_DUMP_HOOK_ONLY
43+
help
44+
Enable this option to forward Xtensa panic backtrace output to
45+
exception dump hook.
46+
47+
When EXCEPTION_DUMP_HOOK_ONLY is enabled, this defaults to y to
48+
preserve hook-only backtrace output.
49+
3950
config XTENSA_SMALL_VECTOR_TABLE_ENTRY
4051
bool "Workaround for small vector table entries"
4152
help

arch/xtensa/core/xtensa_backtrace.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "xtensa/corebits.h"
88
#include "xtensa_backtrace.h"
99
#include <zephyr/sys/printk.h>
10+
#include <zephyr/arch/exception.h>
1011
#if defined(CONFIG_SOC_SERIES_ESP32)
1112
#include <esp_memory_utils.h>
1213
#elif defined(CONFIG_SOC_FAMILY_INTEL_ADSP)
@@ -138,11 +139,17 @@ int xtensa_backtrace_print(int depth, int *interrupted_stack)
138139
if (cause != EXCCAUSE_INSTR_PROHIBITED) {
139140
mask = stk_frame.pc & 0xc0000000;
140141
}
142+
#if defined(CONFIG_XTENSA_BACKTRACE_EXCEPTION_DUMP_HOOK)
143+
arch_exception_call_dump_hook("BT 0x%08x:0x%08x ",
144+
xtensa_cpu_process_stack_pc(stk_frame.pc),
145+
stk_frame.sp);
146+
#endif
147+
#if !defined(CONFIG_EXCEPTION_DUMP_HOOK_ONLY)
141148
printk("\r\n\r\nBacktrace:");
142149
printk("0x%08x:0x%08x ",
143150
xtensa_cpu_process_stack_pc(stk_frame.pc),
144151
stk_frame.sp);
145-
152+
#endif
146153
/* Check if first frame is valid */
147154
bool corrupted = !(xtensa_stack_ptr_is_sane(stk_frame.sp) &&
148155
(xtensa_ptr_executable((void *)
@@ -155,18 +162,36 @@ int xtensa_backtrace_print(int depth, int *interrupted_stack)
155162
if (!xtensa_backtrace_get_next_frame(&stk_frame)) {
156163
corrupted = true;
157164
}
165+
#if defined(CONFIG_XTENSA_BACKTRACE_EXCEPTION_DUMP_HOOK)
166+
arch_exception_call_dump_hook("0x%08x:0x%08x ",
167+
xtensa_cpu_process_stack_pc(stk_frame.pc),
168+
stk_frame.sp);
169+
#endif
170+
#if !defined(CONFIG_EXCEPTION_DUMP_HOOK_ONLY)
158171
printk("0x%08x:0x%08x ", xtensa_cpu_process_stack_pc(stk_frame.pc), stk_frame.sp);
172+
#endif
159173
}
160174

161175
/* Print backtrace termination marker */
162176
int ret = 0;
163177

178+
#if defined(CONFIG_XTENSA_BACKTRACE_EXCEPTION_DUMP_HOOK)
179+
if (corrupted) {
180+
arch_exception_call_dump_hook("CORRUPTED");
181+
ret = -1;
182+
} else if (stk_frame.next_pc != 0) { /* Backtrace continues */
183+
arch_exception_call_dump_hook("CONTINUES");
184+
}
185+
arch_exception_call_dump_hook("\n");
186+
#endif
187+
#if !defined(CONFIG_EXCEPTION_DUMP_HOOK_ONLY)
164188
if (corrupted) {
165189
printk(" |<-CORRUPTED");
166190
ret = -1;
167191
} else if (stk_frame.next_pc != 0) { /* Backtrace continues */
168192
printk(" |<-CONTINUES");
169193
}
170194
printk("\r\n\r\n");
195+
#endif
171196
return ret;
172197
}

0 commit comments

Comments
 (0)