2

So I want to run a program in gdb with the contents of a file as an argument. Then, when an EOF is hit, I want to be able to enter user input again. For a normal program in a terminal I can do something like this with the following command.

(cat input.txt; cat) | ./program

In gdb I can pass in the file arguments like this, but it continues to enter newlines forever after the end of the file has been reached.

(gdb) run < input.txt

It is almost as if stdin was not passed back to the program, similar to what happens if I simply do

(cat input.txt) | ./program

without the second cat. Is this even possible to do in gdb?

rjm27trekkie
  • 284
  • 3
  • 11

1 Answers1

0

You can run the program in one console and attach to it with gdb from another one when it is waiting for input. Therefore you will be able to enter program input in the 1st console and debug it in the 2nd.

ks1322
  • 33,961
  • 14
  • 109
  • 164
  • I have done this before. It does work, I was just wondering if it was possible to do it without 2 terminals. Is this a confirmation that it cannot be done entirely within gdb? – rjm27trekkie Apr 19 '17 at 21:01
  • I guess you can also save user input to a second file and concatenate it with `input.txt` and do it entirely within gdb. Something like in this question http://stackoverflow.com/q/13104206/72178. – ks1322 Apr 19 '17 at 21:29
  • That has the same issue I was having of not being able to take user input afterwards. Your answer works for me. I'm just going to accept it. – rjm27trekkie Apr 19 '17 at 21:47