2011-06-06 83 views
0

谁能告诉我关于watchpoint的break和tbreak有什么区别?gdb,break vs tbreak和watchpoint

A具有一个简单的测试代码:

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

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

当我使用上main()中,然后观察断裂,TOTO似乎切换为0〜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) 

但是当我使用手表似乎工作:

(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) 

与启动命令相同的结果,它的工作原理。

+1

而且......你有什么用编译开关?什么gdb版本?你是否查询过gdb命令的含义? ... – t0mm13b 2011-06-06 11:54:48

+0

“gcc -g3 -O0”在Debian上使用gdb 7.2,是的。 – Lefinnois 2011-06-06 12:37:58

+1

如果在main上添加断点,运行,删除断点,则在toto上添加观察点并继续,完全没有问题。仅当在main上定义断点时才会错过toto = 1的观察点。 – Lefinnois 2011-06-07 07:10:19

回答