Re: Problem with "watch" on a new port.

Florent Defay
2009-07-07T12:29:03Z

Hi,
Thank you very much to all for the answers.

I am still in trouble with the "watch" issue.

I give you a concrete example of the problem bellow.
I debug main.c with the target-gdb (remote protocol) in two different ways.

main.c
---------
void foo ()
{
}

int main ()
{
int a = 1;
int i;

for (i = 0; i < 10; i++)
{
if (i == 5)
{
a = 2;
}
}

for (i = 0; i < 10; i++)
{
if (i == 5)
{
foo();
a = 3;
}
}

return 0;
}
-----------------------------------------------------------

behavior 1
--------------
Breakpoint 1, main () at main.c:8
warning: Source file is more recent than executable.
8 int a = 1;
(gdb) watch a
Hardware watchpoint 2: a
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
main () at main.c:11
11 for (i = 0; i < 10; i++)
(gdb) p i
$1 = 5
(gdb) p a
$2 = 1
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
main () at main.c:11
11 for (i = 0; i < 10; i++)
(gdb) p i
$3 = 5
(gdb) p a
$4 = 2
(gdb) c
Continuing.
//// nothing happens, infinite waiting
-----------------------------------------------------------

behavior 2
--------------
Breakpoint 1, main () at main.c:8
8 int a = 1;
(gdb) set can-use-hw-watchpoints 0
(gdb) watch a
Watchpoint 2: a
(gdb) c
Continuing.
Watchpoint 2: a

Old value = 2
New value = 1
main () at main.c:11
11 for (i = 0; i < 10; i++)
(gdb) c
Continuing.
Watchpoint 2: a

Old value = 1
New value = 2
main () at main.c:11
11 for (i = 0; i < 10; i++)
(gdb) p i
$1 = 5
(gdb) c
Continuing.

Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
0x0000004e in foo () at main.c:4
4 }
-----------------------------------------------------------

My conclusion :
In behavior 1, Hardware watchpoint is used. The problem is
1- There are no info about old and new value.
2- The statement a = 3; is not detected.

In behavior 2, Software watchpoint is used. The problem is
1- It cannot be a final solution because it is very slow.
2- "Watchpoint 2 deleted because the program has left the block in
which its expression is valid."
is not a good behavior. The call to foo has a secondary unexpected
effect (it is the same behavior every time a function is called).

The simulator (sid) seems to receive Z/z packets well. It may be due
to a mistake in t-dep or something missing but I do not know what.
Plus, step, next, breakpoints, finish work very well.

Thank you.

Regards,

Florent.