Преглед изворни кода

Merge branch 'bugfix/panic_instrprohibited' into 'master'

esp_system: fix instrprohibited panic backtrace regression

See merge request espressif/esp-idf!13023
Angus Gratton пре 4 година
родитељ
комит
c22eb769e7

+ 1 - 0
components/esp_system/include/esp_debug_helpers.h

@@ -41,6 +41,7 @@ typedef struct {
     uint32_t pc;       /* PC of the current frame */
     uint32_t pc;       /* PC of the current frame */
     uint32_t sp;       /* SP of the current frame */
     uint32_t sp;       /* SP of the current frame */
     uint32_t next_pc;  /* PC of the current frame's caller */
     uint32_t next_pc;  /* PC of the current frame's caller */
+    const void *exc_frame;  /* Pointer to the full frame data structure, if applicable */
 } esp_backtrace_frame_t;
 } esp_backtrace_frame_t;
 
 
 /**
 /**

+ 7 - 4
components/esp_system/port/arch/xtensa/debug_helpers.c

@@ -23,6 +23,8 @@
 #include "soc/cpu.h"
 #include "soc/cpu.h"
 #include "esp_private/panic_internal.h"
 #include "esp_private/panic_internal.h"
 
 
+#include "xtensa/xtensa_context.h"
+
 #include "sdkconfig.h"
 #include "sdkconfig.h"
 
 
 #include "esp_rom_sys.h"
 #include "esp_rom_sys.h"
@@ -75,9 +77,10 @@ esp_err_t IRAM_ATTR esp_backtrace_print_from_frame(int depth, const esp_backtrac
     print_entry(esp_cpu_process_stack_pc(stk_frame.pc), stk_frame.sp, panic);
     print_entry(esp_cpu_process_stack_pc(stk_frame.pc), stk_frame.sp, panic);
 
 
     //Check if first frame is valid
     //Check if first frame is valid
-    bool corrupted = (esp_stack_ptr_is_sane(stk_frame.sp) &&
-                      esp_ptr_executable((void*)esp_cpu_process_stack_pc(stk_frame.pc))) ?
-                      false : true;
+    bool corrupted = !(esp_stack_ptr_is_sane(stk_frame.sp) &&
+                       (esp_ptr_executable((void *)esp_cpu_process_stack_pc(stk_frame.pc)) ||
+                        /* Ignore the first corrupted PC in case of InstrFetchProhibited */
+                        (stk_frame.exc_frame && ((XtExcFrame *)stk_frame.exc_frame)->exccause == EXCCAUSE_INSTR_PROHIBITED)));
 
 
     uint32_t i = (depth <= 0) ? INT32_MAX : depth;
     uint32_t i = (depth <= 0) ? INT32_MAX : depth;
     while (i-- > 0 && stk_frame.next_pc != 0 && !corrupted) {
     while (i-- > 0 && stk_frame.next_pc != 0 && !corrupted) {
@@ -103,7 +106,7 @@ esp_err_t IRAM_ATTR esp_backtrace_print_from_frame(int depth, const esp_backtrac
 esp_err_t IRAM_ATTR esp_backtrace_print(int depth)
 esp_err_t IRAM_ATTR esp_backtrace_print(int depth)
 {
 {
     //Initialize stk_frame with first frame of stack
     //Initialize stk_frame with first frame of stack
-    esp_backtrace_frame_t start;
+    esp_backtrace_frame_t start = { 0 };
     esp_backtrace_get_start(&(start.pc), &(start.sp), &(start.next_pc));
     esp_backtrace_get_start(&(start.pc), &(start.sp), &(start.next_pc));
     return esp_backtrace_print_from_frame(depth, &start, false);
     return esp_backtrace_print_from_frame(depth, &start, false);
 }
 }

+ 1 - 1
components/esp_system/port/arch/xtensa/panic_arch.c

@@ -460,6 +460,6 @@ void panic_set_address(void *f, uint32_t addr)
 void panic_print_backtrace(const void *f, int core)
 void panic_print_backtrace(const void *f, int core)
 {
 {
     XtExcFrame *xt_frame = (XtExcFrame *) f;
     XtExcFrame *xt_frame = (XtExcFrame *) f;
-    esp_backtrace_frame_t frame = {.pc = xt_frame->pc, .sp = xt_frame->a1, .next_pc = xt_frame->a0};
+    esp_backtrace_frame_t frame = {.pc = xt_frame->pc, .sp = xt_frame->a1, .next_pc = xt_frame->a0, .exc_frame = xt_frame};
     esp_backtrace_print_from_frame(100, &frame, true);
     esp_backtrace_print_from_frame(100, &frame, true);
 }
 }