This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [GDB 6.8] Problem using watchpoints with compound objects


OK. I now understand why the "struct" example below was not working and
my false assumption that coerce_array() was the culprit in both cases (I
checked the array case but assumed it was the same for the struct :-( ).
The reason why it was not working was because I was initially running
the program with the following GDB script:

file a.out
break main
run
watch a
continue

Using the above script I see the following output from GDB (using the
snapshot version 6.8.50.20090303):

> Breakpoint 1 at 0x8048320: file a.c, line 4.
> 
> Breakpoint 1, main () at a.c:4
> 4         a.m1 = 1;
> Hardware watchpoint 2: a
> 
> Program exited normally.

which shows that the watchpoint is not being reported. However if I
replace "break main" with "tbreak main" in the above script I see the
watchpoint being reported, as follows:

> Temporary breakpoint 1 at 0x8048320: file a.c, line 4.
> 
> Temporary breakpoint 1, main () at a.c:4
> 4         a.m1 = 1;
> Hardware watchpoint 2: a
> Hardware watchpoint 2: a
> 
> Old value = {m1 = 0, m2 = 0, m3 = 0, m4 = 0}
> New value = {m1 = 1, m2 = 0, m3 = 0, m4 = 0}
> main () at a.c:5
> 5         return 0;

So in this instance it seems the problem has nothing to do with "a"
being a struct object (as you correctly point out) but as a result of
continuing from a breakpoint; a different GDB issue :-).

However my original query relating to arrays is still valid. If I
perform the same test with "a" defined as an array (as in my original
email) then the effect of coerce_array() in value_equal() remains; the
watchpoint is reported by the H/W but value_equal() will always report
TRUE (since it compares the address of the array and not its contents)
and hence GDB erroneously ignores the watchpoint as unchanged. Therefore
I still think the change to watchpoint_check() is still valid. If you
concur I will submit a patch for this.

[Note that this was tested on RedHat EL3 and EL4 hosts with the same
results.]

Cheers,

Antony.

Daniel Jacobowitz wrote:
> On Tue, Mar 03, 2009 at 09:18:02PM +0000, Antony KING wrote:
>> struct {int m1, m2, m3, m4;} a;
>> int main (void)
>> {
>>   a.m1 = 1;
>>   return 0;
>> }
>>
>> In both cases value_equal is comparing the address of the object and not
>> the contents. This is caused, I believe, by the following code at the
>> start of value_equal:
>>
>>   arg1 = coerce_array (arg1);
>>   arg2 = coerce_array (arg2);
>>
>> which is converting the compound objects into pointers. These are then
>> used in the latter tests of value_equal.
> 
> Arrays are supposed to be handled specially, but I was talking about
> structs since that was in your original example.  coerce_array has no
> effect on structs.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]