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.
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
2. From the "Run/Debug Configurations" window, create a new "GDB Remote Debug" configuration:
If you choose to use an 'Embedded GDB Server' configuration, please note that there is a known issue with having CLion manage Bloom's process - CLion issues a SIGKILL to Bloom, milliseconds after the debug session has ended - this results in Bloom's process being killed before it can shut down safely. This may result in the debug tool or target being left in a bad state at the end of the debug session.
This issue has been reported to CLion's developers - see the corresponding YouTrack ticket for more.
Until this issue is resolved, it is not recommended to use any debug configuration that involves CLion managing Bloom's process.
3. Locate the avr-gdb executable and set the server address & port. If you didn't set the
port debug server parameter in your
project configuration file, you will need to use the default values (localhost/127.0.0.1 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.
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] : [INFO] Starting DebugServer 2021-04-14 23:11:36 BST [DS] : [INFO] GDB RSP address: 127.0.0.1 2021-04-14 23:11:36 BST [DS] : [INFO] GDB RSP port: 1442 2021-04-14 23:11:36 BST [DS] : [INFO] DebugServer ready 2021-04-14 23:11:36 BST [DS] : [INFO] Waiting for GDB RSP connection
If Insight is enabled, the Insight window will appear automatically.
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.