Remote Debug
CLion supports remote debug with GDB/gdbserver. Having an executable running on a remote machine under gdbserver, you can connect to it with the GDB from CLion on another machine and inspect the code using all the benefits of the CLion debugger: set breakpoints from the IDE, view variable values, evaluate expressions, and more.
Since the bundled GDB in CLion is built with multi-arch support, it can be used for remote cross-platform debug in various Linux/Windows/macOS and embedded cases. Below you can find the list of remote targets supported by the bundled GDB:
Remote targets supported by the bundled GDB
i686-pc-mingw32 i686-w64-mingw32 x86_64-w64-mingw32 i686-linux-gnu x86_64-linux-gnu aarch64-linux-gnu alpha-linux-gnu arm-linux-gnu arm-linux-gnueabi arm-linux-gnueabihf hppa-linux-gnu ia64-linux-gnu m68k-linux-gnu m68k-rtems mips-linux-gnu mipsel-linux-gnu mips64-linux-gnu mips64el-linux-gnu powerpc-linux-gnu powerpc-linux-gnuspe
Remote GDB debug
Before starting the debug session, you need to create a GDB Remote Debug configuration (go to Run | Edit Configurations on the main menu and create one from the GDB Remote Debug template):
In this dialog, specify the following settings for the configuration:
-
'target remote' args
Here you need to provide the medium to carry the debugging packets (serial line, or an IP network using TCP or UDP). See gdb documentation for more details on connecting to a remote target.
-
Symbol file
GDB that runs on the host needs access to debug information for the executable running on the target. For this, it requires the symbol file on host to be a non-stripped copy of the executable on the target. However, leaving this field empty may also work well, as recent versions of GDB can transfer symbols from GDB server automatically.
-
Sysroot
In this field, specify the local directory that contains the symbol file and the copies of target libraries in corresponding subdirectories.
-
Path mappings
Use this pane to provide paths on target machine (the Remote column) to be mapped to local paths on host (the Local column).
Launching the remote GDB debug session
First, you need to run an executable on target system under the GDB server. For example, you can use the CLion terminal to access the remote host:
Then launch your GDB Remote Debug configuration. CLion will connect to the GDB server, and you will be able to use the CLion debugger as usual (for example, set breakpoints, step through the code, and examine the variables):