I want to debug a file, say file.c, and this file reads information from a txt file, say input.txt. So normally, to compile and run the program I would do the following:
gcc -std=c99 -g file.c -o file.exe
and to debug I would try the following:
gdb ./file.exe input.txt
However this doesn't work and fails with No such file exits. '(null)': Bad address when the program, file.c, attempts to open the file specified in argv[1] which input.txt is.
I have tried the following methods:
1. gdb ./file.exe
(gdb) run < input.txt
2. gdb ./file.exe
b main
(gdb) r
(gdb) call (int)dup2(open("input.txt",0),0)
$1 = 0
All with the same outcome as described above...No such file exits. '(null)': Bad address
The code is merely:
FILE *input = fopen(argv[1],"r");
(gdb) run input.txtgdb --args ...FILE *input = fopen(argv[1],"r");This will not compile. It needs: 1)#include <stdio.h>2)int main( void ){ FILE *input = fopen(argv[1],"r"); ....etc