WatchPoint
Conditional breakpoints
Sometimes you want to a breakpoint to happen only when certain conditions are true. Such as a session having started, a file or socket being open or an iteration being at a certain point. Conditional breakpoints can help with this.
Regexp, temporary and normal breakpoints can all be made conditional by adding the suffix:
if [CONDITION]
Here [CONDITION]
is a boolean expression, which, in GDB is true if the result is nonzero, otherwise it is false. The condition can include a function call, the value of a variable or the result of any GDB expression.
A common use case is using a conditional breakpoint to pause execution of your program on the [N]th iteration of a loop by typing something like:
break foo if i == [N]
For example:
break foo if i == 4
Get tutorials straight to your inbox
Become a GDB Power User. Get Greg’s debugging tips directly in your inbox every 2 weeks.
Want GDB pro tips directly in your inbox?
Share this tutorial