CLion 2020.3 Help

Embedded GDB Server

To debug on-chip with GDB server, use the Embedded GDB Server configuration, which covers the following cases:

  • ST-Link GDB servers (you can find the open-source version of the tools on GitHub).

  • 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.

This configuration works for CMake and Makefile projects, as well as custom build targets.

Required tools

  1. Toolchain

    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-gcc from 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 Settings/Preferences | Build, Execution, Deployment | Toolchain or in your CMake script (take a look at the template CMakeLists.txt).

    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.

  2. GDB server

    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

  1. Go to Run | Edit Configurations, click icons.general.add.svg and select Embedded GDB Server.

  2. Embedded GDB Server configuration

    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 Settings / Preferences | Build, Execution, Deployment | Custom Build Targets dialog.

    • GDB

      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.

    • GDB Server

      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

      This command is sent by default after flashing the MCU and also when you press MCU reset 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).

    • 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 Debugicons.actions.startDebugger.svg this configuration, CLion performs a sequence of steps:

  1. Start GDB server with the specified environment.

  2. Wait until the configured startup delay time passes.

  3. Start GDB client and connect to the GDB server.

  4. Upload the binary as specified by the Download option in the configuration settings.

  5. Start the debug session.

    Now your firmware running on-chip can be debugged using the entire set of CLion debug features, including Memory view and the Peripherals tab showing peripheral registers and bits.

    Debugging an Embedded GDB Server configuration

    Notice the MCU reset 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.

    Last modified: 27 October 2020