调试过程如下:怎么在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)