mdb I/O redirection
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Dec 18 16:43:02 AEDT 1998
While reviewing Tyson's recent mdb bug fix, I started thinking about
some possible alternatives for ways of telling mdb to run the program
in a different window.
Here's what I propose:
Usage: mdb [<options>] <executable> [<arguments>]
Options:
-t <file-name>, --tty <file-name>
Redirect all of the I/O for the debugger
to the device specified by <file-name>.
The I/O for the program being debugged
will not be redirected.
-w, --window
Run the program in a new window,
with the program's I/O going to that
window, but with mdb's I/O going
to the current terminal.
-c <command>, --window-command <command>
Specify the command used by the --window option
for creating a new window. The default command
that it uses is `xterm -e'.
Comments?
--------------------
P.S.
It would be easy to make things a lot more complicated
than that. For completeness, I include below a description
of additional options, etc., that I considered.
I decided against providing the additional functionality
below because I didn't think it was worth the complexity.
(1) Provide the new functionality using options to mdb:
Usage: mdb [<options>] <executable> [<arguments>]
Options:
--prog-in <file-name>
--prog-out <file-name>
--prog-err <file-name>
Redirect standard input, standard output, or
standard error stream (respectively) for the
program being debugged to the file or device
specified by <file-name>.
--prog-tty <file-name>
Redirect all of the standard streams for the
program being debugged to the file or device
specified by <file-name>.
--mdb-in <file-name>
--mdb-out <file-name>
--mdb-err <file-name>
Redirect the debugger input, the debugger output, or
the debugger error messages (respectively) for mdb
to the file or device specified by <file-name>.
--mdb-tty <file-name>
Redirect all of the I/O for the debugger
to the file or device specified by <file-name>.
--prog-in-window
Run the program in a new xterm window.
--mdb-in-window
Run the program in a new xterm window.
--window-command <command>
Specify the command used by the --prog-in-window
or --mdb-in-window options for creating a new window.
The default command that these options use is
`xterm -e'.
(2) add new functionality without adding new options
Description:
mbd's I/O normally goes to and from the current
terminal, but you can redirect it using the normal
shell I/O redirection.
The I/O for the program being debugged normally goes to
and from the same streams used for mdb, but you can
redirect it by specificing a different command name in
the arguments to mdb. The command specified in the
arguments to mdb need not be the program to be
debugged; it can be a command which _invokes_ the
program to be debugged. The command can for example
open a new window and redirect the program's I/O to
that different window.
Examples:
mdb xterm -e ./a.out arg1 arg2
Run the program `a.out' in a new xterm window;
mdb's input and output will go to the current
terminal, but the program's input and output
will go to the new xterm window.
mdb sh -c './a.out </dev/tty2 >/dev/tty2 2>&1'
Debug the program `a.out' with the program's
I/O redirected to /dev/tty2; mdb's input and
output will go to the current terminal.
mdb ./a.out < infile > outfile
Debug the program `a.out' with the input and
output for *both* mdb and the program being
debugged being redirected to/from the specified
files.
mdb sh -c './a.out <prog-in >prog-out' <mdb-in >mdb-out
Debug the program `a.out' with the input and
output for mdb going to/from the files `mdb-in'
and `mdb-out' and with the program's output
going to/from the files `prog-in' and `prog-out'.
Unfortunately, redirecting the program's output without also
redirecting mdb's output is very tricky to implement portably.
It is trivial to implement on Linux, by having mdb
pass e.g. MERCURY_OPTIONS="--mdb-stdin /proc/$$/0 ..."
to ensure that debugger input comes from the stdin of
the mdb script process rather than the stdin of the
debuggee, However, I think it may be infeasibly
difficult to implement on other OSs.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh> | but source code lives forever"
PGP: finger fjh at 128.250.37.3 | -- leaked Microsoft memo.
More information about the developers
mailing list