Decoding ESP32 back trace

Any developer working with ESP32 has most likely came across with one of those infamous “Guru Meditation Error” messages when the execution crashes. They look like this:

Basically, a cryptic output with a bunch of addresses that are begging to be decoded so one can even start make sense out of it! 😯 😥

It could be a limitation of mine, but I’ve struggled a long time with these messages and what to do with them. There must be a way to decode these, right?! After a long search I’ve found that such tool exists and it’s readily available in the IDF SDK. Surprisingly (again this could be my fault 😀 ) I haven’t seen it highlighted, let alone mentioned, in IDF documentation about debugging…

The tool goes by the (somewhat obvious) name of xtensa-esp32-elf-addr2line. It gets installed in the xtensa tools folder, along with the GCC compiler. There is one specific for each ESP32 series, so you have xtensa-esp32s2-elf-addr2line for ESP32-S2 and so on.

As inputs, the tool takes the executable file (in ELF format) and the backtrace information from the guru meditation error message. This bit here:

It also accepts various options to format the decoded output, which can be listed using the usual -h option that will output the help information.

For the sake of the example, this is the full command line that I’m using to decode the above back trace data:

xtensa-esp32-elf-addr2line -aspCfire "my_executable_file.elf" 0x400f426e:0x3ffc5cb00x400f3a11:0x3ffc5cd0 0x400ec290:0x3ffc5cf0 0x400ec38b:0x3ffc5d40 0x400da253:0x3ffc5d60 0x400da321:0x3ffc5d80 0x400d8384:0x3ffc5da0 0x400d901d:0x3ffc5dc0 0x400e3575:0x3ffc5e00 0x400f88da:0x3ffc5e30 0x400f700d:0x3ffc5e50

And here’s the decoded output, which (out of curiosity) belongs to a nasty bug that we’ve chasing for a long time in .NET nanoFramework.

Now we have a nice stack trace with the call thread and, hopefully, a good starting point to start investigating what could be causing the fault.

VS Code Task for .NET nanoFramework

To make life easier for developers working in .NET nanoFramework a VS Code Task was added to the toolbox which makes decoding an ESP32 backtrace very easy.

Assuming that the Tasks template that is provided in nf-interpreter repository as been setup, the Task can be found under the name Decode ESP32 backtrace.

Next step is to choose the ESP32 series (it defaults to ESP32).

Follows the path to the executable file to decode against. It defaults to the nanoCLR.elf that’s supposed to be found in the build directory after a successful build. In case the backtrace comes from a different executable, it’s a matter of replacing the default path with the full path to the respective file.

Last step is to enter the backtrace data coming from the guru meditation error output. Mind that only the backtrace line is required! Adding more than that won’t work.

The output with the stack trace shows in the console pane. Like this:

And this is it: simple and effective!

Now you can decode Guru Meditation Error messages from ESP32.

And have fun with .NET nanoFramework! 😉