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 <

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

gdb test <

or (inspiration,

gdb test

and in gdb

(gdb) run <

but I’m getting

Starting program:  <
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


Thanks, that worked :wink: