Unable to debug ESP8266 in CLion IDE

First time poster. I’m not too familiar with platformIO yet.

I’m trying to setup CLion IDE to do building and debugging of my Arduino/ESP8266 projects. The PlatformIO instructions and community comments have got me to the point where Building and Uploading works.

I think I have a memory corruption issue causing an exception that can’t easily be debugged using Serial prints. There is a CLion configuration called “PlatformIO Debug”, but when I try to run this I get an instant error “Debugger process finished with exit code 1”.

Can anyone offer any advice on how I can get this working please? Ideally, I’d like to be able to break and step through the code.

I’m on a Mac. Here’s my ini file:

platform = espressif8266
board = esp12e
framework = arduino
build_flags = -D ARDUINO_ESP8266_GENERIC
lib_deps = 
	adafruit/Adafruit SSD1306@^2.4.2
	adafruit/Adafruit GFX Library@^1.10.4
	adafruit/Adafruit BMP085 Library@^1.2.0


PlatformIO does not support debugging ESP8266 targets out of the box. (NodeMCU 1.0 (ESP-12E Module) — PlatformIO latest documentation) due to lacking good HW + SW support.

Also see PIO Unified Debugger - ESP8266 - #4 by ivankravets

Do you have a working JTAG debugger or GDB stub setup that allows otherwise? If yes we’d very interested in that.

If an exception occurs that prints a stacktrace, you can use a monitor_filters and build_type value to get some info.

build_type = debug
monitor_filters = esp8266_exception_decoder

in the platformio.ini, re-flashing and restarting the serial monitor should show the decode of the exception when it occurrs.

Otherwise PlatformIO features a static code analyzer (aka cppcheck) that can catch a lot of bugs. You can run that over your project in the VSCode PIO Home → Inspect screen.

1 Like

Thanks for the very quick response Max! I’ll investigate your suggestions and reply here with the results.

I did manage to decode the stacktrace using a plugin tool for Arduino IDE, but as is often the case with memory corruption, you find where it was noticed and not where it occurred. Good call on using static code analysis tools. Is there a way I can run it on the command line, or as part of a standard build in CLion? I tried updating the config but didn’t see anything different in the build output. I would guess it needs to be a specific build? I’m not keen on learning another IDE (VSCode) just for this, but if there’s no other option…

Sorry, no JTAG or GDB here :frowning: Really wish there was!

pio check is available on the commandline, and also accessible via the normal Tools → PlatformIO → Check menu.


Notice that you can also launch PlatofrmIO → Home which then opens the same website VSCode is looking at. From there, Inspect is accessible too.

Caveat: Sometimes the pio check command requires the --skip-packages option because cppcheck otherwise chokes on framework files…

Note: If you are working with the Arduino-ESP8266 core and are experiencing a memory corruption in the heap, the core has facilities to detect that, using special heap wrappers.

So you can catch the culprit in the act. Can be activated with e.g. build_flags = -DUMM_POISON_CHECK in the platformio.ini. Also has a usage manual.

Regarding that I might have a look at what other people have tried before with OpenOCD and JTAG adapters (Using GDB for online debugging ESP8266) and UART-GDB stubs (Using GDB for online debugging ESP8266). Would be interesting if those work well now.