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