CLion 2024.3 Help

Debugger options

In CLion, you can debug C/C++ executables with LLDB on macOS/Linux and GDB on Windows/Linux (debugging with GDB on macOS is possible only with a custom GDB binary). Also, there is an LLDB-based debugger for the MSVC toolchain on Windows.

Current versions of the bundled debuggers:

  • GDB v 14.1 for Windows (local debug not supported for Windows ARM64)

  • GDB v 14.1 for Linux

  • LLDB v 17.0.6 for macOS and Linux

  • LLDB v 9.0.0 for MSVC toolchain on Windows

You can also use a custom GDB binary, the supported versions are 7.8.x-14.1.

Switching between the debuggers

  1. Go to Settings | Build, Execution, Deployment | Toolchains.

  2. In the Debugger field on the right pane, select the debugger for the current toolchain:

    the Select debugger list

Debugger data views

In the Settings | Build, Execution, Deployment | Debugger | Data Views | C/C++ dialog, you can customize the C/C++ data representation.

C/C++ debugger data views settings

Here you can control the standard library types rendering, module names, function parameter types and function template arguments, and other options. Alternatively, use the context menu in the Debug tool window, in the Frames view and in the Variables view:

Frames view context options
Variables view context options

STL containers rendering

When you set the Enable GNU library renderers checkbox, this affects rendering STL containers by GDB when using the gcc compiler. In the case of clang used in pair with GDB, this option works for libstdc++ only (for more information, refer to next chapter).

Currently this option is not applicable to LLDB. Check how LLDB (starting from version 9.0) handles libc++ and libstdcxx in LLDB STL formatters below.

LLDB STL formatters

Lists given below are accurate for LLDB version 9.0.

Type

libcxx

libstdc++

string

check_retina.png

check_retina.png

array

check_retina.png

check_retina.png

vector

check_retina.png

minus_retina.png

deque

check_retina.png

minus_retina.png

list

check_retina.png

minus_retina.png

forward list

check_retina.png

minus_retina.png

set

check_retina.png

minus_retina.png

map

check_retina.png

minus_retina.png

multiset

check_retina.png

minus_retina.png

multimap

check_retina.png

minus_retina.png

unordered_set

check_retina.png

minus_retina.png

unordered_map

check_retina.png

minus_retina.png

unordered_multiset

check_retina.png

minus_retina.png

unordered_multimap

check_retina.png

minus_retina.png

stack

check_retina.png

minus_retina.png

queue

check_retina.png

minus_retina.png

priority_queue

check_retina.png

minus_retina.png

Type

libcxx

libstdc++

string

check_retina.png if compiled with -fstandalone-debug

check_retina.png

array

check_retina.png

check_retina.png

vector

check_retina.png

check_retina.png

deque

check_retina.png

check_retina.png

list

check_retina.png

check_retina.png

forward list

check_retina.png

minus_retina.png

set

check_retina.png

check_retina.png

map

check_retina.png

check_retina.png

multiset

check_retina.png

check_retina.png

multimap

check_retina.png

check_retina.png

unordered_set

check_retina.png

minus_retina.png

unordered_map

check_retina.png

minus_retina.png

unordered_multiset

check_retina.png

minus_retina.png

unordered_multimap

check_retina.png

minus_retina.png

stack

check_retina.png

check_retina.png

queue

check_retina.png

check_retina.png

priority_queue

check_retina.png

check_retina.png

STL renderers for GDB on macOS

Combination of GDB as the debugging backend and Clang (the CMake default compiler) implies limitations on viewing the content of STL containers on macOS. As a workaround, try the following instructions.

  1. Use the libstdc++ library instead of libc++. To include libstdc++ in your project, add the following command in CMakeLists.txt:

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")

    Alternatively, go to Settings | Build, Execution, Deployment | CMake and specify the library in the CMake options field:

    -DCMAKE_CXX_FLAGS="-stdlib=libstdc++"
  2. We also recommend you use the dwarf3 debug info format. For this, add the following commands to your CMakeLists.txt:

    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -gdwarf-3") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -gdwarf-3")

Custom .gdbinit/.lldbinit files

If your project requires more configuration options for debugging, you can create a custom initialization file, .gdbinit for GDB or .lldbinit for LLDB, and place it under the project root. This file can be shared through VCS along with other project files.

Generally, GDB/LLDB loads several initialization files in certain order during startup. First, the debugger looks for an initialization file in the user's home directory, then for a file in the current working directory (your project root).

By default, commands from project-specific init files are not executed for security reasons. To allow that, modify the init file in your home directory as described below.

Enable reading project-specific .gdbinit/.lldbinit

Set permissions in the ~/.gdbinit file.

With GDB 11.1 and newer, you can use $HOME/.config/gdb/gdbinit or $HOME/Library/Preferences/gdb/gdbinit instead.

When working with WSL, edit the .gdbinit file located in WSL's home directory, /home/[user]/.gdbinit.

  • For all projects

    set auto-load local-gdbinit on add-auto-load-safe-path /
  • For a particular project

    set auto-load local-gdbinit on add-auto-load-safe-path [full path to the project root]/.gdbinit

Set permissions in the home ~/.lldbinit file:

settings set target.load-cwd-lldbinit true

    Adjusting GDB timeout values

    You can control the GDB timeout values by setting the corresponding properties in CLion registry.

    1. Press Ctrl+Shift+A or choose Help | Find Action from the main menu. In the popup that opens, start typing Registry, select the corresponding item and press Enter.

      Searching for Registry in Find Action
    2. In the dialog that opens, start typing cidr.debugger.timeout. Click the Value field of the highlighted string and enter the timeout value in milliseconds.

      registry keys for GDB timeouts

    Configuring external GDB console on Windows

    On Windows with GDB versions prior to 8.0, a separate console is used for application input/output. For the newer GDB versions, the output is redirected to CLion console by default. However, you can switch back to opening an external output window.

    1. Press Ctrl+Shift+A or choose Help | Find Action from the main menu. In the popup that opens, start typing Registry, select the corresponding item and press Enter.

      Searching for Registry in Find Action
    2. In the dialog that opens, start typing cidr.debugger.gdb.workaround.windows.forceExternalConsole. Click the Value field of the highlighted string and enter the timeout value in milliseconds.

      Registry key to enable external GDB console on Windows
    Last modified: 28 June 2024