From 75f9391a727d191397f04e812fd174f1c90e7dc6 Mon Sep 17 00:00:00 2001 From: M Hightower <27247790+mhightower83@users.noreply.github.com> Date: Sun, 30 Apr 2023 07:55:10 -0700 Subject: [PATCH 1/2] Soft WDT: detect deliberate infinite loop at Postmortem --- cores/esp8266/core_esp8266_postmortem.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/core_esp8266_postmortem.cpp b/cores/esp8266/core_esp8266_postmortem.cpp index c367deeced..a40e406df3 100644 --- a/cores/esp8266/core_esp8266_postmortem.cpp +++ b/cores/esp8266/core_esp8266_postmortem.cpp @@ -181,7 +181,13 @@ static void postmortem_report(uint32_t sp_dump) { exccause, epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc); } else if (rst_info.reason == REASON_SOFT_WDT_RST) { - ets_printf_P(PSTR("\nSoft WDT reset\n")); + ets_printf_P(PSTR("\nSoft WDT reset")); + const char infinite_loop[] = { 0x06, 0xff, 0xff }; // loop: j loop + if (0 == memcmp_P((void*)rst_info.epc1, infinite_loop, 3u)) { + // The SDK is riddled with these. They are usually preceded by an ets_printf. + ets_printf_P(PSTR(" - deliberate infinite loop detected")); + } + ets_putc('\n'); ets_printf_P(PSTR("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n"), rst_info.exccause, /* Address executing at time of Soft WDT level-1 interrupt */ rst_info.epc1, 0, 0, 0, 0); } From be94e094e66673010a1c64dd70981fde12654c82 Mon Sep 17 00:00:00 2001 From: M Hightower <27247790+mhightower83@users.noreply.github.com> Date: Sun, 30 Apr 2023 14:41:07 -0700 Subject: [PATCH 2/2] corrected argument order for memcmp_P --- cores/esp8266/core_esp8266_postmortem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/core_esp8266_postmortem.cpp b/cores/esp8266/core_esp8266_postmortem.cpp index a40e406df3..123158c48a 100644 --- a/cores/esp8266/core_esp8266_postmortem.cpp +++ b/cores/esp8266/core_esp8266_postmortem.cpp @@ -183,7 +183,7 @@ static void postmortem_report(uint32_t sp_dump) { else if (rst_info.reason == REASON_SOFT_WDT_RST) { ets_printf_P(PSTR("\nSoft WDT reset")); const char infinite_loop[] = { 0x06, 0xff, 0xff }; // loop: j loop - if (0 == memcmp_P((void*)rst_info.epc1, infinite_loop, 3u)) { + if (0 == memcmp_P(infinite_loop, (PGM_VOID_P)rst_info.epc1, 3u)) { // The SDK is riddled with these. They are usually preceded by an ets_printf. ets_printf_P(PSTR(" - deliberate infinite loop detected")); }