1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#!/bin/sh
#-----------------------------------------------------------------------------#
# Copyright (C) 1998 The University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public License - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
#
# IMPORTANT: the manpage is produced automatically from this help
# message, so if you change the help message, don't forget to check
# that the manpage still looks OK.
Help="\
Name: mdb - Mercury debugger
Usage: mdb [<options>] <executable> [<args>]...
Description:
\`mdb' invokes the specified command \`<executable> <args>...'
with Mercury debugging enabled. If that command is a Mercury
program that was compiled with debugging enabled (e.g. using
the \`--debug' option), or if that command invokes such a
program, then mdb will cause the program to be executed under
the supervision of the Mercury internal debugger. Otherwise,
mdb will execute the command line as if the mdb prefix weren't
there.
By default, all the output of the debugger and the output of the
program being debugged will be interleaved on the same terminal
window. This can be avoided using the \`--tty' or \`--window'
options described below.
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 <window-command>, --window-command <window-command>
Specify the command used by the \`--window' option for
executing a command in a new window. The default such
command is \`xterm -e'.
Environment variables:
MERCURY_OPTIONS, MERCURY_DEBUGGER_INIT.
"
tty=
window=false
window_cmd="xterm -e"
#-----------------------------------------------------------------------------#
#
# process the command line options
#
case $# in
0) echo "Usage: mdb [<options>] <executable> [<arg> ...]" 1>&2
exit 1 ;;
esac
while : ; do
case "$1" in
--help)
echo "$Help"
exit 0 ;;
-t|--tty)
tty="$2";
shift; shift ;;
-t*)
tty="` expr $1 : '-t\(.*\)' `"
shift ;;
-w|--window)
window=true
shift ;;
-w-|--no-window)
window=false
shift ;;
-c|--window-command)
window_cmd="$2";
shift; shift ;;
--)
shift; break ;;
-*)
echo "$0: unknown option \`$1'" 1>&2
exit 1 ;;
*)
break ;;
esac
done
#-----------------------------------------------------------------------------#
#
# Figure out how we should invoke the command
#
invoke_cmd=
case "$window" in true)
invoke_cmd="$window_cmd"
#
# If windowing is enabled, check that DISPLAY is set, and if not,
# issue a warning message. This is needed because the default error
# message from xterm is very poor.
#
case "$DISPLAY" in "")
echo "$0: warning: environment variable \`DISPLAY' not set" 1>&2 ;;
esac ;;
esac
#-----------------------------------------------------------------------------#
#
# Figure out if/how we should redirect the mdb I/O streams
#
case "$tty" in
"")
case "$window" in
true)
#
# On Linux, we can use special files in /proc
# that refer to the file descriptors for a
# particular process.
#
stdin=/proc/$$/fd/0
stdout=/proc/$$/fd/1
stderr=/proc/$$/fd/2
if [ -f $stdin -a -f $stdout -a -f $stderr ]; then
redirect_opts="
--mdb-in $stdin
--mdb-out $stdout
--mdb-err $stderr
"
else
# In the general case, we can use the `tty' command.
# But that will only work if we're actually running
# on a terminal.
tty="`tty`"
case "$tty" in ""|"not a tty")
echo "$0: standard input stream is not a tty" 1>&2
exit 1
;;
esac
redirect_opts="--mdb-tty $tty"
fi
;;
false)
redirect_opts=""
;;
esac ;;
*)
redirect_opts="--mdb-tty $tty"
;;
esac
#-----------------------------------------------------------------------------#
#
# Set the environment variables used by the Mercury runtime to the
# the appropriate values to enabled debugging and to redirect mdb I/O,
# and then finally use $invoke_cmd to invoke the command.
#
enable_mdb_opt="-Di"
MERCURY_OPTIONS="$MERCURY_OPTIONS $redirect_opts $enable_mdb_opt"
export MERCURY_OPTIONS
MERCURY_DEBUGGER_INIT=${MERCURY_DEBUGGER_INIT-@DEFAULT_MERCURY_DEBUGGER_INIT_DIR@/mdbrc}
export MERCURY_DEBUGGER_INIT
exec $invoke_cmd "$@"
#-----------------------------------------------------------------------------#
|