esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
16.09k stars 13.33k forks source link

CONT stack overflow postmortem #9083

Closed mcspr closed 8 months ago

mcspr commented 9 months ago

additionally

Noticed in esp-idf cfg as CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL=y, where Freertos it is a so called 'Method 1' of overflow checking happening right before ctx switch https://www.freertos.org/Stacks-and-stack-overflow-checking.html (also ref. #8666)

simple example like this one usually already offsets a1 when yield() happens, so the newly added check would cause a reset

#include <Arduino.h>

void setup() {
  Serial.begin(115200);
}

void loop() {
  int buf[1048]; // oops
  yield();
  printf("%p %p %p %p\n",
    &buf[0], &buf[1], &buf[2], &buf[3]);
}

and it should generate more useful info as the result

Stack overflow detected
sp: 3fffef28 end: 3fffffd0 offset: 0000

ctx: cont
0x4010015c: ets_post at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/core_esp8266_main.cpp:243
0x402017f5: esp_suspend_within_cont at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/core_esp8266_main.cpp:121
(inlined by) __yield at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/core_esp8266_main.cpp:193
0x40201052: loop at /home/runner/dev/stack_overflow_test/src/main.cpp:10
0x402016da: loop_task(ETSEventTag*) at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/core_esp8266_main.cpp:279
0x40105245: call_user_start_local at ??:?
0x4010524b: call_user_start_local at ??:?
0x4010000d: call_user_start at ??:?
0x401000ab: app_entry_redefinable at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/core_esp8266_main.cpp:391
0x40225e1e: cont_ret at cont.S.o:?
0x40202761: uart_flush at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/uart.cpp:583
0x401009d8: malloc at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/umm_malloc/umm_malloc.cpp:914
0x40202ab0: uart_init at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/uart.cpp:715
0x402029d6: uart_init at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/uart.cpp:707
0x40202c2c: uart_set_debug at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/uart.cpp:989
0x402012b0: HardwareSerial::begin(unsigned long, SerialConfig, SerialMode, unsigned char, bool) at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/HardwareSerial.cpp:56
0x402018b0: loop_wrapper() at /home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/core_esp8266_main.cpp:263
0x40100d4d: cont_wrapper at ??:?
0x40201052: loop at /home/runner/dev/stack_overflow_test/src/main.cpp:10
> sed -ne 10p src/main.cpp
  printf("%p %p %p %p\n",