Embedded GDB Server
To debug on-chip with GDB server, use the Embedded GDB Server configuration, which covers the following cases:
Segger J-Link GDB server.
Qemu as a GDB server.
OpenOCD as a standalone GDB server, as an alternative to OpenOCD Download & Run configuration.
Any other boards or specific GDB stubs that comply with the GDB server protocol.
Your cross-compiler toolchain should be configured in advance.
For ARM Cortex-M and Cortex-R MCUs, install GNU ARM toolchain. After the installation, make sure the toolchain is presented in the system PATH: run
arm-none-eabi-gccfrom the command line, and your system should recognize this command.
For all other platforms, install the platform-specific toolchain and set up the tools in CMakeLists.txt).or in your CMake script (take a look at the template
If you are working with an STM32CubeMX project, then installing the GNU ARM toolchain is a part of the project set up, and CubeMX generates the linker file automatically. Otherwise, obtain the linker script from your chip vendor or create it manually, and specify in CMake settings.
Make sure the selected GDB server is installed on your machine. There is no need to launch it manually: the configuration will run the GDB server automatically when you start a debug session.
Create an Embedded GDB Server configuration
Go to Embedded GDB Server., click and select
Configure the following settings:
Target and Executable
Select the target to be built (either a CMake or custom target) and the executable to be uploaded remotely.
Click the button to configure custom targets in the dialog.
Here you can select the GDB client debugger, which will run on CLion's side and connect to the remote GDB server. Use either the bundled GDB or your custom GDB binary.
'target remote' args
Provide the medium to carry debugging packets (serial line or an IP network using TCP or UDP). See gdb documentation for more details on connecting to a remote target.
Specify the binary to be used as GDB server.
GDB Server args
Provide the GDB server-specific arguments (for example, port number or board config file).
Advanced options: Reset command
By default, this command is sent after flashing the MCU and also when you press during a debug session. It usually starts with monitor, and the rest of the line is passed to the GDB server directly. Note that most GDB servers support several reset commands (refer to your vendor-specific documentation).
Reset can be performed at different stages: Before or After flashing MCU ROM or writing to RAM, Always (both before and after), or Never.
Advanced options: startup delay
The amount of time CLion will wait after starting the GDB server before attempting to connect.
Debug an Embedded GDB Server configuration
When you Debug this configuration, CLion performs a sequence of steps:
Start GDB server with the specified environment.
Wait until the configured startup delay time passes.
Start GDB client and connect to the GDB server.
Upload the binary as specified by the Download option in the configuration settings.
Start the debug session.
Notice the button on the left-hand bar of the Debugger tool window. When pressed, it sends the chip reset command specified in the Reset command field of the configuration settings.