GDB Remote Debug
The GDB Remote Debug configuration is one of the two options that CLion provides for debugging remotely under gdbserver. Use this configuration if you already have the executable with debug information and don't need CLion to build the project for you. This configuration is independent of a particular build system or project format.
With this configuration, you can remotely debug applications that were built by any build system. The only requirement is for the debug symbols to be present on the local machine.
There are also no restrictions on the target environment: your program can run remotely under gdbserver on any OS including Linux-based embedded systems (for example, Raspbian OS), on a cloud platform, or, for example, inside a Docker container. You can connect to any GDB stub that complies with the remote gdbserver protocol - for example, Qemu to debug OS kernels or OpenOCD to debug flashed firmware.
CLion's bundled GDB, which is used as a client debugger by default, is built with multiarch support, which makes it suitable for remote cross-platform debug in various Linux/Windows/macOS and embedded cases. Below you can find the full list of all supported targets:
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
General steps of the workflow
Find below a brief description of the steps to take for remote GDB debug. More details for each step are given in the next chapters.
Prepare a binary with debug information. If required, use a cross-platform toolchain.
Make sure to place the binary on the remote machine and symbol file on the local machine.
Usually, the debug executable itself works well as a symbol file, or this can be a separate file as well.
In CLion, create a GDB Remote Debug configuration. The settings you specify are crucial for the debugger to be able to stop on breakpoints during a remote session, so we recommend you double-check the confugration set up.
Launch the program under gdbserver on the remote machine.
Back in CLion, start debugging the configuration you created on step 3.
Create a GDB Remote Debug configuration
Go to Run | Edit Configurations, click , and select GDB Remote Debug from the list of templates.
Specify the following settings:
Select the client debugger: bundled multiarch GDB (default), one of the toolchain debuggers, or a custom GDB binary.
'target remote' args
In this field, provide the connection to the remote system: IP address followed by a port number (like in our example) or connection details in another format.
This is the local machine path to the file with debug symbols, which can be a non-stripped copy of the executable running on target or an ELF file containing only the debug info.
Recent versions of GDB clients can transfer symbols from gdbserver automatically, so leaving this field empty may also work well if the executable running on target is a non-stripped binary.
Use this pane to provide the paths on the target machine (the Remote column) to be mapped to local paths on host (the Local column).
Sysrootis used by GDB client to access the copies of target libraries with debug symbols on your local system (in order to set breakpoints and find source lines in the libraries code).
Most of the recent versions of GDB can download the files automatically, so it's not required that you specify this field. However, note that automatic download may slow down the debugging process significantly.
If you choose to manually copy the libraries into a non-default local directory and want GDB to use it, set its path in this field.
Launch your program remotely under gdbserver
To launch your application on the target under gdbserver, you can use the remote terminal or invoke the CLion's built-in SSH terminal (run and provide the credentials).
Run gdbserver with two arguments:
Either a device name (for a serial line connection) or a TCP hostname with the port number (
:1234in the example below).
The path and filename of the executable to be debugged, followed by the program input arguments, if any.
Gdbserver then suspends the program at the entry point and waits for the client debugger to connect.
Start a remote debug session
In CLion, make sure to have GDB selected in Debugger field., the
If needed, place breakpoint in your code, then start a debug session for the newly created GDB Remote Debug configuration.
CLion’s debugger will connect to the running remote process. The terminal will show the Remote debugging from host.. message, and you can also check the debugger console for the Debugger connected to.. message.