CLion 2018.2 Help

Debugging

General debugging steps

  1. Configure the debugger options
  2. Choose the desired CMake profile.
  3. Define a run/debug configuration for the application to be debugged.
  4. Create breakpoints in the source code.
  5. Launch a debugging session.
  6. Pause or resume the debugging session as required.
  7. During the debugger session, step through the breakpoints, evaluate expressions, change values on-the-fly examine suspended program, set watches and watchpoints.

After you've started a debug session, the icons actions startDebugger svg icon that marks the Debug tool window toggles to debug active to indicate that the debug process is active.

Debug

After you have configured a run configuration for your project, you can launch it in debug mode by pressing Shift+F9.

In the Debug tool window you can see the list of frames and threads with their states, variables and watches. When you select a frame, you see the variables corresponding to the selected frame.

Useful debugger shortcuts

Breakpoints

Breakpoint details and condition

If you want to change details of a breakpoint, press Ctrl+Shift+F8. Here you can specify the breakpoint conditions:

cl breakpoint properties

To see all breakpoints in the project (with more advanced settings), press the same shortcut Ctrl+Shift+F8 again.

Action breakpoints

Another action might be useful if you want to evaluate something at a particular line of code without actually making a stop. You can do that by using the Action breakpoint. To create one, just click on the gutter while holding Shift.

cl actionbp

Temporary breakpoints

To create a breakpoint that stops only once, click the left gutter while holding Shift+Alt.

cl temp breakpoint

Refer to the section Using Breakpoints for details.

Disable breakpoints

It's also useful to know that any breakpoint can be quickly disabled by clicking on the gutter while holding Alt.

Refer to the section Enabling, Disabling and Removing Breakpoints for details.

Debugger session

Run to cursor

Sometimes you need to resume the program and stop at another line of code, without adding another breakpoint. Just press Alt+F9.

cl runtocursor

The icon icons actions runToCursor is described in the toolbar reference of the Debug tool window.

Evaluate expression

While in debug mode, you can evaluate any expression by pressing Alt+F8.

cl evalexpr panelbutton

This tool provides code completion just as in the editor so it’s very easy to enter any expression:

cl evalexpression

Refer to the section Evaluating Expressions for details.

Remote debug

The final thing you definitely should know about debugging in CLion is Remote debug. Remote debug means attaching debugger to a process which is already running on a specific port on your or any other’s host. This way you can attach the debugger to your application server which is running standalone.

To create a remote configuration, go to Edit configurations and add a new GDB Remote Debug configuration. Make sure to specify the correct host and port before running this configuration.

Settings

If you want to change the default debugger settings, choose Debugger in CLion Settings/Preferences.

Last modified: 16 June 2018

See Also