01 #include
02
03 int main()
04 {
05 int cnt, len;
06 for (cnt = 0; cnt < 100000; cnt++)
07 {
08 printf("cnt = %d\n", cnt);
09 len = cnt + 10;
10 }
11 }
root@zengxiaolong:/tmp# gdb -q test
(gdb) l
1 #include
2
3 int main()
4 {
5 int cnt, len;
6 for (cnt = 0; cnt < 100000; cnt++)
7 {
8 printf("cnt = %d\n", cnt);
9 len = cnt + 10;
10 }
(gdb) b test.c:8 if cnt == 5 // test.c的第8行,如果cnt等于5,将会设置断点
Breakpoint 1 at 0x804838e: file test.c, line 8.
(gdb) r
Starting program: /tmp/test
cnt = 0
cnt = 1
cnt = 2
cnt = 3
cnt = 4
Breakpoint 1, main () at test.c:8
8 printf("cnt = %d\n", cnt);
(gdb) watch len // 此时监测len的变化
Hardware watchpoint 2: len
(gdb) c
Continuing.
cnt = 5
Hardware watchpoint 2: len
Old value = 14
New value = 15
main () at test.c:6
6 for (cnt = 0; cnt < 100000; cnt++)
(gdb)
阅读(4592) | 评论(0) | 转发(0) |