[RFA] Compare contents when evaluating an array watchpoint

Klee Dienes klee@apple.com
Mon Nov 4 18:27:00 GMT 2002


On Monday, October 21, 2002, at 08:44 PM, Andrew Cagney wrote:

> (Like Eli, I'm puzzled by the existing behavior :-)
>
> Just to get this straight.  given:
> 	int a[10];
> then:
> 	(gdb) watch a
> sets up the hardware to look for a change in ``*a@10'' but then 
> evaluates ``a'' and hence, while stopping when ever `a' changes, never 
> trigger the watchpoint?

That's exactly correct.  The watchpoint code goes through all of the 
values referenced in evaluating an expression, and sets an OS-level 
watchpoint on each.  Since 'a' evaluates to a value with type ARRAY, 
the watchpoint code sets a hardware-assisted watchpoint on the full 
contents of that array.

> Would it be better to make it possible for the user to clearly 
> differentiate between these two cases and specify any of:
>
> 	int a[10];
> 	int *b;
> 	(gdb) watch a
> 	(gdb) watch b
> 	(gdb) watch *b@10
> 	(gdb) watch *a@sizeof(a)
>
> While the existing ``watch a'' might have annoying semantics, it would 
> make its behavior consistent with C.  An array is converted to a 
> pointer in an expression.  I'm not sure how well this would work with 
> the expression evaluator though.

The expression evaluator is perfectly happy to handle *b@10 in a 
watchpoint.  I think that the real issue is that the current mechanism 
to determine if a watchpoint has changed is:

	if (old_expr != new_expr) { print watchpoint; }

, which is fine, but IMO not overly intuitive, and would lead to the 
same problem of *b@10 not evaluating as having changed unless we were 
to special-case it somehow separately from 'watch a' (since both *b@10 
and 'a' evaluate to having the exact same type, namely ARRAY of INT).

The semantics I'm proposing are:

	if the value of 'old_expr' is different from the value of 'new_expr'.

, which I think is in general a lot less surprising to the user (if the 
output of 'print a' is different, how can we say that 'a' has not 
changed?), as well as simpler in the long term. If we're using the == 
semantics, do we call operator == for objects?  Easier I think just to 
say "we mark the watchpoint as changed if anything about the evaluated 
value has changed.".

Actually, I think there's a good argument to make watchpoint_equal use 
the code that I currently have special-cased for arrays for all the 
cases, and not use value_equal at all.  We don't have to worry about 
type conversions, since we're evaluating the same expression at two 
different points in time.

> What ever the outcome, this desperatly needs a testcase.  Otherwize 
> we're all going to keep spinning our weels wondering what the behavior 
> was ment to be.

Agreed.  I wrote this test with the assumption of "arrays compare as 
their contents in watchpoints", but I'm happy to modify the test if we 
decide on different semantics.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: watchpoint-tests.txt
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20021104/4411dc3c/attachment.txt>


More information about the Gdb-patches mailing list