Setting a breakpoint when a variable reaches a certain value

Do I need to set a breakpoint when the variable reaches a certain value in GDB? For example, a variable takes these values: 1 4 8 10 3 2 9 13 11, and I want to set a breakpoint when this variable reaches 9.

+5
source share
2 answers

Yes, set a breakpoint with a condition .

break ... if value==9
+6
source

You can use watchpoints for this.

watch n > 9

... must be interrupted when the logical expression changes n > 9; that is, whenever n goes from less than or equal to 9 to more than 9, or vice versa.

+1

All Articles