CLion 2024.3 Help

CMake debug

CLion CMake debugger can help you identify and fix errors or unwanted behavior in your CMake scripts.

For CMake version 3.27 and later, CLion uses the Debug Adapter Protocol (DAP). You can also switch to the implementation based on the CMake script debugger from Sysprogs in Advanced settings.

Debug a failed CMake generation

  1. If CMake generation failed, click the debug hint in the CMake tool window:

    Debug hint in CMake tool window
  2. CLion will launch a debug session and get you to the corresponding point in your code:

    Debug session started from the CMake tool window

Launch a CMake debug session from the editor

  • Open the top-level CMakeLists.txt, click the gutter icon next to the first command, and select Debug:

    Starting a CMake debug session from gutter

When you launch a debug session this way, CLion creates a temporary configuration of the type CMake Debug. You can save it for further use and create more configurations of that type. For more information, refer to the next section.

Create and launch CMake Debug configurations

  1. In the main menu, go to Run | Edit Configurations.

  2. Click on the toolbar or press Alt+Insert. Select CMake Debug from the list of templates:

    Adding a CMake Debug configuration
  3. Set the name for your configuration and add the Before launch steps if required.

  4. Select the newly created configuration in the switcher and click The Debug button or press Shift+F9.

CMake debug features

The CMake debugger includes many of the general debug features available in CLion. For example, you can set breakpoints, step through your code, watch CMake variables, and explore values inlined in the editor:

Debug session example
Last modified: 11 February 2024