Chinaunix

标题: 用gdb调试段错误的时候怎么会正常执行结束?? [打印本页]

作者: zxbjlu1983    时间: 2006-08-23 14:58
标题: 用gdb调试段错误的时候怎么会正常执行结束??
程序如下:

#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 编辑 ]
作者: magic475    时间: 2006-12-07 16:23
这不是已经正常执行结束了么?




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2