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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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?
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 stackoverflow.com/q/13104206/72178.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.