vegafish
vegafish

Reputation: 455

How do I pass the arguments from a text file to run a program under gdb?

I want to use the function like the command under gdb.

$ cat arg.txt | xargs ./binary

Is there any way to make it?

Upvotes: 5

Views: 5174

Answers (2)

vegafish
vegafish

Reputation: 455

Thanks and I got an simple solution.

(gdb) run $( cat arg.txt )

It is also possible to pass the output of a command to be the arguments.

(gdb) run $( ruby -e 'print( "text as arguments" )' )

Upvotes: 3

ks1322
ks1322

Reputation: 35716

When gdb is invoked via xargs it's stdin by default is redirected from /dev/null. Obviously gdb needs stdin to read and perform user input but it can't because stdin is /dev/null.

One way to solve this issue is to use xargs with --arg-file:

xargs --arg-file arg.txt gdb --args ./binary

See man xargs:

   -a file, --arg-file=file
          Read items from file instead of standard input.  If you use
          this option, stdin remains unchanged when commands are run.
          Otherwise, stdin is redirected from /dev/null.

Upvotes: 2

Related Questions