日期:2014-05-16  浏览次数:20890 次

请教gdb调试问题
[root@localhost code4]# gdb replace6
GNU gdb (GDB) Red Hat Enterprise Linux (7.1-29.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/wangdu/code4/replace6...done.
(gdb) l
9 { int fd1,fd2;
10 char *filename1;
11 char *filename2;
12 char *src, *dest;
13 char *content;
14 char *p;
15 char *tmp;
16 struct stat st;
17 int size;
18 if(argc != 5)
(gdb) 
19 {
20 printf("%1 filename source_string dest_string\n", argv[0]);
21 return 0;
22 }
23 filename1 = argv[1];
24 filename2=argv[2];
25 src = argv[3];
26 dest = argv[4];
27 fd1 = open(filename1, O_RDONLY);
28 if(fd1 < 0)
(gdb) 
29 {
30 printf("Open file failed:%s\n", strerror(errno));
31 return 0;
32 }
33 fstat(fd1, &st);
34 printf("File size:%d\n", st.st_size);
35 content = (char *)malloc(st.st_size+1);
36 if(content == NULL)
37 {
38 close(fd1);
(gdb) 
39 printf("No enough memory\n");
40 return 0;
41 }
42 size = read(fd1, content, st.st_size);
43 if(size <= 0)
44 {
45 return 0;
46 }
47
48 content[size] = '\0';
(gdb) 
49 fd2=open(filename2,O_WRONLY|O_CREAT|O_APPEND);
50 tmp=content;
51 while(1)
52 {
53 p=strstr(tmp,src);
54 if(p == NULL)
55 {
56 write(fd2,tmp,strlen(tmp));
57 break;
58 }
(gdb) 
59 write(fd2,tmp,p-tmp);
60 write(fd2,dest,strlen(dest));
61 tmp=p+strlen(src);
62 } 
63 //unlink(filename1);
64 close(fd2);
65 return 0;
66 }
(gdb) b main 
Breakpoint 1 at 0x80485f0: file replace6.c, line 18.
(gdb) r
Starting program: /home/wangdu/code4/replace6 

Breakpoint 1, main (argc=1, argv=0xbffff684) at replace6.c:18
18 if(argc != 5)
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.7.el6.i686
(gdb) n
20 printf("%1 filename source_string dest_string\n", argv[0]);
(gdb) n
%1 filename source_string dest_string
21 return 0;
(gdb) n
66 }
(gdb) n
0x00bbdcc6 in __libc_start_main () from /lib/libc.so.6
(gdb) n
Single stepping until exit from function __libc_start_main, 
which has no line number information.

Program exited normally.
(gdb) n
The program is not being run

要是再run的话,又重新开始了
请问如何执行下一步

------解决方案--------------------