Skip to content

Commit 5559729

Browse files
Dump faulting function PC in stack overflow
Report a fake exception to have the exception decoder print the actual faulting function. This won't tell you where in the function the issue happened, but it will tell you the function name first and foremost.
1 parent 2c99453 commit 5559729

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cores/esp8266/core_esp8266_postmortem.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ static const char* s_panic_what = 0;
4545
static bool s_abort_called = false;
4646
static const char* s_unhandled_exception = NULL;
4747

48+
static uint32_t s_stacksmash_addr = 0;
49+
4850
void abort() __attribute__((noreturn));
4951
static void uart_write_char_d(char c);
5052
static void uart0_write_char_d(char c);
@@ -150,6 +152,8 @@ void __wrap_system_restart_local() {
150152
}
151153
else if (rst_info.reason == REASON_USER_STACK_SMASH) {
152154
ets_printf_P(PSTR("\nStack overflow detected.\n"));
155+
ets_printf_P(PSTR("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n"),
156+
5 /* Alloca exception, closest thing to stack fault*/, s_stacksmash_addr, 0, 0, 0, 0);
153157
}
154158
else {
155159
ets_printf_P(PSTR("\nGeneric Reset\n"));
@@ -299,6 +303,8 @@ void __stack_chk_fail(void) {
299303
s_user_reset_reason = REASON_USER_STACK_SMASH;
300304
ets_printf_P(PSTR("\nPANIC: Stack overrun"));
301305

306+
s_stacksmash_addr = (uint32_t)__builtin_return_address(0);
307+
302308
if (gdb_present())
303309
__asm__ __volatile__ ("syscall"); // triggers GDB when enabled
304310

0 commit comments

Comments
 (0)