CLion 2024.1 Help

Complicated remote scenarios

This article gives general recommendations for the case when you need to build a CMake or Makefile application on a remote system and then debug it on another remote system:

  • CLion is running locally (is referred below as local machine)

  • build is performed remotely inside a Docker container or another system (build machine)

  • the application is launched on an embedded device or yet another system (target machine)

1. Set up the build toolchain

  1. Select the tab that corresponds to where the application is built, on a remote machine or inside a Docker container.

    In Settings | Build, Execution, Deployment | Toolchains, create a Remote toolchain and provide the credentials to access your build machine:

    Remote toolchain for build

    In Settings | Build, Execution, Deployment | Toolchains, create a Docker toolchain:

    Docker toolchain for build
  2. Connect the created toolchain to a CMake profile (make sure it' a Debug profile) or select it in Makefile settings.

    Settings the build toolchain in CMake profile
  3. Build your project to get the binary.

    For Remote toolchain, the binary will be created on the build machine and will not be downloaded to your local machine automatically. Later on we will add an external tool to perform the required copying.

    In the case of Docker, the binary is automatically synced to your local machine. You can check the binary in the mapped directory right away after building.

2. Prepare the debugger

  1. Make sure to have a multi-arch GDB executable on your build machine.

    For example, if you build on Ubuntu, you can install a multi-arch GDB by running

    sudo apt install gdb-multiarch
  2. In the toolchain settings, check that the multi-arch GDB is selected in the Debugger field. Provide the path manually if it was not detected automatically.

3. Create an external tool to download the binary (skip for Docker)

  1. Create an external tool that will download the binary from the build machine to your local system.

    For example, you can use scp for that:

    External tool for downloading the binary
  2. Check the path mappings: the directory where you download the binary from the build machine should have the same relative path to the project root.

  3. After configuring the tool, call it manually using Tools | External Tools to perform the download for the first time. Check the binary on your local system.

4. Set up a Remote GDB Server configuration

Create a Remote GDB Server configuration and fill in the following settings:

  • Executable - select the downloaded (local) binary

  • GDB - select the GDB from the build machine (the one specified in the toolchain)

  • Credentials - provide the credentials to access your target machine

  • Before launch area (skip for Docker) - add the external tool for download, after the Build step

Remote GDB Server confguration

    Now when you launch that Remote GDB Server configuration, the following sequence of steps will be performed:

    1. Your project will be built on the build machine using the Remote/Docker toolchain.

    2. In the case of Docker, the binary will be copied locally. Otherwise, it will be downloaded to the local system by the external tool.

    3. The binary will be then uploaded to the target machine and launched under gdbserver.

    4. CLion debugger (which you configured to be the GDB from your build machine) will connect to the gdbserver on the target machine.

    Last modified: 26 May 2024