/[cmucl]/src/code/ntrace.lisp
ViewVC logotype

Contents of /src/code/ntrace.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations)
Wed May 27 01:09:51 1992 UTC (21 years, 11 months ago) by ram
Branch: MAIN
Branch point for: patch_16
Changes since 1.7: +595 -274 lines
Substantially rewritten.  TRACE has a new syntax.  It now subsumes the old
encapsulation-based trace via the :ENCAPSULATE option.  Interpreted functions
and generic functions are traced via encapsulation by default, which works.
Conditional stuff works much better.
1 chiles 1.1 ;;; -*- Package: debug -*-
2     ;;;
3     ;;; **********************************************************************
4     ;;; This code was written as part of the CMU Common Lisp project at
5     ;;; Carnegie Mellon University, and has been placed in the public domain.
6     ;;; If you want to use this code or any part of CMU Common Lisp, please contact
7     ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
8     ;;;
9     (ext:file-comment
10 ram 1.8 "$Header: /tiger/var/lib/cvsroots/cmucl/src/code/ntrace.lisp,v 1.8 1992/05/27 01:09:51 ram Exp $")
11 chiles 1.1 ;;;
12     ;;; **********************************************************************
13     ;;;
14 ram 1.8 ;;; This is a tracing facility based on breakpoints.
15 chiles 1.1 ;;;
16 ram 1.8 ;;; Written by Rob MacLachlan and Bill Chiles.
17 chiles 1.1 ;;;
18     ;;; **********************************************************************
19     ;;;
20 chiles 1.2 (in-package "LISP")
21    
22     (export '(trace untrace))
23    
24 chiles 1.1 (in-package "DEBUG")
25    
26 ram 1.8 (export '(*trace-values* *max-trace-indentation* *trace-encapsulate-default*))
27 chiles 1.1
28 ram 1.7 (defvar *trace-values* nil
29     "This is bound to the returned values when evaluating :BREAK-AFTER and
30     :PRINT-AFTER forms.")
31    
32 ram 1.8 (defvar *max-trace-indentation* 40
33     "If the trace indentation exceeds this value, then indentation restarts at
34     0.")
35 chiles 1.2
36 ram 1.8 (defvar *trace-encapsulate-default* :default
37     "The default value for the :ENCAPSULATE option to trace.")
38    
39 chiles 1.1
40 ram 1.8 ;;;; Internal state:
41    
42     ;;; A hash-table that maps each traced function to the TRACE-INFO. The entry
43     ;;; for a closure is the shared function-entry object.
44 chiles 1.1 ;;;
45 ram 1.8 (defvar *traced-functions* (make-hash-table :test #'eq))
46 chiles 1.2
47 ram 1.8 ;;; The TRACE-INFO structure represents all the information we need to trace a
48     ;;; given function.
49     ;;;
50     (defstruct (trace-info
51     (:print-function
52     (lambda (s stream d)
53     (declare (ignore d))
54     (print-unreadable-object (s stream)
55     (format stream "Trace-Info ~S" (trace-info-what s)))))
56     (:make-load-form-fun :just-dump-it-normally))
57     ;;
58     ;; The original representation of the thing traced.
59     (what nil :type (or function cons symbol))
60     ;;
61     ;; True if What is a function name whose definition we should track.
62     (named nil)
63     ;;
64     ;; True if tracing is to be done by encapsulation rather than breakpoints.
65     ;; T implies Named.
66     (encapsulated *trace-encapsulate-default*)
67     ;;
68     ;; True if this trace has been untraced.
69     (untraced nil)
70     ;;
71     ;; Breakpoints we set up to trigger tracing.
72     (start-breakpoint nil :type (or di:breakpoint null))
73     (end-breakpoint nil :type (or di:breakpoint null))
74     ;;
75     ;; The list of function names for wherein. NIL means unspecified.
76     (wherein nil :type list)
77     ;;
78     ;; The following slots represent the forms that we are supposed to evaluate
79     ;; on each iteration. Each form is represented by a cons (Form . Function),
80     ;; where the Function is the cached result of coercing Form to a function.
81     ;; Forms which use the current environment are converted with
82     ;; PREPROCESS-FOR-EVAL, which gives us a one-arg function.
83     ;; Null environment forms also have one-arg functions, but the argument is
84     ;; ignored. NIL means unspecified (the default.)
85     ;;
86     ;; Current environment forms:
87     (condition nil)
88     (break nil)
89     ;;
90     ;; List of current environment forms:
91     (print () :type list)
92     ;;
93     ;; Null environment forms.
94     (condition-after nil)
95     (break-after nil)
96     ;;
97     ;; List of null environment forms
98     (print-after () :type list))
99 chiles 1.1
100 ram 1.8 ;;; This is a list of conses (function-end-cookie . condition-satisfied),
101     ;;; which we use to note distinct dynamic entries into functions. When we
102     ;;; enter a traced function, we add a entry to this list holding the new
103     ;;; end-cookie and whether the trace condition was statisfied. We must save
104     ;;; the trace condition so that the after breakpoint knows whether to print.
105     ;;; The length of this list tells us the indentation to use for printing TRACE
106     ;;; messages.
107     ;;;
108     ;;; This list also helps us synchronize the TRACE facility dynamically for
109     ;;; detecting non-local flow of control. Whenever execution hits a
110     ;;; :function-end breakpoint used for TRACE'ing, we look for the
111     ;;; function-end-cookie at the top of *traced-entries*. If it is not there, we
112     ;;; discard any entries that come before our cookie.
113     ;;;
114     ;;; When we trace using encapsulation, we bind this variable and add
115     ;;; (nil . condition-satisfied), so a NIL "cookie" marks an encapsulated
116     ;;; tracing.
117     ;;;
118     (defvar *traced-entries* ())
119     (declaim (list *traced-entries*))
120 ram 1.7
121 ram 1.8 ;;; This variable is used to discourage infinite recursions when some trace
122     ;;; action invokes a function that is itself traced. In this case, we quietly
123     ;;; ignore the inner tracing.
124     ;;;
125     (defvar *in-trace* nil)
126    
127    
128     ;;;; Utilities:
129    
130 ram 1.7 ;;; TRACE-FDEFINITION -- Internal
131     ;;;
132 ram 1.8 ;;; Given a function name, a function or a macro name, return the raw
133     ;;; definition and some information. "Raw" means that if the result is a
134     ;;; closure, we strip off the closure and return the bare code. The second
135     ;;; value is T if the argument was a function name. The third value is one of
136     ;;; :COMPILED, :COMPILED-CLOSURE, :INTERPRETED, :INTERPRETED-CLOSURE and
137     ;;; :FUNCALLABLE-INSTANCE.
138 ram 1.7 ;;;
139     (defun trace-fdefinition (x)
140 ram 1.8 (multiple-value-bind
141     (res named-p)
142     (typecase x
143     (symbol
144     (cond ((special-form-p x)
145     (error "Can't trace special form ~S." x))
146     ((macro-function x))
147     (t
148     (values (fdefinition x) t))))
149     (function x)
150     (t (values (fdefinition x) t)))
151     (if (eval:interpreted-function-p res)
152     (values res named-p (if (eval:interpreted-function-closure res)
153     :interpreted-closure :interpreted))
154     (case (kernel:get-type res)
155     (#.vm:closure-header-type
156     (values (kernel:%closure-function res) named-p :compiled-closure))
157     (#.vm:funcallable-instance-header-type
158     (values res named-p :funcallable-instance))
159     (t (values res named-p :compiled))))))
160 ram 1.7
161    
162 ram 1.8 ;;; TRACE-REDEFINED-UPDATE -- Internal
163 chiles 1.1 ;;;
164 ram 1.8 ;;; When a function name is redefined, and we were tracing that name, then
165     ;;; untrace the old definition and trace the new one.
166 chiles 1.1 ;;;
167 ram 1.8 (defun trace-redefined-update (fname new-value)
168     (when (fboundp fname)
169     (let* ((fun (trace-fdefinition fname))
170     (info (gethash fun *traced-functions*)))
171     (when (and info (trace-info-named info))
172     (untrace-1 fname)
173     (trace-1 fname info new-value)))))
174 chiles 1.1 ;;;
175 ram 1.8 (push #'trace-redefined-update ext:*setf-fdefinition-hook*)
176 chiles 1.1
177 ram 1.8
178     ;;; COERCE-FORM, COERCE-FORM-LIST -- Internal
179     ;;;
180     ;;; Annotate some forms to evaluate with pre-converted functions. Each form
181     ;;; is really a cons (exp . function). Loc is the code location to use for
182     ;;; the lexical environment. If Loc is NIL, evaluate in the null environment.
183     ;;; If Form is NIL, just return NIL.
184     ;;;
185     (defun coerce-form (form loc)
186     (when form
187     (let ((exp (car form)))
188     (if (di:code-location-p loc)
189     (let ((fun (di:preprocess-for-eval exp loc)))
190     (cons exp
191     #'(lambda (frame)
192     (let ((*current-frame* frame))
193     (funcall fun frame)))))
194     (let* ((bod (ecase loc
195     ((nil) exp)
196     (:encapsulated
197     `(flet ((debug:arg (n)
198     (declare (special argument-list))
199     (elt argument-list n)))
200     (declare (ignorable #'debug:arg))
201     ,exp))))
202     (fun (coerce `(lambda () ,bod) 'function)))
203     (cons exp
204     #'(lambda (frame)
205     (declare (ignore frame))
206     (let ((*current-frame* nil))
207     (funcall fun)))))))))
208     ;;;
209     (defun coerce-form-list (forms loc)
210     (mapcar #'(lambda (x) (coerce-form x loc)) forms))
211    
212    
213     ;;; PRINT-TRACE-INDENTATION -- Internal
214     ;;;
215     ;;; Print indentation according to the number of trace entries. Entries
216     ;;; whose condition was false don't count.
217     ;;;
218     (defun print-trace-indentation ()
219     (let ((depth 0))
220     (dolist (entry *traced-entries*)
221     (when (cdr entry) (incf depth)))
222     (format t "~&~VT~D: "
223     (+ (mod (* depth 2) (- *max-trace-indentation* 2)) 2)
224     depth)))
225    
226    
227     ;;; TRACE-WHEREIN-P -- Internal.
228     ;;;
229     ;;; Return true if one of the Names appears on the stack below Frame.
230     ;;;
231     (defun trace-wherein-p (frame names)
232     (do ((frame (di:frame-down frame) (di:frame-down frame)))
233     ((not frame) nil)
234     (when (member (di:debug-function-name (di:frame-debug-function frame))
235     names :test #'equal)
236     (return t))))
237    
238     ;;; TRACE-PRINT -- Internal
239     ;;;
240     ;;; Handle print and print-after options.
241     ;;;
242     (defun trace-print (frame forms)
243     (dolist (ele forms)
244     (fresh-line)
245     (print-trace-indentation)
246     (format t "~S = ~S" (car ele) (funcall (cdr ele) frame))))
247    
248     ;;; TRACE-MAYBE-BREAK -- Internal
249     ;;;
250     ;;; Test a break option, and break if true.
251     ;;;
252     (defun trace-maybe-break (info break where frame)
253     (when (and break (funcall (cdr break) frame))
254     (di:flush-frames-above frame)
255     (let ((*stack-top-hint* frame))
256     (break "Breaking ~A traced call to ~S:" where
257     (trace-info-what info)))))
258    
259     ;;; DISCARD-INVALID-ENTRIES -- Internal
260     ;;;
261     ;;; This function discards any invalid cookies on our simulated stack.
262     ;;; Encapsulated entries are always valid, since we bind *traced-entries* in
263     ;;; the encapsulation.
264     ;;;
265     (defun discard-invalid-entries (frame)
266     (loop
267     (when (or (null *traced-entries*)
268     (let ((cookie (caar *traced-entries*)))
269     (or (not cookie)
270     (di:function-end-cookie-valid-p frame cookie))))
271     (return))
272     (pop *traced-entries*)))
273    
274    
275     ;;;; Hook functions:
276    
277     ;;; TRACE-START-BREAKPOINT-FUN -- Internal.
278     ;;;
279     ;;; Return a closure that can be used for a function start breakpoint hook
280     ;;; function and a closure that can be used as the FUNCTION-END-COOKIE
281     ;;; function. The first communicates the sense of the Condition to the second
282     ;;; via a closure variable.
283     ;;;
284     (defun trace-start-breakpoint-fun (info)
285     (let (conditionp)
286     (values
287     #'(lambda (frame bpt)
288     (declare (ignore bpt))
289     (discard-invalid-entries frame)
290     (let ((condition (trace-info-condition info))
291     (wherein (trace-info-wherein info)))
292     (setq conditionp
293     (and (not *in-trace*)
294     (or (not condition)
295     (funcall (cdr condition) frame))
296     (or (not wherein)
297     (trace-wherein-p frame wherein)))))
298    
299     (when conditionp
300     (let ((*print-length* (or *debug-print-length* *print-length*))
301     (*print-level* (or *debug-print-level* *print-level*))
302     (*standard-output* *trace-output*)
303     (*in-trace* t))
304     (fresh-line)
305     (print-trace-indentation)
306     (if (trace-info-encapsulated info)
307     (locally (declare (special basic-definition argument-list))
308     (prin1 `(,(trace-info-what info) ,@argument-list)))
309     (print-frame-call-1 frame nil))
310     (terpri)
311     (trace-print frame (trace-info-print info)))
312     (trace-maybe-break info (trace-info-break info) "before" frame)))
313    
314     #'(lambda (frame cookie)
315     (declare (ignore frame))
316     (push (cons cookie conditionp) *traced-entries*)))))
317    
318    
319     ;;; TRACE-END-BREAKPOINT-FUN -- Internal
320     ;;;
321     ;;; This prints a representation of the return values delivered. First,
322     ;;; this checks to see that cookie is at the top of *traced-entries*; if it is
323     ;;; not, then we need to adjust this list to determine the correct indentation
324     ;;; for output. We then check to see if the function is still traced and that
325     ;;; the condition succeeded before printing anything.
326 chiles 1.1 ;;;
327 ram 1.8 (defun trace-end-breakpoint-fun (info)
328     #'(lambda (frame bpt *trace-values* cookie)
329     (declare (ignore bpt))
330     (unless (eq cookie (caar *traced-entries*))
331     (setf *traced-entries*
332     (member cookie *traced-entries* :key #'car)))
333    
334     (let ((entry (pop *traced-entries*)))
335     (when (and (not (trace-info-untraced info))
336     (or (cdr entry)
337     (let ((cond (trace-info-condition-after info)))
338     (and cond (funcall (cdr cond) frame)))))
339     (let ((*print-length* (or *debug-print-length* *print-length*))
340     (*print-level* (or *debug-print-level* *print-level*))
341     (*standard-output* *trace-output*)
342     (*in-trace* t))
343     (print-trace-indentation)
344     (format t "~S returned " (trace-info-what info))
345     (dolist (v *trace-values*)
346     (prin1 v)
347     (write-char #\space))
348     (trace-print frame (trace-info-print-after info))
349     (terpri))
350     (trace-maybe-break info (trace-info-break-after info)
351     "after" frame)))))
352    
353    
354     ;;; TRACE-CALL -- Internal
355 chiles 1.2 ;;;
356 ram 1.8 ;;; This function is called by the trace encapsulation. It calls the
357     ;;; breakpoint hook functions with NIL for the breakpoint and cookie, which
358     ;;; we have cleverly contrived to work for our hook functions.
359 chiles 1.2 ;;;
360 ram 1.8 (defun trace-call (info)
361     (multiple-value-bind
362     (start cookie)
363     (trace-start-breakpoint-fun info)
364     (let ((frame (di:frame-down (di:top-frame))))
365     (funcall start frame nil)
366     (let ((*traced-entries* *traced-entries*))
367     (declare (special basic-definition argument-list))
368     (funcall cookie frame nil)
369     (let ((vals
370     (multiple-value-list
371     (apply basic-definition argument-list))))
372     (funcall (trace-end-breakpoint-fun info) frame nil vals nil)
373     (values-list vals))))))
374 chiles 1.1
375 ram 1.8
376 chiles 1.2 ;;; TRACE-1 -- Internal.
377 chiles 1.1 ;;;
378 ram 1.8 ;;; Trace one function according to the specified options. We copy the
379     ;;; trace info (it was a quoted constant), fill in the functions, and then
380     ;;; install the breakpoints or encapsulation.
381 chiles 1.1 ;;;
382 ram 1.8 ;;; If non-null, Definition is the new definition of a function that we are
383     ;;; automatically retracing; this
384     ;;;
385     (defun trace-1 (function-or-name info &optional definition)
386     (multiple-value-bind
387     (fun named kind)
388     (if definition
389     (values definition t
390     (nth-value 2 (trace-fdefinition definition)))
391     (trace-fdefinition function-or-name))
392     (when (gethash fun *traced-functions*)
393 ram 1.7 (warn "Function ~S already TRACE'd, retracing it." function-or-name)
394     (untrace-1 fun))
395    
396     (let* ((debug-fun (di:function-debug-function fun))
397 ram 1.8 (encapsulated
398     (if (eq (trace-info-encapsulated info) :default)
399     (ecase kind
400     (:compiled nil)
401     (:compiled-closure
402     (unless (functionp function-or-name)
403     (warn "Tracing shared code for ~S:~% ~S"
404     function-or-name fun))
405     nil)
406     ((:interpreted :interpreted-closure :funcallable-instance)
407     t))
408     (trace-info-encapsulated info)))
409     (loc (if encapsulated
410     :encapsulated
411     (di:debug-function-start-location debug-fun)))
412     (info (make-trace-info
413     :what function-or-name
414     :named named
415     :encapsulated encapsulated
416     :wherein (trace-info-wherein info)
417     :condition (coerce-form (trace-info-condition info) loc)
418     :break (coerce-form (trace-info-break info) loc)
419     :print (coerce-form-list (trace-info-print info) loc)
420     :break-after (coerce-form (trace-info-break-after info) nil)
421     :condition-after
422     (coerce-form (trace-info-condition-after info) nil)
423     :print-after
424     (coerce-form-list (trace-info-print-after info) nil))))
425 chiles 1.1
426 ram 1.8 (dolist (wherein (trace-info-wherein info))
427     (unless (or (stringp wherein)
428     (fboundp wherein))
429     (warn ":WHEREIN name is not a defined global function: ~S"
430     wherein)))
431    
432     (cond
433     (encapsulated
434     (unless named
435     (error "Can't use encapsulation to trace anonymous function ~S."
436     fun))
437     (ext:encapsulate function-or-name 'trace `(trace-call ',info)))
438     (t
439     (multiple-value-bind
440     (start-fun cookie-fun)
441     (trace-start-breakpoint-fun info)
442     (let ((start (di:make-breakpoint start-fun debug-fun
443     :kind :function-start))
444     (end (di:make-breakpoint
445     (trace-end-breakpoint-fun info)
446     debug-fun :kind :function-end
447     :function-end-cookie cookie-fun)))
448     (setf (trace-info-start-breakpoint info) start)
449     (setf (trace-info-end-breakpoint info) end)
450     ;;
451     ;; The next two forms must be in the order in which they appear,
452     ;; since the start breakpoint must run before the function-end
453     ;; breakpoint's start helper (which calls the cookie function.)
454     ;; One reason is that cookie function requires that the CONDITIONP
455     ;; shared closure variable be initialized.
456     (di:activate-breakpoint start)
457     (di:activate-breakpoint end)))))
458    
459     (setf (gethash fun *traced-functions*) info)))
460    
461     function-or-name)
462    
463    
464     ;;;; The TRACE macro:
465    
466     ;;; PARSE-TRACE-OPTIONS -- Internal
467 chiles 1.1 ;;;
468 ram 1.8 ;;; Parse leading trace options off of Specs, modifying Info accordingly.
469     ;;; The remaining portion of the list is returned when we encounter a plausible
470     ;;; function name.
471 chiles 1.1 ;;;
472 ram 1.8 (defun parse-trace-options (specs info)
473     (let ((current specs))
474     (loop
475     (when (endp current) (return))
476     (let ((option (first current))
477     (value (cons (second current) nil)))
478     (case option
479     (:condition (setf (trace-info-condition info) value))
480     (:condition-after
481     (setf (trace-info-condition info) (cons nil nil))
482     (setf (trace-info-condition-after info) value))
483     (:condition-all
484     (setf (trace-info-condition info) value)
485     (setf (trace-info-condition-after info) value))
486     (:wherein
487     (setf (trace-info-wherein info)
488     (if (listp (car value)) (car value) value)))
489     (:encapsulate
490     (setf (trace-info-encapsulated info) (car value)))
491     (:break (setf (trace-info-break info) value))
492     (:break-after (setf (trace-info-break-after info) value))
493     (:break-all
494     (setf (trace-info-break info) value)
495     (setf (trace-info-break-after info) value))
496     (:print
497     (setf (trace-info-print info)
498     (append (trace-info-print info) (list value))))
499     (:print-after
500     (setf (trace-info-print-after info)
501     (append (trace-info-print-after info) (list value))))
502     (:print-all
503     (setf (trace-info-print info)
504     (append (trace-info-print info) (list value)))
505     (setf (trace-info-print-after info)
506     (append (trace-info-print-after info) (list value))))
507     (t (return)))
508     (pop current)
509     (unless current
510     (error "Missing argument to ~S TRACE option." option))
511     (pop current)))
512     current))
513 chiles 1.1
514 ram 1.8
515     ;;; EXPAND-TRACE -- Internal
516 chiles 1.1 ;;;
517 ram 1.8 ;;; Compute the expansion of TRACE in the non-trivial case (arguments
518     ;;; specified.) If there are no :FUNCTION specs, then don't use a LET. This
519     ;;; allows TRACE to be used without the full interpreter.
520 chiles 1.1 ;;;
521 ram 1.8 (defun expand-trace (specs)
522     (collect ((binds)
523     (forms))
524     (let* ((global-options (make-trace-info))
525     (current (parse-trace-options specs global-options)))
526     (loop
527     (when (endp current) (return))
528     (let ((name (pop current))
529     (options (copy-trace-info global-options)))
530     (cond
531     ((eq name :function)
532     (let ((temp (gensym)))
533     (binds `(,temp ,(pop current)))
534     (forms `(trace-1 ,temp ',options))))
535     ((and (keywordp name)
536     (not (or (fboundp name) (macro-function name))))
537     (error "Unknown TRACE option: ~S" name))
538     (t
539     (forms `(trace-1 ',name ',options))))
540     (setq current (parse-trace-options current options)))))
541 chiles 1.1
542 ram 1.8 (if (binds)
543     `(let ,(binds) (list ,@(forms)))
544     `(list ,@(forms)))))
545 chiles 1.1
546 ram 1.8
547     ;;; %LIST-TRACED-FUNCTIONS -- Internal
548 chiles 1.2 ;;;
549 ram 1.8 (defun %list-traced-functions ()
550     (loop for x being each hash-value in *traced-functions*
551     collect (trace-info-what x)))
552    
553    
554     ;;; TRACE -- Public.
555 chiles 1.2 ;;;
556 ram 1.8 (defmacro trace (&rest specs)
557     "TRACE {Option Global-Value}* {Name {Option Value}*}*
558     TRACE is a debugging tool that prints information when specified functions
559     are called. In its simplest form:
560     (trace Name-1 Name-2 ...)
561 chiles 1.1
562 ram 1.8 TRACE causes a printout on *TRACE-OUTPUT* each time that one of the named
563     functions is entered or returns (the Names are not evaluated.) The output
564     is indented according to the number of pending traced calls, and this trace
565     depth is printed at the beginning of each line of output.
566 chiles 1.2
567 ram 1.8 Options allow modification of the default behavior. Each option is a pair
568     of an option keyword and a value form. Options may be interspersed with
569     function names. Options only affect tracing of the function whose name they
570     appear immediately after. Global options are specified before the first
571     name, and affect all functions traced by a given use of TRACE.
572    
573     The following options are defined:
574    
575     :CONDITION Form
576     :CONDITION-AFTER Form
577     :CONDITION-ALL Form
578     If :CONDITION is specified, then TRACE does nothing unless Form
579     evaluates to true at the time of the call. :CONDITION-AFTER is
580     similar, but suppresses the initial printout, and is tested when the
581     function returns. :CONDITION-ALL tries both before and after.
582    
583     :WHEREIN Names
584     If specified, Names is a function name or list of names. TRACE does
585     nothing unless a call to one of those functions encloses the call to
586     this function (i.e. it would appear in a backtrace.) Anonymous
587     functions have string names like \"DEFUN FOO\".
588    
589     :BREAK Form
590     :BREAK-AFTER Form
591     :BREAK-ALL Form
592     If specified, and Form evaluates to true, then the debugger is invoked
593     at the start of the function, at the end of the function, or both,
594     according to the respective option.
595    
596     :PRINT Form
597     :PRINT-AFTER Form
598     :PRINT-ALL Form
599     In addition to the usual prinout, he result of evaluating Form is
600     printed at the start of the function, at the end of the function, or
601     both, according to the respective option. Multiple print options cause
602     multiple values to be printed.
603    
604     :FUNCTION Function-Form
605     This is a not really an option, but rather another way of specifying
606     what function to trace. The Function-Form is evaluated immediately,
607     and the resulting function is traced.
608    
609     :ENCAPSULATE {:DEFAULT | T | NIL}
610     If T, the tracing is done via encapsulation (redefining the function
611     name) rather than by modifying the function. :DEFAULT is the default,
612     and means to use encapsulation for interpreted functions and funcallable
613     instances, breakpoints otherwise. When encapsulation is used, forms are
614     *not* evaluated in the function's lexical environment, but DEBUG:ARG can
615     still be used.
616    
617     :CONDITION, :BREAK and :PRINT forms are evaluated in the lexical environment
618     of the called function; DEBUG:VAR and DEBUG:ARG can be used. The -AFTER and
619     -ALL forms are evaluated in the null environment."
620     (if specs
621     (expand-trace specs)
622     '(%list-traced-functions)))
623    
624 chiles 1.1
625 ram 1.8 ;;;; Untracing:
626 chiles 1.1
627 ram 1.8 ;;; UNTRACE-1 -- Internal
628     ;;;
629     ;;; Untrace one function.
630     ;;;
631     (defun untrace-1 (function-or-name)
632     (let* ((fun (trace-fdefinition function-or-name))
633     (info (gethash fun *traced-functions*)))
634     (cond
635     ((not info) (warn "Function is not TRACE'd -- ~S." function-or-name))
636     ((trace-info-encapsulated info)
637     (ext:unencapsulate (trace-info-what info) 'trace))
638     (t
639     (di:delete-breakpoint (trace-info-start-breakpoint info))
640     (di:delete-breakpoint (trace-info-end-breakpoint info))))
641     (setf (trace-info-untraced info) t)
642     (remhash fun *traced-functions*)))
643    
644     ;;; UNTRACE-ALL -- Internal
645     ;;;
646     ;;; Untrace all traced functions.
647     ;;;
648     (defun untrace-all ()
649     (dolist (fun (%list-traced-functions))
650     (untrace-1 fun))
651     t)
652    
653 chiles 1.4 (defmacro untrace (&rest specs)
654     "Removes tracing from the specified functions. With no args, untraces all
655 chiles 1.1 functions."
656 ram 1.8 (if specs
657     (collect ((res))
658     (let ((current specs))
659     (loop
660     (unless current (return))
661     (let ((name (pop current)))
662     (res (if (eq name :function)
663     `(untrace-1 ,(pop current))
664     `(untrace-1 ',name)))))
665     `(progn ,@(res) t)))
666     '(untrace-all)))

  ViewVC Help
Powered by ViewVC 1.1.5