Home Getting Started Download Discussions Source Report An Issue

Debugging embedded systems with CLion and Bloom

Because Bloom exposes the connected target via a GDB RSP debug server, any IDE with GDB RSP client capabilities can interface with Bloom to gain access to the target. The CLion IDE is equipped with GDB RSP support.

Once you have installed Bloom and created a project configuration file, you can follow the steps below to setup a debug configuration in CLion.

Installing GDB for AVR debugging

For debugging AVR microcontrollers, CLion must be configured to use the avr-gdb executable. This can be installed via the gdb-avr package.

$ sudo apt-get install gdb-avr;

There is a known bug in GDB, when configured for debugging AVR targets. This bug results in GDB's failure to read program (flash) memory from the target, subsequently causing disassembling operations to fail. This bug was fixed in GDB version 10.1.

Some OS repositories may not contain the latest version of the gdb-avr Debian package. The following command can be used to confirm the GDB version is 10.1 or later:

$ avr-gdb --version

Repositories for Ubuntu 20.04 or earlier do not contain the latest version of gdb-avr. To install the latest version, users can manually download the Debian package from https://packages.ubuntu.com/hirsute/gdb-avr or https://packages.debian.org/stable/gdb-avr. The package can be installed via the following command:

$ sudo apt install path/to/gdb-avr-package.deb

NOTE: The version number of the gdb-avr Debian package does not equate to the GDB version number. In other words, the gdb-avr package, from version 7.7-4.1, will be built from GDB 10.1 or later.

Setup a "GDB Remote Debug" configuration in CLion

To configure CLion to interface with Bloom, a "GDB Remote Debug" configuration must be created. To do this, follow the steps below:

1. From CLion, open the "Run/Debug Configurations" window via Tools -> Edit configurations

The Clion Run/Debug Configurations window

2. From the "Run/Debug Configurations" window, create a new "GDB Remote Debug" configuration:

Adding a new GDB Remote Debug configuration in CLion, for Bloom

3. Locate the avr-gdb executable and set the server address & port. If you didn't set the ipAddress or port debug server parameter in your project configuration file, you will need to use the default values (localhost/ and 1442).

You will also need to select the symbol file to pass to avr-gdb. This will be the ELF output from your compiler.

Adding a new GDB Remote Debug configuration in CLion, for Bloom

When compiling your AVR code, be sure to enable the compiler option for including debug information in the compiler output (for avr-gcc/g++, this can be done via the -ggdb compiler flag).

Start Bloom and begin debugging

You should now be ready to begin debugging. Run Bloom from your project directory:

$ cd /path/to/project; $ bloom [ENVIRONMENT];

Replace "[ENVIRONMENT]" with your environment name, or leave blank to have Bloom fallback to the "default" environment.

Bloom will report when it is ready to accept incoming connections:

2021-04-14 23:11:36 BST [DS] [36]: [INFO] Starting DebugServer 2021-04-14 23:11:36 BST [DS] [37]: [INFO] GDB RSP address: 2021-04-14 23:11:36 BST [DS] [38]: [INFO] GDB RSP port: 1442 2021-04-14 23:11:36 BST [DS] [40]: [INFO] DebugServer ready 2021-04-14 23:11:36 BST [DS] [41]: [INFO] Waiting for GDB RSP connection

If Insight is enabled, the Insight window will appear automatically.

Bloom Insight

See Insight documentation for more on how to use the Insight window.

At this point, you can begin a debug session in CLion by clicking Run -> Debug and selecting the newly created debug configuration.