From f8197c244652abd9b1488aec9f8245b2a62692c8 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 16 Apr 2021 13:59:37 +0300 Subject: [PATCH] Fix problem with panic handler with gdbstubs. --- components/esp_gdbstub/include/esp_gdbstub.h | 1 + .../private_include/esp_gdbstub_common.h | 1 + components/esp_gdbstub/src/gdbstub.c | 3 +- .../esp_gdbstub/xtensa/esp_gdbstub_arch.h | 1 - components/esp_system/panic.c | 93 +++++++------------ 5 files changed, 38 insertions(+), 61 deletions(-) diff --git a/components/esp_gdbstub/include/esp_gdbstub.h b/components/esp_gdbstub/include/esp_gdbstub.h index d896e77ffc..f1e7921de6 100644 --- a/components/esp_gdbstub/include/esp_gdbstub.h +++ b/components/esp_gdbstub/include/esp_gdbstub.h @@ -19,6 +19,7 @@ extern "C" { #endif void esp_gdbstub_init(void); +void esp_gdbstub_panic_handler(void *frame); #ifdef __cplusplus } diff --git a/components/esp_gdbstub/private_include/esp_gdbstub_common.h b/components/esp_gdbstub/private_include/esp_gdbstub_common.h index cb3d341c32..d9f261c9d2 100644 --- a/components/esp_gdbstub/private_include/esp_gdbstub_common.h +++ b/components/esp_gdbstub/private_include/esp_gdbstub_common.h @@ -18,6 +18,7 @@ #include #include +#include "gdbstub_target_config.h" #include "esp_gdbstub_arch.h" #include "sdkconfig.h" diff --git a/components/esp_gdbstub/src/gdbstub.c b/components/esp_gdbstub/src/gdbstub.c index b58fec135e..993d5e9e6b 100644 --- a/components/esp_gdbstub/src/gdbstub.c +++ b/components/esp_gdbstub/src/gdbstub.c @@ -45,8 +45,9 @@ static esp_gdbstub_gdb_regfile_t *gdb_local_regfile = &s_scratch.regfile; /** * @breef panic handler */ -void esp_gdbstub_panic_handler(esp_gdbstub_frame_t *frame) +void esp_gdbstub_panic_handler(void *in_frame) { + esp_gdbstub_frame_t* frame = (esp_gdbstub_frame_t*)in_frame; #ifndef CONFIG_ESP_GDBSTUB_SUPPORT_TASKS esp_gdbstub_frame_to_regfile(frame, &s_scratch.regfile); #else diff --git a/components/esp_gdbstub/xtensa/esp_gdbstub_arch.h b/components/esp_gdbstub/xtensa/esp_gdbstub_arch.h index 18b119cb3f..4730e0a124 100644 --- a/components/esp_gdbstub/xtensa/esp_gdbstub_arch.h +++ b/components/esp_gdbstub/xtensa/esp_gdbstub_arch.h @@ -15,7 +15,6 @@ #pragma once #include #include "freertos/xtensa_context.h" -#include "gdbstub_target_config.h" #ifdef __cplusplus extern "C" { diff --git a/components/esp_system/panic.c b/components/esp_system/panic.c index baa14dba80..7a55653a38 100644 --- a/components/esp_system/panic.c +++ b/components/esp_system/panic.c @@ -30,7 +30,6 @@ #include "esp_private/panic_internal.h" #include "port/panic_funcs.h" -#include "esp_rom_sys.h" #include "sdkconfig.h" @@ -59,10 +58,6 @@ #include "esp_gdbstub.h" #endif -#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG -#include "hal/usb_serial_jtag_ll.h" -#endif - bool g_panic_abort = false; static char *s_panic_abort_details = NULL; @@ -73,13 +68,13 @@ static wdt_hal_context_t wdt1_context = {.inst = WDT_MWDT1, .mwdt_dev = &TIMERG1 #if !CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT #if CONFIG_ESP_CONSOLE_UART -static uart_hal_context_t s_panic_uart = { .dev = CONFIG_ESP_CONSOLE_UART_NUM == 0 ? &UART0 :&UART1 }; +static uart_hal_context_t s_panic_uart = { .dev = CONFIG_ESP_CONSOLE_UART_NUM == 0 ? &UART0 : &UART1 }; void panic_print_char(const char c) { uint32_t sz = 0; - while (!uart_hal_get_txfifo_len(&s_panic_uart)); - uart_hal_write_txfifo(&s_panic_uart, (uint8_t *) &c, 1, &sz); + while(!uart_hal_get_txfifo_len(&s_panic_uart)); + uart_hal_write_txfifo(&s_panic_uart, (uint8_t*) &c, 1, &sz); } #endif // CONFIG_ESP_CONSOLE_UART @@ -92,27 +87,6 @@ void panic_print_char(const char c) } #endif // CONFIG_ESP_CONSOLE_USB_CDC -#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG -//Timeout; if there's no host listening, the txfifo won't ever -//be writable after the first packet. - -#define USBSERIAL_TIMEOUT_MAX_US 50000 -static int s_usbserial_timeout = 0; - -void panic_print_char(const char c) -{ - while (!usb_serial_jtag_ll_txfifo_writable() && s_usbserial_timeout < (USBSERIAL_TIMEOUT_MAX_US / 100)) { - esp_rom_delay_us(100); - s_usbserial_timeout++; - } - if (usb_serial_jtag_ll_txfifo_writable()) { - usb_serial_jtag_ll_write_txfifo((const uint8_t *)&c, 1); - s_usbserial_timeout = 0; - } -} -#endif //CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG - - #if CONFIG_ESP_CONSOLE_NONE void panic_print_char(const char c) { @@ -122,7 +96,7 @@ void panic_print_char(const char c) void panic_print_str(const char *str) { - for (int i = 0; str[i] != 0; i++) { + for(int i = 0; str[i] != 0; i++) { panic_print_char(str[i]); } } @@ -171,7 +145,7 @@ static void reconfigure_all_wdts(void) //Reconfigure TWDT (Timer Group 0) wdt_hal_init(&wdt0_context, WDT_MWDT0, MWDT0_TICK_PRESCALER, false); //Prescaler: wdt counts in ticks of TG0_WDT_TICK_US wdt_hal_write_protect_disable(&wdt0_context); - wdt_hal_config_stage(&wdt0_context, 0, 1000 * 1000 / MWDT0_TICKS_PER_US, WDT_STAGE_ACTION_RESET_SYSTEM); //1 second before reset + wdt_hal_config_stage(&wdt0_context, 0, 1000*1000/MWDT0_TICKS_PER_US, WDT_STAGE_ACTION_RESET_SYSTEM); //1 second before reset wdt_hal_enable(&wdt0_context); wdt_hal_write_protect_enable(&wdt0_context); @@ -216,29 +190,29 @@ void esp_panic_handler(panic_info_t *info) info->exception = PANIC_EXCEPTION_ABORT; } - /* - * For any supported chip, the panic handler prints the contents of panic_info_t in the following format: - * - * - * Guru Meditation Error: Core (). - *
- * - * - * - * - * - * - * ---------------------------------------------------------------------------------------- - * core - core where exception was triggered - * exception - what kind of exception occured - * description - a short description regarding the exception that occured - * details - more details about the exception - * state - processor state like register contents, and backtrace - * elf_info - details about the image currently running - * - * NULL fields in panic_info_t are not printed. - * - * */ + /* + * For any supported chip, the panic handler prints the contents of panic_info_t in the following format: + * + * + * Guru Meditation Error: Core (). + *
+ * + * + * + * + * + * + * ---------------------------------------------------------------------------------------- + * core - core where exception was triggered + * exception - what kind of exception occured + * description - a short description regarding the exception that occured + * details - more details about the exception + * state - processor state like register contents, and backtrace + * elf_info - details about the image currently running + * + * NULL fields in panic_info_t are not printed. + * + * */ if (info->reason) { panic_print_str("Guru Meditation Error: Core "); panic_print_dec(info->core); @@ -322,7 +296,7 @@ void esp_panic_handler(panic_info_t *info) wdt_hal_disable(&rtc_wdt_ctx); wdt_hal_write_protect_enable(&rtc_wdt_ctx); panic_print_str("Entering gdb stub now.\r\n"); - esp_gdbstub_panic_handler((esp_gdbstub_frame_t *)info->frame); + esp_gdbstub_panic_handler(info->frame); #else #if CONFIG_ESP_COREDUMP_ENABLE static bool s_dumping_core; @@ -347,7 +321,8 @@ void esp_panic_handler(panic_info_t *info) #if CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT || CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT if (esp_reset_reason_get_hint() == ESP_RST_UNKNOWN) { - switch (info->exception) { + switch (info->exception) + { case PANIC_EXCEPTION_IWDT: esp_reset_reason_set_hint(ESP_RST_INT_WDT); break; @@ -373,10 +348,10 @@ void esp_panic_handler(panic_info_t *info) } -void __attribute__((noreturn,no_sanitize_undefined)) panic_abort(const char *details) +void __attribute__((noreturn)) panic_abort(const char *details) { g_panic_abort = true; - s_panic_abort_details = (char *) details; + s_panic_abort_details = (char*) details; #if CONFIG_APPTRACE_ENABLE #if CONFIG_SYSVIEW_ENABLE @@ -388,7 +363,7 @@ void __attribute__((noreturn,no_sanitize_undefined)) panic_abort(const char *det #endif *((int *) 0) = 0; // NOLINT(clang-analyzer-core.NullDereference) should be an invalid operation on targets - while (1); + while(1); } /* Weak versions of reset reason hint functions.