DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Using the command line interface of debug

Redirecting process input/output

As long as you are debugging one process at a time, or even multiple programs in a pipeline, I/O will probably not be confusing because there is only one process reading from standard input or writing to standard output at a time. However, if you are debugging several processes that are all doing I/O independently it may not be easy to tell which message came from which program, nor can you guarantee which program will receive the characters you type in to standard input. Using the debugger's redirection capability will help you keep the I/O straight. The -r option (for redirection) to the create command will tell debug to set up a pseudo-terminal for that program's I/O. debug will tell you the name of the pseudo-terminal and all I/O to or from the program will be labeled with that
name. For example, here are two programs, each writing to a different pseudo-terminal:

   debug> create -r a
   New program a (process p1) created
   HALTED p1 [main in a.c]
    ...
   Program I/O redirected to pseudo-terminal pts3
   debug> create -r b
   New program b (process p2) created
   HALTED p2 [...]
   ...
   Program I/O redirected to pseudo-terminal pts4
   debug> run -p all
   pts3> output from program a
   pts4> output from program b
   pts4> more output
   Process p2 has exited
   Current process is now p1, program a
   pts3> more output
Similarly, with the input command you can direct a string to a particular program if the program's I/O has been redirected to a pseudo-terminal. Here, cat echoes a string that was directed to it with the input command:
   debug> create -r /usr/bin/cat
   Warning: No -g information in /usr/bin/cat
   New program cat (process p1) created
   HALTED p1 [...]
   ...
   Program I/O redirected to pseudo-terminal pts0
   debug> run -b
   debug> input -r pts0 "this is an example"
   pts0> this is an example
input normally adds a newline to every string. You can suppress the newline with the -n option:
   debug> input -n -r pts0 "this example "
   debug> input -r pts0 "is on one line"
   pts0> this example is on one line
Since the program is associated with one specific pseudo-terminal, input -p a.out or input -p p1 would also have the same effect. (You don't need either -p or -r if the input is going to the current program.) However, a pseudo-terminal may have more than one object associated with it. The I/O for all objects resulting from a single create command, and from all processes forked and exec'd from the original program, are directed to the same pseudo-terminal.

If you want the I/O for all created processes to be directed to pseudo-terminals, you can change the default behavior of the create command by setting the debugger variable %redir to yes.


Next topic: Reading the address map
Previous topic: Change command

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004