Debugging with Eclipse

A good visualization helps us understand things faster. What we can do is use Using with Eclipse CDT and its debugging plugins to do remote debugging as we did from the command line.

Note

For all architectures the Basic Blink is recommended as a starting point, as it’s the simplest.

The Live Debug sample demonstrates more advanced features and is more focused on the Esp8266.

Here is the general procedure for setting up Eclipse for debugging:

Start Eclipse CDT and import the sample makefile
  • Select File -> New -> Project -> C/C++ -> Makefile Project with Existing Code

  • Point Eclipse to the location of the application sample

  • Import the Sming Framework

Import Project

Import Project

Once the two projects are in Eclipse, set the Basic_Blink project to reference the Sming project.

Host Emulator

Create a new Debugging Configuration:

  • Select Run -> Debug Configurations -> C/C++ Application

  • Right-click and create a new C/C++ Application

  • In the Main tab set, set:
    • Project: Basic_Build

    • C/C++ Application: out/Host/debug/firmware/app

    • disable for now the auto build

C/C++ Application

C/C++ Application

Then go to the Debugger tab and point the GDB debugger to your gdb binary. (Type make list-config and look for GDB.)

Debugger configuration

Debugger configuration

Embedded Devices

Create a new Remote Debugging Configuration:

  • Select Run -> Debug Configurations -> C/C++ Remote Application

  • Right-click and create a new C/C++ Remote Application

  • In the Main tab set the following, replacing {ARCH} with, for example, Esp8266:
    • Project: Basic_Build

    • C/C++ Application: out/build/{ARCH}/Debug/app.out

    • disable for now the auto build

Remote Debugging Session

Remote Debugging Session

Now go to the Debugger tab and point the GDB debugger to your GDB binary. To find this, type make list-config | grep GDB at the command prompt and look for GDB.

Remote Debugging Session

Remote Debugging Session

Make sure to load also the GDB command file. This is identified by GDBSTUB_DIR. The file is called gdbcmds, and you may wish to place a copy of the file somewhere else, especially if you intend to modify it. Here is the one for Esp8266: Sming/Arch/Esp8266/Components/gdbstub/gdbcmds.

Finally we should configure the remote connection via the Debugger -> Connection tab. This varies slightly between architectures:

Esp8266
  • type: Serial

  • device: /dev/ttyUSB0 (or as required for your operating system)

  • speed: 115200

Set remote connection

Set remote connection

Esp32
  • type: TCP

  • host: localhost

  • port: 3333

Set remote connection

Set remote connection

We are now ready for debugging. Press the Debug button. (In the screenshot above the Debug button is in the bottom-right corner.) After some seconds your debugging session should be up and running and you can enjoy live debugging.

Live Debugging Session

Live Debugging Session (Esp8266)

Live Debugging Session

Live Debugging Session (Esp32)

You will be able to see the current variables and their values. You should be able to go step by step, go inside of functions, add breakpoints to code in RAM or add breakpoints to code that was in FLASH.