2

Can anyone tell me what's the difference between break and tbreak regarding watchpoints ?

A have a simple test code :

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv) {
  int toto;
  toto = 1;
  toto = 2;
  toto = 3;
  return (EXIT_SUCCESS);
}

When i use break on main(), then watch, toto seem to switch from 0 to 2 :

(gdb) break main
Breakpoint 1 at 0x804839a: file pp.c, line 6.
(gdb) r
Starting program: /mnt/mega20/SRC/C/gdb/pp 

Breakpoint 1, main (argc=1, argv=0xbffff4f4) at pp.c:6
6         toto = 1;
(gdb) watch toto 
Hardware watchpoint 2: toto
(gdb) c
Continuing.
Hardware watchpoint 2: toto

Old value = 0
New value = 2
main (argc=1, argv=0xbffff4f4) at pp.c:8
8         toto = 3;
(gdb)

But when i use tbreak, watch seem to work :

(gdb) tbreak main 
Temporary breakpoint 1 at 0x804839a: file pp.c, line 6.
(gdb) r
Starting program: /mnt/mega20/SRC/C/gdb/pp 

Temporary breakpoint 1, main (argc=1, argv=0xbffff4f4) at pp.c:6
6         toto = 1;
(gdb) watch toto 
Hardware watchpoint 2: toto
(gdb) c
Continuing.
Hardware watchpoint 2: toto

Old value = 0
New value = 1
main (argc=1, argv=0xbffff4f4) at pp.c:7
7         toto = 2;
(gdb) c
Continuing.
Hardware watchpoint 2: toto

Old value = 1
New value = 2
main (argc=1, argv=0xbffff4f4) at pp.c:8
8         toto = 3;
(gdb)

Same results with the start command, it works.

Lefinnois
  • 21
  • 2
  • 1
    And... what have you used for compile switches? What gdb version? Have you looked up the meaning of the gdb commands? ... – t0mm13b Jun 06 '11 at 11:54
  • "gcc -g3 -O0" with gdb 7.2 on Debian, and yes. – Lefinnois Jun 06 '11 at 12:37
  • 1
    If a add a breakpoint on main, run, delete breakpoint, add watchpoint on toto and continue, no problem at all. watchpoint is missed on toto=1 only if a breakpoint is defined on main. – Lefinnois Jun 07 '11 at 07:10

1 Answers1

2

I suggest you to read this:

Breakpoints and Watchpoints

Kyrol
  • 3,475
  • 7
  • 34
  • 46