But it turns out that life debugging wasn’t even necessary: you can use the crash information also offline to figure out what function was responsible for the crash!
Preparing the binary
These days I am using the platform.io environment with the Atom editor to do my ESP8266 development. In order to have enough information in the binary you have to add some flags to the platformio.ini. In the section for your target platform add:
build_flags = -Og -ggdb -DDEBUG_ESP_PORT=Serial
which will cause the compiler to create a binary containing the symbol information required for debugging. Save it and make sure that the whole workspace gets re-compiled.. Upload it, start the serial console and provoke the crash:
Fatal exception 0(IllegalInstructionCause): epc1=0x4020188c, epc2=0x00000000
The interesting part here is the epc1 address, which is the program counter.
Finding the culprit
The next step was to figure out where the debugger was installed for the platformio environment.
On a Mac you can (currently) find it here:
Now you can start it by telling it where your binary is:
(assuming that you are in the root of your project folder). The debugger should great you with:
Reading symbols from .pioenvs/nodemcuv2/firmware.elf...done. (gdb)
Now you can enter the epc1 pointer from above and get a pretty clear picture where the problem occured:
(gdb) info line *0x4020188c Line 116 of ".pioenvs/nodemcuv2/FrameworkArduino/Tone.cpp" starts at address 0x4020188c and ends at 0x40201891
Tone.cpp was the culprit! I quickly headed over to the Arduino/ESP8266 github repo and searched for problems with Tone and found the following issue: https://github.com/esp8266/Arduino/issues/1761
Even (or even more) on embedded devices debugging is a very powerful tool. But it might take some time to set it up properly. While I still did not succeed in doing operation on the open heart (life debugging) it wasn’t even necessary in this case. Having a program counter pointing me to the location of the crash helped already a lot. After debugging, don’t forget to remove the flags in platformio or you will miss compiler optimizations…
A ridiculous amount of coffee was consumed in the process of building this project. Add some fuel if you'd like to keep me going!