2

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?

Community
  • 1
  • 1
Paul
  • 6,435
  • 4
  • 34
  • 45
  • duplicate of [http://stackoverflow.com/questions/455544/how-to-load-program-reading-stdin-and-taking-parameters-in-gdb](http://stackoverflow.com/questions/455544/how-to-load-program-reading-stdin-and-taking-parameters-in-gdb) ? – dfa Apr 20 '09 at 17:23

2 Answers2

3

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

Bastien Léonard
  • 60,478
  • 20
  • 78
  • 95
2

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).

coppro
  • 14,338
  • 5
  • 58
  • 73