uki uki - 1 year ago 100
C++ Question

How to pass arguments and redirect stdin from a file to program run in gdb?

I usually run a program as :

./a.out arg1 arg2 <file

I would like to debug it using gdb.

I am aware of the
set args
functionality, but that only works from the gdb prompt.

Answer Source

Pass the arguments to the run command from within gdb.

$ gdb ./a.out
(gdb) r < t
Starting program: /dir/a.out < t
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download