免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 9593 | 回复: 4
打印 上一主题 下一主题

gdb使用watch问题 不解 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-23 16:19 |只看该作者 |倒序浏览
(gdb) l 1
1       #include<stdio.h>
2       #include<string.h>
3       int main()
4       {
5               int i;
6               char str[20]="This is a test";
7               for(i=0;i<5;i++)
8               {
9                       strcat(str,"!\0");
10                      printf("%s",str);
(gdb)
11              }
12              return 0;
13      }
14
15
(gdb) info breakpoints
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x080483ce in main at test.c:7
        breakpoint already hit 1 time
2       breakpoint     keep y   0x080483ff in main at test.c:10
        breakpoint already hit 5 times
3       breakpoint     keep y   0x0804841c in main at test.c:12
        breakpoint already hit 1 time
(gdb) r
Starting program: /root/driver_study/test

Breakpoint 1, main () at test.c:7
7               for(i=0;i<5;i++)
(gdb) watch str
Watchpoint 5: str
(gdb) c
Continuing.

Breakpoint 2, main () at test.c:10
10                      printf("%s",str);
(gdb) c
Continuing.

Watchpoint 5 deleted because the program has left the block in
which its expression is valid.
0x0048fce3 in _dl_fixup () from /lib/ld-linux.so.2
(gdb)
Continuing.

Breakpoint 2, main () at test.c:10
10                      printf("%s",str);
(gdb)
Continuing.

Breakpoint 2, main () at test.c:10
10                      printf("%s",str);
(gdb)
Continuing.

Breakpoint 2, main () at test.c:10
10                      printf("%s",str);
(gdb)
Continuing.

Breakpoint 2, main () at test.c:10
10                      printf("%s",str);
(gdb)
Continuing.

Breakpoint 3, main () at test.c:12
12              return 0;
(gdb)
Continuing.
This is a test!This is a test!!This is a test!!!This is a test!!!!This is a test!!!!!
Program exited normally.
(gdb)


//////////////////////////////////////////

这地方的watch怎么用,我要看str的值。。

论坛徽章:
0
2 [报告]
发表于 2009-12-23 16:52 |只看该作者
watch命令就是当watch后的表达式的值变化以后,就break,否则就不会break

你这里str是字符数组,因此str就是指向这个数组的指针,而这个地址永远没有变,当然不会触发watch了

当watch触发后,会打印出watch后跟的表达式在执行当前语句前后的值

我觉得你可以试试watch strlen(str), 也许就可以了

论坛徽章:
0
3 [报告]
发表于 2009-12-23 20:22 |只看该作者
是否应该有一个mem变化就停止的命令?

论坛徽章:
0
4 [报告]
发表于 2009-12-23 23:52 |只看该作者
二楼正解,str是指针,是地址,在主函数内都不会变。
可是怎么会有Watchpoint 5 deleted because the program has left the block in
which its expression is valid.

出现这个提示的时候还没有出作用域呀。。

论坛徽章:
0
5 [报告]
发表于 2009-12-24 13:41 |只看该作者
自己顶起来!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP