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
Select the tab that corresponds to where the application is built, on a remote machine or inside a Docker container.
In create a Remote toolchain and provide the credentials to access your build machine:
,In create a Docker toolchain:
,Connect the created toolchain to a CMake profile (make sure it' a Debug profile) or select it in Makefile settings.
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
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-multiarchIn 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)
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:
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.
After configuring the tool, call it manually using
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
Now when you launch that Remote GDB Server configuration, the following sequence of steps will be performed:
Your project will be built on the build machine using the Remote/Docker toolchain.
In the case of Docker, the binary will be copied locally. Otherwise, it will be downloaded to the local system by the external tool.
The binary will be then uploaded to the target machine and launched under gdbserver.
CLion debugger (which you configured to be the GDB from your build machine) will connect to the gdbserver on the target machine.