2
votes

I'm trying to debug a program using gdb mode in emacs. It was compiled with g++, and I'm using cygwin. My program takes one command line argument, and also takes input from stdin, which I redirect from a file, like this:

program.exe inputFile.dat <otherInput.dat

The problem is, gdb is sending the string

"<otherInput.dat"

as a command line argument instead of redirecting stdin. How do I force gdb to redirect stdin?

EDIT:

Within gdb, I'm using the command:

run inputFile.dat <otherInput.dat

It doesn't work when I use gdb outside of emacs, either.

EDIT #2:

dfa pointed out a similar question: How to load program reading stdin and taking parameters in gdb?

Unfortunately, the accepted answer for that question isn't working for me... Could it be a cygwin-related bug?

2

2 Answers

3
votes

It seems that you have to use the run command:

You can redirect your program's input and/or output using shell redirection with the run > command. For example,

run > outfile

http://sourceware.org/gdb/current/onlinedocs/gdb_5.html#SEC24

2
votes

If you are using bash, you can attach gdb to the process immediately by doing PROGRAM ARGS < FILE & jobs -x gdb PROGRAM %1. Depending on the shell you use, you may find yourself having to use more creative methods (probably involving output from ps -C being redirected into gdb's command line).