How to debug program reading from stdin in gdb

I’d like to ask how to debug some program using gdb that reads from stdin.

g++ -Wall test.c -o test

and I’m running it as

./test < test.in

I tried to debug it in gdb (none of those two tries worked)

gdb test < test.in

or (inspiration http://www.velocityreviews.com/forums/t645602-using-gbd-to-debug-a-program-reading-from-stdin.html, http://stackoverflow.com/questions/2953658/gdb-trouble-with-stdin-redirection)

gdb test

and in gdb

(gdb) run < test.in

but I’m getting

Starting program:  < test.in
No executable file specified.
Use the "file" or "exec-file" command.

Any idea what am I doing wrong?

1 Like

You forgot to add -g option while compiling. This produces debugging information which gdb can use.
So the compilation will be

g++ -g -Wall test.c -o test

And I always go for the second method you mentioned for redirecting stdin.

You can read my answer http://discuss.codechef.com/questions/4364/how-to-debug-after-many-attempts/4397

2 Likes

Thanks, that worked :wink: