Watchpoints (sometimes referred to as data breakpoints) are helpful when you need to focus on a particular variable and its behaviour throughout the program execution. By using watchpoints in CLion, you can force your program to pause (and/or log to console) whenever the variable in question is being accessed.
Setting up a watchpoint
- Pick a variable or expression from those already added to Watches, right-click it and choose Add Watchpoint:
- Configure your watchpoint via the pop-up dialog: To access additional properties, click More Ctrl+Shift+F8 or select from the main menu:
Option Description Enabled Select or clear this checkbox to enable or disable the watchpoint. Suspend If this option is selected, the program's execution will stop at the event specified in the Access Type field. If you clear this checkbox, the program will not stop at the watchpoint hit, but any associated actions (e.g., logging) will still be performed. Log to console Select these checkboxes to log the Breakpoint hit message or the watchpoint's stack trace to console. This is useful if you want to analyze the changes of a variable without stopping the program's execution. Remove once hit Set this option to ensure that the watchpoint is removed after being hit once. This is helpful when you need to find the first occurrence of a watchpoint event. Disable until breakpoint is hit This option disables the current watchpoint until some other breakpoint is encountered. Access Type Choose the type of access that will trigger the watchpoint: Read, Write, or Any.