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

user277465 picture user277465 · Dec 23, 2010 · Viewed 159.3k times · Source

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

rubenvb picture rubenvb · Dec 23, 2010

You can do this:

gdb --args path/to/executable -every -arg you can=think < of

The magic bit being --args.

Just type run in the gdb command console to start debugging.