This is the mail archive of the
mailing list for the GDB project.
Re: Watchpoints with condition
- From: Jim Blandy <jimb at codesourcery dot com>
- To: gdb at sourceware dot org
- Date: Mon, 03 Dec 2007 09:54:41 -0800
- Subject: Re: Watchpoints with condition
- References: <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <20071130234853.GA27583@caradoc.them.org>
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.