1 ;;;; (ice-9 debugging trace) -- breakpoint trace behaviour
3 ;;; Copyright (C) 2002 Free Software Foundation, Inc.
5 ;; This library is free software; you can redistribute it and/or
6 ;; modify it under the terms of the GNU Lesser General Public
7 ;; License as published by the Free Software Foundation; either
8 ;; version 2.1 of the License, or (at your option) any later version.
10 ;; This library is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;; Lesser General Public License for more details.
15 ;; You should have received a copy of the GNU Lesser General Public
16 ;; License along with this library; if not, write to the Free Software
17 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 (define-module (ice-9 debugging trace)
20 #:use-module (ice-9 debug)
21 #:use-module (ice-9 debugger)
22 #:use-module (ice-9 debugging ice-9-debugger-extensions)
23 #:use-module (ice-9 debugging steps)
24 #:use-module (ice-9 debugging traps)
31 trace/stack-real-depth
33 trace/source-file-name
43 (cond ((string>=? (version) "1.7")
44 (use-modules (ice-9 debugger utils))))
46 (define trace-format-string #f)
47 (define trace-arg-procs #f)
49 (define (set-trace-layout format-string . arg-procs)
50 (set! trace-format-string format-string)
51 (set! trace-arg-procs arg-procs))
53 (define (trace/pid trap-context)
56 (define (trace/stack-id trap-context)
57 (stack-id (tc:stack trap-context)))
59 (define (trace/stack-depth trap-context)
60 (tc:depth trap-context))
62 (define (trace/stack-real-depth trap-context)
63 (tc:real-depth trap-context))
65 (define (trace/stack trap-context)
67 (stack-id (tc:stack trap-context))
68 (tc:real-depth trap-context)
69 (- (tc:depth trap-context) (tc:real-depth trap-context))))
71 (define (trace/source-file-name trap-context)
72 (cond ((frame->source-position (tc:frame trap-context)) => car)
75 (define (trace/source-line trap-context)
76 (cond ((frame->source-position (tc:frame trap-context)) => cadr)
79 (define (trace/source-column trap-context)
80 (cond ((frame->source-position (tc:frame trap-context)) => caddr)
83 (define (trace/source trap-context)
84 (cond ((frame->source-position (tc:frame trap-context))
87 (format #f "~a:~a:~a" (car pos) (cadr pos) (caddr pos))))
90 (define (trace/type trap-context)
91 (case (tc:type trap-context)
92 ((#:application) "APP")
93 ((#:evaluation) "EVA")
98 (define (trace/real? trap-context)
99 (if (frame-real? (tc:frame trap-context)) " " "t"))
101 (define (trace/info trap-context)
102 (with-output-to-string
104 (if (memq (tc:type trap-context) '(#:application #:evaluation))
105 ((if (tc:expression trap-context)
106 write-frame-short/expression
107 write-frame-short/application) (tc:frame trap-context))
110 (write (tc:return-value trap-context)))))))
112 (set-trace-layout "|~3@a: ~a\n" trace/stack-real-depth trace/info)
116 ;;; Trace the current location, and install a hook to trace the return
117 ;;; value when we exit the current frame.
119 (define (trace-trap trap-context)
123 (map (lambda (arg-proc)
124 (arg-proc trap-context))
127 (set! (behaviour-ordering trace-trap) 50)
131 ;;; The port to which trace information is printed.
134 (let ((port (current-output-port)))
135 (make-procedure-with-setter
137 (lambda (new) (set! port new)))))
141 ;;; Trace return value on exit from the current frame.
143 (define (trace-at-exit trap-context)
144 (at-exit (tc:depth trap-context) trace-trap))
148 ;;; Trace absolutely everything until exit from the current frame.
150 (define (trace-until-exit trap-context)
151 (let ((step-trap (make <step-trap> #:behaviour trace-trap)))
152 (install-trap step-trap)
153 (at-exit (tc:depth trap-context)
154 (lambda (trap-context)
155 (uninstall-trap step-trap)))))
157 ;;; (ice-9 debugging trace) ends here.