【发布时间】:2013-04-23 17:18:05
【问题描述】:
谁能告诉我关于观察点的 break 和 tbreak 有什么区别?
有一个简单的测试代码:
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv) {
int toto;
toto = 1;
toto = 2;
toto = 3;
return (EXIT_SUCCESS);
}
当我在 main() 上使用 break 时,然后观察,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)
但是当我使用 tbreak 时,手表似乎可以工作:
(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)
与 start 命令的结果相同,它可以工作。
【问题讨论】:
-
还有……你用什么编译开关?什么gdb版本?您是否查过 gdb 命令的含义? ...
-
"gcc -g3 -O0" 在 Debian 上使用 gdb 7.2,是的。
-
如果在 main 上添加断点,运行,删除断点,在 toto 上添加观察点并继续,完全没有问题。仅当在 main 上定义断点时,才会在 toto=1 上错过观察点。
标签: debugging gdb watchpoint