How to load program reading stdin and taking parameters in gdb?

If you were doing it from a shell you'd do it like this:

% gdb myprogram
gdb> run params ... < input.txt

This seems to work within emacs too.


For completeness' sake upon starting a debugging session there is also the --args option. ie)

gdb gdbarg1 gdbarg2 --args yourprog arg1 arg2 -x arg3

There are several ways to do it:

$ gdb myprogram
(gdb) r -path /home/user/work < input.txt

or

$ gdb myprogram
(gdb) set args -path /home/user/work < input.txt
(gdb) r

or

$ gdb -ex 'set args -path /home/user/work < input.txt' myprogram
(gdb) r

where the gdb run command (r) uses by default the arguments as set previously with set args.