免费注册 查看新帖 |

Chinaunix

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

用gdb调试段错误的时候怎么会正常执行结束?? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-08-23 14:58 |只看该作者 |倒序浏览
程序如下:

#include <stdio.h>


int
main(int argc, char *argv[]){

        char *str = "string1";

        str[strlen(str)] = 'E';
        printf("%s", str);

        exit(0);
}



调试过程如下:怎么在gdb下最后会成功输出呢?
[root@node1 zhangxb]# gdb a
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...
(gdb) l
1       #include <stdio.h>
2
3
4       int
5       main(int argc, char *argv[]){
6
7               char *str = "string1";
8
9               str[strlen(str)] = 'E';
10              printf("%s", str);
(gdb) break 9  
Breakpoint 1 at 0x80483a7: file a.c, line 9.
(gdb)
Note: breakpoint 1 also set at pc 0x80483a7.
Breakpoint 2 at 0x80483a7: file a.c, line 9.
(gdb)
Note: breakpoints 1 and 2 also set at pc 0x80483a7.
Breakpoint 3 at 0x80483a7: file a.c, line 9.
(gdb) r
Starting program: /home/zhangxb/a

Breakpoint 1, main (argc=1, argv=0xbfffd854) at a.c:9
9               str[strlen(str)] = 'E';
(gdb) p str
$1 = 0x8048488 "string1"
(gdb)
$2 = 0x8048488 "string1"
(gdb) n
10              printf("%s", str);
(gdb) p str
$3 = 0x8048488 "string1E%s"
(gdb) n
12              exit(0);
(gdb) n
string1E%s
Program exited normally.
(gdb)

[ 本帖最后由 zxbjlu1983 于 2006-8-23 14:59 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-12-07 16:23 |只看该作者
这不是已经正常执行结束了么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP