* New version of IRM New version of the IRM, updated to Medley. * moved to docs/medley-irm as discussed
1019 lines
102 KiB
Plaintext
1019 lines
102 KiB
Plaintext
MEDLEY REFERENCE MANUAL
|
||
ERRORS AND DEBUGGING
|
||
"14"14. ERRORS AND DEBUGGING
|
||
3
|
||
|
||
Occasionally, while a program is running, an error occurs which stops the computation. Errors can be caused in different ways. A coding mistake may have caused the wrong arguments to be passed to a function, or caused the function to attempt something illegal. For example, PLUS will cause an error if its arguments are not numbers. It is also possible to interrupt a computation by typing one of the ªinterrupt characters,º such as Control-D or Control-E (Medley interrupt characters are listed in Chapter 30). Finally, you can specify that certain functions automatically cause an error whenever they are entered (see Chapter 15). This facilitates debugging by allowing you to examine the context within the computation.
|
||
When an error occurs, the system can either reset and unwind the stack, or go into a ªbreakº, and attempt to debug the program. You can modify the mechanism that decides whether to unwind the stack or break, and is described in the Controlling When to Break section in this chapter. Within a break, Medley offers an extensive set of ªbreak commandsº.
|
||
This chapter explains what happens when errors occur. It also tells you how to handle program errors using breaks and break commands. The debugging capabilities of the break window facility are described, as well as the variables that control its operation. Finally, advanced facilities for modifying and extending the error mechanism are presented.
|
||
Breaks
|
||
1
|
||
|
||
One of the most useful debugging facilities in Medley is the ability to put the system into a ªbreakº, stopping a computation at any point, allowing you to interrogate the state of the world and affect the course of the computation. When a break occurs, a ªbreak windowº (see the Break Windows section below) is brought up near the TTY window of the broken process. The break window looks like a top-level executive window, except that the prompt character is ª:º instead of ª¬º as in the top-level executive. A break saves the environment where the break occurred, so that you may evaluate variables and expressions in the borken environment. In addition, the break program recognizes a number of useful ªbreak commandsº, providing an easy way to interrogate the state of the broken computation.
|
||
Breaks may be entered in several ways. Some interrupt characters (Chapter 30) automatically cause a break whenever you type them. Function errors may also cause a break, depending on the depth of the computation (see Controlling When to Break below). Finally, Medley provides facilities which make it easy to ªbreakº suspect functions so that they always cause a break whenever they are entered.
|
||
Within a break you have access to all of the power of Medley; you can do anything you can do at the top-level executive. For example, you can evaluate an expression, call the editor, change the function, and evaluate the expression again, all without leaving the break. You can also type in commands like REDO, and UNDO (Chapter 13), to redo or undo previously executed events, including break commands.
|
||
Similarly, you can prettyprint functions, define new functions or redefine old ones, load a file, compile functions, time a computation, etc. In addition, you can examine the stack (see Chapter 11), and even force a return back to some higher function via the functions RETFROM or RETEVAL.
|
||
Once a break occurs, you are in complete control of the flow of the computation, and the computation will not proceed without specific instruction from you. If you type in an expression whose evaluation causes an error, the break is maintained. Similarly if you abort a computation initiated from within the break (by typing Control-E), the break is maintained. Only if you give one of the commands that exits from the break, or evaluates a form which does a RETFROM or RETEVAL out of BREAK1, will the computation continue. Also, BREAK1 does not ªturn offº Control-D, so a Control-D will force an immediate return to the top level.
|
||
Break Windows
|
||
1
|
||
|
||
When a break occurs, a break window is brought up near the TTY window of the borken process and the terminal stream switched to it. The title of the break window is changed to the name of the broken function and the reason for the break. If a break occurs under a previous break, a new break window is created.
|
||
If a break is caused by a storage full error, the display break package will not try to open a new break window, since this would cause an infinite loop.
|
||
While in a break window, clicking the middle button brings up a menu of break commands: EVAL, EDIT, revert, , OK, BT, BT!, and ?=. Clicking on these commands is equivalent to typing the corresponding break commandm, except BT and BT! which behave differently from the typed-in commands (see Break Commands below).
|
||
The BT and BT! menu commands bring up a backtrace menu beside the break window showing the frames on the stack. BT shows frames for which REALFRAMEP is T; BT! shows all frames. When one of the frames is selected from the backtrace menu, it is grayed and the function name and the variables bound in that frame (including local variables and PROG variables) are printed in the ªbacktrace frame window.º If the left button is used for the selection, only named variables are printed. If the middle button is used, all variables are printed (variables without names appear as *var* N). The ªbacktrace frameº window is an inspect window (see Chapter 26). In this window, the left button is used to select the name of the function, the names of the variables or the values of the variables. For example, below is a picture of a break window with a backtrace menu created by BT. The OPENSTREAM stack frame has been selected, so its variables are shown in an inspect window on top of the break window:
|
||
|