1

I need to debug a program that feeds on the output of another program. Hence, writing the output of the 'feeder' into a file, and piping that to the 'reader' doesn't work.

Normal run:

# feeder | ./reader

This is NOT an option here:

# feeder > data
# gdb ./reader
(gdb) run < data
3
  • Why is it NOT an option? Commented Nov 29, 2017 at 0:07
  • Because the output of feeder is not continuous. A dump to file, pipe from file would simply push all data at once. Commented Nov 30, 2017 at 0:44
  • Wonder why the downvote... Commented Nov 30, 2017 at 0:45

1 Answer 1

2

You can make the reader pause and wait for GDB to attach, as described here.

Then run:

feeder | ./reader

in one terminal, and gdb -p $(pgrep reader) in another terminal.

Once gdb is attached, let the reader proceed, and debug it normally.

Update:

Now that you've clarified your constraint, another way is to use named pipe:

mknod /tmp/.pipe p
feeder > /tmp/.pipe
gdb reader
(gdb) run < /tmp/.pipe
Sign up to request clarification or add additional context in comments.

2 Comments

Not the most elegant way, but a well placed sleep could work indeed.
@Bgs I think your question is under-specified, but you may be able to use a named pipe. Answer updated.

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.