General debugging steps
- Configure the debugger options
- Choose the desired CMake profile.
- Define a run/debug configuration for the application to be debugged.
- Create breakpoints in the source code.
- Launch a debugging session.
- Pause or resume the debugging session as required.
- 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 icon that marks the Debug tool window toggles to to indicate that the debug process is active.
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
Breakpoint details and condition
If you want to change details of a breakpoint, press Ctrl+Shift+F8. Here you can specify the breakpoint conditions:
To see all breakpoints in the project (with more advanced settings), press the same shortcut Ctrl+Shift+F8 again.
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.
To create a breakpoint that stops only once, click the left gutter while holding Shift+Alt.
Refer to the section Using Breakpoints for details.
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.
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.
The icon is described in the toolbar reference of the Debug tool window.
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.
If you want to change the default debugger settings, choose Debugger in CLion Settings/Preferences.