首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

请问gdb调试有关问题

2012-04-21 
请教gdb调试问题[root@localhost code4]# gdb replace6GNU gdb (GDB) Red Hat Enterprise Linux (7.1-29.e

请教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的话,又重新开始了
请问如何执行下一步

[解决办法]
下一步就是n,要进入函数就是s,要打断点就是b,打好断点就可以c执行到断点停住,循环退出until,函数退出finish.


[解决办法]
18 if(argc != 5)
(gdb) 
19 {
20 printf("%1 filename source_string dest_string\n", argv[0]);
21 return 0;
22 }

你自己运行参数不对 导致argc !=5自然退出了。

r xxx
r后面加命令行参数就对了。

热点排行