Crash backtrace analysis for Arduino IDE/ESP32

If you're got your Arduino ESP32 sketch crashing with a message similar to this:

Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
...
Backtrace: 0x400d2606:0x3ffc91e0 0x400d334b:0x3ffc9200 0x400d354f:0x3ffc92a0 0x400d40bb:0x3ffc9330 0x400887a1:0x3ffc9b50
Rebooting...

Notice the Backtrace: BACKTRACE_ADDRESSES line? It points to the place where the crash has happened. That line is not human-readable. It must be symbolised and converted into the file name/line number list. This is how to do it.

Step 1. Find the xtensa-esp32-elf-addr2line utility

This utility comes with the Arduino's support package for Espressif. Seach for it in the Arduino installation directory. For example, on Macos this is $HOME/Library/Arduino15. On your system, it could be in a different location.

Step 2. Find your firmware .elf file

This .elf file is produced by the firmware build process. If you're using Arduino IDE, search in the temporary folder for the file called YOUR_SKETCH_NAME.ino.elf.

If you're using ESP-IDF, the .elf file is in the build/ directory, together with the firmware .bin file.

Step 3. Symbolise backtrace

Start command prompt (or terminal on Mac / Linux), and enter the following command (note on Windows it is xtensa-esp32-elf-addr2line.exe):

xtensa-esp32-elf-addr2line  -pfiaC -e ELF_FILE BACKTRACE_ADDRESSES

Here is an example for Macos:

$ /Users/lsm/Library/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-addr2line \
 -pfiaC -e \
 /var/folders//bh/y02gkfp16bn42q1t79rf_ty80000gn/T/arduino_build_936069/sketch_sep23a.ino.elf \
 0x400d2606:0x3ffc91e0 0x400d334b:0x3ffc9200 0x400d354f:0x3ffc92a0 0x400d40bb:0x3ffc9330 0x400887a1:0x3ffc9b50

0x400d334b: fsput at /Users/lsm/src/alib/rpc.c:233
0x400d354f: jsonrpc_ctx_process at /Users/lsm/src/alib/mjson.c:869
0x400d40bb: onMessage at /Users/lsm/src/alib/mDash.c:129
 (inlined by) mDashTask at /Users/lsm/src/alib/mDash.c:235