O'Reilly logo

The Art of Debugging with GDB and DDD by Peter Jay Salzman, Norman Matloff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Watchpoints

A watchpoint is a special kind of breakpoint which, like a normal breakpoint, is an instruction that tells GDB to pause execution of your program. The difference is that watchpoints don't "live" at a line of source code. Instead, a watchpoint is an instruction that tells GDB to pause execution whenever an expression changes value.[11] That expression can be quite simple, like the name of a variable:

(gdb) watch i

which will make GDB pause whenever i changes value. The expression can also be quite complex:

(gdb) watch (i | j > 12) && i > 24 && strlen(name) > 6

You can think of a watchpoint as being "attached" to an expression; when the value of that expression changes, GDB will pause the program's execution.

Although watchpoints and breakpoints ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required