1

I want to run gdb (GNU debugger) in Screen virtual terminal and grep the output in real time on adjacent Screen view.

How do I implement this arrangement? Normal pipe just redirects the output. I'm also curious how to bind Screen view (^A + c) to an existing process for IO.

EDIT:

I came up with the following solution. Created a named pipe with mkfifo pipe and executed gdb program | tee pipe in pty1. This will duplicate the output to a pipe. In pty2 I executed less -f pipe | grep foo to print the lines of interest.

I'm sure there have to be simpler way for such a trivial task though.

EDIT2:

The method mentioned above seems somewhat buggy. Gdb doesn't print anything to it's console unless something actually reads from the FIFO. Why is that? Also, when I try this method with my own program, which simply printf HelloWorld to stdout, nothing is printed in neither view.

EDIT3:

I figured out it's intentional that Tee blocks if nobody actually reads from the pipe. A matter of synchronization. Still I wonder, how is the original program able to read the input from keyboard even Tee controls now the terminal window. Or is it so that terminal input goes to stdin of original program and output to stdout of Tee?

3
  • 1
    Use a file istead of a pipe to prevent the blocking. Then, use tailf to watch that file (or tail -f to watch multiple files). Commented Mar 30, 2016 at 7:28
  • This seems like a good solution. Does kernel provide any non-blocking pipe mechanism, ie. passing data between processes without writing to disk? I also encountered interesting issue: if i printf something and sleep after that, nothing is ever written to pipe even the sleep is done. Why is it so? Commented Mar 30, 2016 at 13:32
  • Input and output are usually line-buffered, use fflush() or write a line-ending. That said, why doesn't a temp file work? I was under the impression that was just for debug logging. If you need something different, you need to be more precise about it.. Commented Mar 30, 2016 at 14:51

1 Answer 1

0

You don't have to start your program out of gdb. Just start it in one screen pane, and determine the pid (use top, pgrep, ps).

In the other pane you start the gdb session:

gdb <path_to_program> <pid>

This way you have a terminal to control gdb and a terminal to use the program you are debugging, both have their own input and outputs.

The only condition is that the program runs long enough for you to attach the debugger to the process. An easy way to do that is to make it wait for input at the beginning. You could also make it print its pid.

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

1 Comment

I think you misunderstand my intention. The program in other view is not the program being debugged, but program receiving the console text form gdb and filtering/formatting it. In this case grep, just printing the lines i'm interested.

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.