Re: Watchpoints with condition

Eli Zaretskii
2007-12-04T21:07:04Z

> Cc: Eli Zaretskii <eliz@gnu.org>, gdb@sourceware.org
> From: Jim Blandy <jimb@codesourcery.com>
> Date: Tue, 04 Dec 2007 09:23:52 -0800
>
> I guess I don't see why 'GDB stops your program whenever the value of
> this expression changes' is hard to understand.

Two reasons: (1) most people think watchpoints watch variables, not
expressions; and (2) the notion of "foo == 1" being an expression
whose value is either 1 or zero is natural only to C hackers.

> Explaining conditional watchpoints is a superset of explaining
> watchpoints, so I don't see how it could be simpler.

It is simpler because you still watch a simple variable, and the
condition is kept separately. It is similar to

x = y + (foo == 1);

vs

if (foo == 1)
x = y + 1;
else
x = y;

The latter shows what the code does more clearly (and in fact some
coding standards advise against the former style).