797 lines
47 KiB
Plaintext
797 lines
47 KiB
Plaintext
1
|
||
|
||
Interlisp-D Reference Manual
|
||
1
|
||
|
||
Interlisp-D Reference Manual
|
||
15. BREAKING, TRACING, AND ADVISING
|
||
1
|
||
|
||
15. BREAKING, TRACING, AND ADVISING
|
||
1
|
||
|
||
|
||
|
||
"15"15. BREAKING, TRACING, AND ADVISING
|
||
6
|
||
|
||
Interlisp 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. These are very useful debugging tools.
|
||
"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 NIL 1) and Debugging(DEBUGGING NIL Debugging NIL NIL 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 Interlisp system, there are three facilities which allow the user to (temporarily) modify selected function definitions so that he can follow the flow of control in his 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 (defined by the user) 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 values specified by the user) 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 user traces the function FACTORIAL. 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 the user had originally performed (BREAK FACTORIAL) instead of (TRACE FACTORIAL), and the user can evaluate various Interlisp forms and direct the course of the computation. In this case, the user examines the variable N, and instructs BREAK1 to return 1 as the value of this cell to FACTORIAL. The rest of the tracing proceeds without incident. The user would then presumably edit FACTORIAL 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, the user has constructed a non-recursive definition of FACTORIAL. He uses BREAKIN 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, the user tries to look at the value of N, but mistakenly types NN. The break is maintained, however, and no damage is done. After examining N and M the user allows the computation 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)ÿÿ |