Next: , Previous: Tracing optimized code, Up: Debugging   [Contents][Index]

7.6 Mercury debugger invocation

The executables of Mercury programs by default do not invoke the Mercury debugger even if some or all of their modules were compiled with some form of tracing, and even if the grade of the executable is a debugging grade. This is similar to the behaviour of executables created by the implementations of other languages; for example the executable of a C program compiled with ‘-g’ does not automatically invoke gdb or dbx etc when it is executed.

Unlike those other language implementations, when you invoke the Mercury debugger ‘mdb’, you invoke it not just with the name of an executable but with the command line you want to debug. If something goes wrong when you execute the command

prog arg1 arg2

and you want to find the cause of the problem, you must execute the command

mdb [mdb-options] prog arg1 arg2

because you do not get a chance to specify the command line of the program later.

When the debugger starts up, as part of its initialization it executes commands from the following three sources, in order:

  1. The file named by the MERCURY_DEBUGGER_INIT environment variable. Usually, ‘mdb’ sets this variable to point to a file that provides documentation for all the debugger commands and defines a small set of aliases. However, if MERCURY_DEBUGGER_INIT is already defined when ‘mdb’ is invoked, it will leave its value unchanged. You can use this override ability to provide alternate documentation. If the file named by MERCURY_DEBUGGER_INIT cannot be read, ‘mdb’ will print a warning, since in that case, that usual online documentation will not be available.
  2. The file named .mdbrc in your home directory. You can put your usual aliases and settings here.
  3. The file named .mdbrc in the current working directory. You can put program-specific aliases and settings here.

mdb will ignore any lines starting with the character ‘#’ in any of the above mentioned files.

mdb accepts the following options from the command line. The options should be given to mdb before the name of the executable to be debugged.

-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. This option allows the contents of a file to be piped to the program being debugged and not to mdb. For example, on Linux the command

mdb -t /dev/tty ./myprog < myinput

will cause the contents of myinput to be piped to the program ‘myprog’, but mdb will read its input from the terminal.

-w, --window, --mdb-in-window

Run mdb in a new window, with mdb’s I/O going to that window, but with the program’s I/O going to the current terminal. Note that this will not work on all systems.


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. Note that input and output redirection will not work with the ‘--program-in-window’ option. ‘--program-in-window’ will work on most Unix systems running the X Window System, even those for which ‘--mdb-in-window’ is not supported.

-c window-command, --window-command window-command

Specify the command used by the ‘--program-in-window’ option for executing a command in a new window. The default such command is ‘xterm -e’.

Next: , Previous: Tracing optimized code, Up: Debugging   [Contents][Index]