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

Contents of /src/code/ntrace.lisp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5