Skip to content

Commit 3cc64f7

Browse files
d-a-vearlephilhower
authored andcommitted
Fix raise_exception() (#6288)
* workaround when an exceptin occurs while in an ISR * tuning for gdb * remove dead code and rename defines/variables * per reviews: naming, handle "unhandled return" case * fix reset message
1 parent 1c68d02 commit 3cc64f7

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

cores/esp8266/core_esp8266_postmortem.cpp

+27-15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ static void uart0_write_char_d(char c);
5252
static void uart1_write_char_d(char c);
5353
static void print_stack(uint32_t start, uint32_t end);
5454

55+
// using numbers different from "REASON_" in user_interface.h (=0..6)
56+
enum rst_reason_sw
57+
{
58+
REASON_USER_SWEXCEPTION_RST = 254
59+
};
60+
static int s_user_reset_reason = REASON_DEFAULT_RST;
61+
5562
// From UMM, the last caller of a malloc/realloc/calloc which failed:
5663
extern void *umm_last_fail_alloc_addr;
5764
extern int umm_last_fail_alloc_size;
@@ -86,24 +93,20 @@ void __wrap_system_restart_local() {
8693
register uint32_t sp asm("a1");
8794
uint32_t sp_dump = sp;
8895

89-
if (gdb_present()) {
90-
/* When GDBStub is present, exceptions are handled by GDBStub,
91-
but Soft WDT will still call this function.
92-
Trigger an exception to break into GDB.
93-
TODO: check why gdb_do_break() or asm("break.n 0") do not
94-
break into GDB here. */
95-
raise_exception();
96-
}
97-
9896
struct rst_info rst_info;
9997
memset(&rst_info, 0, sizeof(rst_info));
100-
system_rtc_mem_read(0, &rst_info, sizeof(rst_info));
101-
if (rst_info.reason != REASON_SOFT_WDT_RST &&
102-
rst_info.reason != REASON_EXCEPTION_RST &&
103-
rst_info.reason != REASON_WDT_RST)
98+
if (s_user_reset_reason == REASON_DEFAULT_RST)
10499
{
105-
return;
100+
system_rtc_mem_read(0, &rst_info, sizeof(rst_info));
101+
if (rst_info.reason != REASON_SOFT_WDT_RST &&
102+
rst_info.reason != REASON_EXCEPTION_RST &&
103+
rst_info.reason != REASON_WDT_RST)
104+
{
105+
rst_info.reason = REASON_DEFAULT_RST;
106+
}
106107
}
108+
else
109+
rst_info.reason = s_user_reset_reason;
107110

108111
// TODO: ets_install_putc1 definition is wrong in ets_sys.h, need cast
109112
ets_install_putc1((void *)&uart_write_char_d);
@@ -128,6 +131,9 @@ void __wrap_system_restart_local() {
128131
else if (rst_info.reason == REASON_SOFT_WDT_RST) {
129132
ets_printf_P(PSTR("\nSoft WDT reset\n"));
130133
}
134+
else {
135+
ets_printf_P(PSTR("\nGeneric Reset\n"));
136+
}
131137

132138
uint32_t cont_stack_start = (uint32_t) &(g_pcont->stack);
133139
uint32_t cont_stack_end = (uint32_t) g_pcont->stack_end;
@@ -222,7 +228,13 @@ static void uart1_write_char_d(char c) {
222228
}
223229

224230
static void raise_exception() {
225-
__asm__ __volatile__ ("syscall");
231+
if (gdb_present())
232+
__asm__ __volatile__ ("syscall"); // triggers GDB when enabled
233+
234+
s_user_reset_reason = REASON_USER_SWEXCEPTION_RST;
235+
ets_printf_P(PSTR("\nUser exception (panic/abort/assert)"));
236+
__wrap_system_restart_local();
237+
226238
while (1); // never reached, needed to satisfy "noreturn" attribute
227239
}
228240

0 commit comments

Comments
 (0)