Re: Watchpoints with condition

Jim Blandy
2007-12-03T17:54:55Z

Daniel Jacobowitz <drow at false.org> writes:
> On Fri, Nov 30, 2007 at 03:30:21PM -0800, Jim Blandy wrote:
>> Isn't that equivalent to 'watch foo == 1'?
>
> Not quite.
>
> watch foo == 1
>
> stops when foo becomes 1 or non-1.
>
> watch foo if foo == 1
>
> stops only when foo becomes 1.

Okay, so 'watch foo if foo == 1' has some interesting behavior:
- if foo is 1 when the watchpoint is set, then the watchpoint doesn't
trigger until foo becomes != 1, and then becomes 1 again.
- If foo is != 1 when the watchpoint is set, then the command is
equivalent to watch foo == 1.

The first case seems really obscure; I assumed that wasn't what Eli
was using conditional watchpoints for "quite a lot".

I think any time you have 'watch X if Y', and X is a subexpression of
Y, and Y is initially false, it's equivalent to 'watch Y != 0' (or
simply 'watch Y' if Y is a boolean expression). X gets watched
automatically because it appears in Y, and the only time the
expression changes value is when it becomes true.

I think the only valuable use case for conditional watchpoints is the
one you mentioned, where Y is something expensive, and X is some
cheaper conservative approximation to the condition we really want.