I wanted to provide an easy to use Arduino Audio Decoding Library based on libhelix. Unfortunately the ESP32 was crashing w/o any stacktrace and on the desktop it was the first time I was running into Segmentation Faults. I tried to resolve the issue with the help of Google where I found the recommendation

So I used my Arduino Emulator to debug the code on my McBook and on my Raspberry PI (for valgrind).

Unfortunately both of this was just identifying only the location of the symptom and not the root cause!

The breakthru finally came when I discovered the -fsanitize=address compiler option!
I just needed to add the following lines to my CMakeList.txt

set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")

and built the project in debug mode with

cmake -DCMAKE_BUILD_TYPE=Debug ..
make

After starting the debugger, I added the breakpoint on __asan::ReportGenericError to stop the debugger right before the error and to my surprise I found the issue right way!

The example test case can be found on Github.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *