* New version of IRM New version of the IRM, updated to Medley. * moved to docs/medley-irm as discussed
63 lines
46 KiB
Plaintext
63 lines
46 KiB
Plaintext
MEDLEY REFERENCE MANUAL
|
||
BREAKING, TRACING, AND ADVISING
|
||
"15"15. BREAKING, TRACING, AND ADVISING
|
||
3
|
||
|
||
Medley provides several different facilities for modifing the behavior of a function without actually editing its definition. By ªbreakingº a function, you can cause breaks to occur at various times in the running of an incomplete program, so that the program state can be inspected. ªTracingº a function causes information to be printed every time the function is entered or exited.
|
||
ªAdvisingº is a facility for specifying longer-term function modifications. Even system functions can be changed through advising.
|
||
Breaking Functions(BREAKING% FUNCTIONS NIL Breaking% Functions NIL ("15") 1) and Debugging(DEBUGGING NIL Debugging NIL ("15") 1)
|
||
1
|
||
|
||
Debugging a collection of Lisp functions involves isolating problems within particular functions and/or determining when and where incorrect data are being generated and transmitted. In the Medley, there are three facilities which allow you to (temporarily) modify selected function definitions so that you can follow the flow of control in your programs, and obtain this debugging information. All three redefine functions in terms of a system function, BREAK1 (see Chapter 14).
|
||
BREAK modifies the definition of a function FN, so that whenever FN is called and a break condition (user-defined) is satisfied, a function break occurs. You can then interrogate the state of the machine, perform any computation, and continue or return from the call.
|
||
TRACE modifies a definition of a function FN so that whenever FN is called, its arguments (or some other user-specified values) are printed. When the value of FN is computed it is printed also. TRACE is a special case of BREAK.
|
||
BREAKIN allows you to insert a breakpoint inside an expression defining a function. When the breakpoint is reached and if a break condition (defined by you) is satisfied, a temporary halt occurs and you can again investigate the state of the computation.
|
||
The following two examples illustrate these facilities. In the first example, the function FACTORIAL is traced. TRACE redefines FACTORIAL so that it print its arguments and value, and then goes on with the computation. When an error occurs on the fifth recursion, a full interactive break occurs. The situation is then the same as though (BREAK FACTORIAL) had been performed instead of (TRACE FACTORIAL), now you can evaluate various Interlisp forms and direct the course of the computation. In this case, the variable N is examined, and BREAK1 is instructed to return 1 as the value of this cell to FACTORIAL. The rest of the tracing proceeds without incident. Presumably, FACTORIAL would be edited to change L to 1.
|
||
¬PP FACTORIAL
|
||
(FACTORIAL
|
||
[LAMBDA (N)
|
||
(COND
|
||
((ZEROP N)
|
||
L)
|
||
(T (ITIMES N (FACTORIAL (SUB1 N])
|
||
FACTORIAL
|
||
¬(TRACE FACTORIAL)
|
||
(FACTORIAL)
|
||
¬(FACTORIAL 4)
|
||
FACTORIAL:
|
||
N = 4
|
||
FACTORIAL:
|
||
N = 3
|
||
FACTORIAL:
|
||
N = 2
|
||
FACTORIAL:
|
||
N = 1
|
||
FACTORIAL:
|
||
N = 0
|
||
UNBOUND ATOM
|
||
L
|
||
(FACTORIAL BROKEN)
|
||
:N
|
||
0
|
||
:RETURN 1
|
||
FACTORIAL = 1
|
||
FACTORIAL = 1
|
||
FACTORIAL = 2
|
||
FACTORIAL = 6
|
||
FACTORIAL = 24
|
||
24
|
||
¬
|
||
In the second example, a non-recursive definition of FACTORIAL has been constructed. BREAKIN is used to insert a call to BREAK1 just after the PROG label LOOP. This break is to occur only on the last two iterations, when N is less than 2. When the break occurs, in trying to look at the value of N, NN is mistakenly typed. The break is maintained, however, and no damage is done. After examining N and M the computation is allowed to continue by typing OK. A second break occurs after the next iteration, this time with N = 0. When this break is released, the function FACTORIAL returns its value of 120.
|
||
¬PP FACTORIAL
|
||
(FACTORIAL
|
||
[LAMBDA (N)
|
||
(PROG ((M 1))
|
||
LOOP (COND
|
||
((ZEROP N)
|
||
(RETURN M)))
|
||
(SETQ M (ITIMES M N))
|
||
(SETQ N (SUB1 N))
|
||
(GO LOOP])
|
||
FACTORIAL
|
||
¬(BREAKIN FACTORIAL (AFTER LOOP) (ILESSP N 2]
|
||
SEARCHING...
|
||
FACTORIAL
|
||
¬((FACTORIAL 5)
|
||
((FACTORIAL) BROKEN)
|
||
:NN
|
||
U.B.A.
|
||
NN
|
||
(FACTORIAL BROKEN AFTER LOOP)
|
||
:N
|
||
1
|
||
:M
|
||
120
|
||
:OK
|
||
(FACTORIAL)
|
||
|
||
((FACTORIAL) BROKEN)
|
||
:N
|
||
0
|
||
:OK
|
||
(FACTORIAL)ÿÿ |