GDB on Eclipse

By: Gil Pinheiro

While it isn’t strictly required to have a good debugger, we can get a lot done quickly with greater confidence if we have one at our disposal. Dealing with the ESP8266 is hard enough without being able to quickly and easily test hypothesis and verify things are where they should be.

I spent a good deal of time getting GDB up and running using the espressif gdbstub, and the result really paid off when I was implementing rboot into our project. The ability to poke and prod on live hardware was worth the time it took to get up and running.

Ryan is used to debugging from eclipse, so I wanted to make sure that worked. Unfortunately, that ended up being quite an ordeal. Despite having a huge variety of GDB options, each one always ended in some dead end. I’ll outline what worked, but there are definitely caveats.

Step-by-Step

I’ve tested with a variety of different eclipse versions, but for this document, I’ll stick with the eclipse 4.7 (“oxygen”). Install CDT, and make sure you've got the gdb-related plugins installed.

screenshot
Open the debug configuration settings.
screenshot
Create a new c/c++ remote application configuration.
screenshot
You can add the .out elf file from your project as the "C/C++ application". I disable auto builds, since it helps to ensure that the .out file exactly matches the version I've loaded on the device. At the bottom of the window there is a 'select other' link.
screenshot
Switch over to manual remote debugging.
screenshot
Switch over to manual remote debugging.
screenshot
Heading over to the debugger tab, change the gdb executable to the one in your SDK.
screenshot
There is a "connection tab here, switch over and set the serial connection to match your hardware configuration. Apply your changes.
screenshot
That is pretty much it. You can hit the debug button to launch the debugger.

Depending on how you've configurated gdbstub, your application will have been suspended early in its startup process waiting for the debugger to be attached. It'll start inside the gdbstub-entry code that is written in ASM - stepping forward to the end of the routine will bring you back to your code and you can start debugging from there.

Problems

There are times where things don't quite work the way I'd like, and I'm not sure why. For instance, most of the time breakpoints work as expected, but in some cases they don't. The memory inspector doesn't work, it displays all 0xff. Occasionally gdb itself will segfault out. If you find further work arounds or have tips and tricks, send me an email at gil@pushrate.com and I'll expand this document.

Back to Post