8 个解决方案
#1
gdb>r exefile arg1 arg2 ...
#2
set args filename
#3
楼上的,我照你说的做了,但还是提示文件不能打开.
我程序运行格式是:filerwt in.txt
其中文件的当前目录是:/home/zgh/test
操作流程如下,我把我操作的步骤过程给你paste下来了,请指正
[zgh@ps test]$ pwd
/home/zgh/test
[zgh@ps test]$ ls
FileRWTest.c filerwt* in.txt test* test.c
[zgh@ps test]$ gdb -q filerwt
(gdb) set args in.txt
(gdb) b main
Breakpoint 1 at 0x8048556: file FileRWTest.c, line 9.
(gdb) r
Starting program: /home/zgh/test/filerwt in.txt
Breakpoint 1, main (argc=2, argv=0xbffffd04) at FileRWTest.c:9
9 if( (fp=fopen(argv[1],"r"))==NULL ){
(gdb) s
_IO_new_fopen (filename=0xbffffe13 "in.txt", mode=0x8048690 "r")
at iofopen.c:44
44 iofopen.c: No such file or directory.
(gdb) n
47 in iofopen.c
(gdb)
我程序运行格式是:filerwt in.txt
其中文件的当前目录是:/home/zgh/test
操作流程如下,我把我操作的步骤过程给你paste下来了,请指正
[zgh@ps test]$ pwd
/home/zgh/test
[zgh@ps test]$ ls
FileRWTest.c filerwt* in.txt test* test.c
[zgh@ps test]$ gdb -q filerwt
(gdb) set args in.txt
(gdb) b main
Breakpoint 1 at 0x8048556: file FileRWTest.c, line 9.
(gdb) r
Starting program: /home/zgh/test/filerwt in.txt
Breakpoint 1, main (argc=2, argv=0xbffffd04) at FileRWTest.c:9
9 if( (fp=fopen(argv[1],"r"))==NULL ){
(gdb) s
_IO_new_fopen (filename=0xbffffe13 "in.txt", mode=0x8048690 "r")
at iofopen.c:44
44 iofopen.c: No such file or directory.
(gdb) n
47 in iofopen.c
(gdb)
#4
回: happen23(微笑刺客):
你说的:gdb>r exefile arg1 arg2 ...好象不行的.请看:
[zgh@ps test]$ pwd
/home/zgh/test
[zgh@ps test]$ ls
FileRWTest.c filerwt* in.txt test* test.c
[zgh@ps test]$ gdb -silent
(gdb) r filerwt in.txt
Starting program: filerwt in.txt
No executable file specified.
Use the "file" or "exec-file" command.
(gdb)
我哪儿操作出错了呢?
你说的:gdb>r exefile arg1 arg2 ...好象不行的.请看:
[zgh@ps test]$ pwd
/home/zgh/test
[zgh@ps test]$ ls
FileRWTest.c filerwt* in.txt test* test.c
[zgh@ps test]$ gdb -silent
(gdb) r filerwt in.txt
Starting program: filerwt in.txt
No executable file specified.
Use the "file" or "exec-file" command.
(gdb)
我哪儿操作出错了呢?
#5
你“set args in.txt”的操作没有错误啊
程序不是正在正常运行嘛。
在“if( (fp=fopen(argv[1],"r"))==NULL )”一句step,就进入iofopen.c了
用next看是进入if体还是跳出if体。
程序不是正在正常运行嘛。
在“if( (fp=fopen(argv[1],"r"))==NULL )”一句step,就进入iofopen.c了
用next看是进入if体还是跳出if体。
#6
(gdb) r
Starting program: /home/zgh/test/filerwt in.txt
Breakpoint 1, main (argc=2, argv=0xbffffd24) at FileRWTest.c:9
9 if( (fp=fopen(argv[1],"r"))==NULL ){
(gdb) s
_IO_new_fopen (filename=0xbffffe35 "in.txt", mode=0x8048690 "r")
at iofopen.c:44
44 iofopen.c: No such file or directory. //此处为何出现"没这样的文件或目录"??
(gdb) n
47 in iofopen.c
(gdb) n
49 in iofopen.c
(gdb) n
50 in iofopen.c
(gdb) n
51 in iofopen.c
(gdb) n //执行next老是 in iofopen.c
不过,以后好象是在向下运行的
谢谢!!
Starting program: /home/zgh/test/filerwt in.txt
Breakpoint 1, main (argc=2, argv=0xbffffd24) at FileRWTest.c:9
9 if( (fp=fopen(argv[1],"r"))==NULL ){
(gdb) s
_IO_new_fopen (filename=0xbffffe35 "in.txt", mode=0x8048690 "r")
at iofopen.c:44
44 iofopen.c: No such file or directory. //此处为何出现"没这样的文件或目录"??
(gdb) n
47 in iofopen.c
(gdb) n
49 in iofopen.c
(gdb) n
50 in iofopen.c
(gdb) n
51 in iofopen.c
(gdb) n //执行next老是 in iofopen.c
不过,以后好象是在向下运行的
谢谢!!
#7
fopen()的源代码是在iofopen.c中的
在if时,就不用step了,直接next,系统函数的源代码没什么好跟的 :-)
在if时,就不用step了,直接next,系统函数的源代码没什么好跟的 :-)
#8
set args ...
#1
gdb>r exefile arg1 arg2 ...
#2
set args filename
#3
楼上的,我照你说的做了,但还是提示文件不能打开.
我程序运行格式是:filerwt in.txt
其中文件的当前目录是:/home/zgh/test
操作流程如下,我把我操作的步骤过程给你paste下来了,请指正
[zgh@ps test]$ pwd
/home/zgh/test
[zgh@ps test]$ ls
FileRWTest.c filerwt* in.txt test* test.c
[zgh@ps test]$ gdb -q filerwt
(gdb) set args in.txt
(gdb) b main
Breakpoint 1 at 0x8048556: file FileRWTest.c, line 9.
(gdb) r
Starting program: /home/zgh/test/filerwt in.txt
Breakpoint 1, main (argc=2, argv=0xbffffd04) at FileRWTest.c:9
9 if( (fp=fopen(argv[1],"r"))==NULL ){
(gdb) s
_IO_new_fopen (filename=0xbffffe13 "in.txt", mode=0x8048690 "r")
at iofopen.c:44
44 iofopen.c: No such file or directory.
(gdb) n
47 in iofopen.c
(gdb)
我程序运行格式是:filerwt in.txt
其中文件的当前目录是:/home/zgh/test
操作流程如下,我把我操作的步骤过程给你paste下来了,请指正
[zgh@ps test]$ pwd
/home/zgh/test
[zgh@ps test]$ ls
FileRWTest.c filerwt* in.txt test* test.c
[zgh@ps test]$ gdb -q filerwt
(gdb) set args in.txt
(gdb) b main
Breakpoint 1 at 0x8048556: file FileRWTest.c, line 9.
(gdb) r
Starting program: /home/zgh/test/filerwt in.txt
Breakpoint 1, main (argc=2, argv=0xbffffd04) at FileRWTest.c:9
9 if( (fp=fopen(argv[1],"r"))==NULL ){
(gdb) s
_IO_new_fopen (filename=0xbffffe13 "in.txt", mode=0x8048690 "r")
at iofopen.c:44
44 iofopen.c: No such file or directory.
(gdb) n
47 in iofopen.c
(gdb)
#4
回: happen23(微笑刺客):
你说的:gdb>r exefile arg1 arg2 ...好象不行的.请看:
[zgh@ps test]$ pwd
/home/zgh/test
[zgh@ps test]$ ls
FileRWTest.c filerwt* in.txt test* test.c
[zgh@ps test]$ gdb -silent
(gdb) r filerwt in.txt
Starting program: filerwt in.txt
No executable file specified.
Use the "file" or "exec-file" command.
(gdb)
我哪儿操作出错了呢?
你说的:gdb>r exefile arg1 arg2 ...好象不行的.请看:
[zgh@ps test]$ pwd
/home/zgh/test
[zgh@ps test]$ ls
FileRWTest.c filerwt* in.txt test* test.c
[zgh@ps test]$ gdb -silent
(gdb) r filerwt in.txt
Starting program: filerwt in.txt
No executable file specified.
Use the "file" or "exec-file" command.
(gdb)
我哪儿操作出错了呢?
#5
你“set args in.txt”的操作没有错误啊
程序不是正在正常运行嘛。
在“if( (fp=fopen(argv[1],"r"))==NULL )”一句step,就进入iofopen.c了
用next看是进入if体还是跳出if体。
程序不是正在正常运行嘛。
在“if( (fp=fopen(argv[1],"r"))==NULL )”一句step,就进入iofopen.c了
用next看是进入if体还是跳出if体。
#6
(gdb) r
Starting program: /home/zgh/test/filerwt in.txt
Breakpoint 1, main (argc=2, argv=0xbffffd24) at FileRWTest.c:9
9 if( (fp=fopen(argv[1],"r"))==NULL ){
(gdb) s
_IO_new_fopen (filename=0xbffffe35 "in.txt", mode=0x8048690 "r")
at iofopen.c:44
44 iofopen.c: No such file or directory. //此处为何出现"没这样的文件或目录"??
(gdb) n
47 in iofopen.c
(gdb) n
49 in iofopen.c
(gdb) n
50 in iofopen.c
(gdb) n
51 in iofopen.c
(gdb) n //执行next老是 in iofopen.c
不过,以后好象是在向下运行的
谢谢!!
Starting program: /home/zgh/test/filerwt in.txt
Breakpoint 1, main (argc=2, argv=0xbffffd24) at FileRWTest.c:9
9 if( (fp=fopen(argv[1],"r"))==NULL ){
(gdb) s
_IO_new_fopen (filename=0xbffffe35 "in.txt", mode=0x8048690 "r")
at iofopen.c:44
44 iofopen.c: No such file or directory. //此处为何出现"没这样的文件或目录"??
(gdb) n
47 in iofopen.c
(gdb) n
49 in iofopen.c
(gdb) n
50 in iofopen.c
(gdb) n
51 in iofopen.c
(gdb) n //执行next老是 in iofopen.c
不过,以后好象是在向下运行的
谢谢!!
#7
fopen()的源代码是在iofopen.c中的
在if时,就不用step了,直接next,系统函数的源代码没什么好跟的 :-)
在if时,就不用step了,直接next,系统函数的源代码没什么好跟的 :-)
#8
set args ...