I am running gdb under Red Hat Linux 6.0 on an intel pentium III,
but the same thing happens at work with GNU gdb 4.18 configured
as "sparc-sun-solaris2":


the files watchpoint.c and watchpoint.cc are identical:

main() {
  int a, n;
  for (n=0; n<10; n++)
    a=n;
}


but I can set watchpoints in C but not in C++:


wilkenin:~/test$ gcc -g watchpoint.c
wilkenin:~/test$ gdb a.out
GNU gdb 19991004
--snip--
This GDB was configured as "i386-redhat-linux"...
(gdb) b main
Breakpoint 1 at 0x80483b6: file watchpoint.c, line 4.
(gdb) r
Starting program: /home/wilkenin/test/a.out 

Breakpoint 1, main () at watchpoint.c:4
4         for (n=0; n<10; n++)
(gdb) n
5           a=n;
(gdb) watch (n==5)
Hardware watchpoint 2: n == 5
(gdb) c
Continuing.
#0  main () at watchpoint.c:5
5           a=n;
Hardware watchpoint 2: n == 5

Old value = 0
New value = 1
0x80483d1 in main () at watchpoint.c:4
4         for (n=0; n<10; n++)
(gdb) p n
$1 = 5
(gdb) quit
The program is running.  Exit anyway? (y or n) y
wilkenin:~/test$ 



wilkenin:~/test$ g++ -g watchpoint.cc
wilkenin:~/test$ gdb a.out
GNU gdb 19991004
--snip--
This GDB was configured as "i386-redhat-linux"...
(gdb) b main
Breakpoint 1 at 0x8048456: file watchpoint.cc, line 4.
(gdb) r
Starting program: /home/wilkenin/test/a.out 

Breakpoint 1, main () at watchpoint.cc:4
4         for (n=0; n<10; n++)
(gdb) n
5           a=n;
(gdb) watch (n==5)
Hardware watchpoint 2: n == 5
(gdb) c
Continuing.
#0  main () at watchpoint.cc:5
5           a=n;
Error evaluating expression for watchpoint 2
Invalid operation on booleans.
Watchpoint 2 deleted.
0x8048471 in main () at watchpoint.cc:5
5           a=n;
(gdb) p n
$1 = 1
(gdb) quit
The program is running.  Exit anyway? (y or n) y
wilkenin:~/test$ 


Thanks for developing gdb!
Sincerely,
Jon Wilkening, grad student at UC Berkeley

Reply via email to