3
;;; A simple debugger (needs much work)
5
(define (backtrace . args)
6
(if (> (length args) 1)
7
(error 'backtrace "too many arguments"))
9
(if (not (eq? (type (car args)) 'control-point))
10
(error 'backtrace "argument must be a control point")))
12
(apply backtrace-list args))
15
(set! trace (cdddr trace)))
19
(format #f "~s" (vector-ref frame 0)))
21
(- maxlen (string-length func))))
23
(if (negative? indent)
26
(set! indent maxlen)))
27
(do ((i indent (1- i)))
33
(display (vector-ref frame 1)))
42
(do ((f (environment->list env) (cdr f)))
44
(do ((b (car f) (cdr b)))
46
(format #t "~s\t~s~%" (caar b) (cdar b)))
55
'("q -- quit inspector"
56
"f -- print current frame"
57
"u -- go up one frame"
58
"d -- go down one frame"
59
"^ -- go to top frame"
60
"$ -- go to bottom frame"
61
"e -- eval expressions in environment"
62
"p -- pretty-print procedure"
63
"v -- show environment"
64
"<n> -- pretty-print n-th argument"
65
"o -- obarray information")))
67
(define (inspect-command-loop)
68
(let ((input) (done #f))
86
(set! frame (1- (length trace)))
90
(format #t "Already on top frame.~%")
91
(set! frame (1- frame))
94
(if (= frame (1- (length trace)))
95
(format #t "Already on bottom frame.~%")
96
(set! frame (1+ frame))
99
(show (vector-ref (list-ref trace frame) 2)))
101
(format #t "Type ^D to return to Inspector.~%")
105
(if (not (eof-object? input))
108
(vector-ref (list-ref trace frame) 2)))
113
(pp (vector-ref (list-ref trace frame) 0))
116
(let ((l (map length (oblist))))
118
(for-each (lambda (x) (set! n (+ x n))) l)
119
(format #t "~s symbols " n)
120
(format #t "(maximum bucket: ~s).~%" (apply max l)))))
124
(let ((args (vector-ref (list-ref trace frame) 1)))
125
(if (or (< input 1) (> input (length args)))
126
(format #t "No such argument.~%")
127
(pp (list-ref args (1- input)))
132
(format #t "Invalid command. Type ? for help.~%")))))
134
(inspect-command-loop))))
136
(define (print-frame)
137
(format #t "~%Frame ~s of ~s:~%~%" (1+ frame) (length trace))
138
(let* ((f (list-ref trace frame)) (args (vector-ref f 1)))
139
(format #t "Procedure: ~s~%" (vector-ref f 0))
140
(format #t "Environment: ~s~%" (vector-ref f 2))
142
(format #t "No arguments.~%")
146
(do ((i 1 (1+ i)) (args args (cdr args))) ((null? args))
147
(format #t "Argument ~s: ~s~%" i (car args))))))
153
(set! trace (backtrace-list))
154
(set! trace (cddr trace))
155
(do ((t trace (cdr t)) (f 1 (1+ f))) ((null? t))
156
(if (not (null? (vector-ref (car t) 1)))
157
(let ((last (last-pair (vector-ref (car t) 1))))
158
(if (not (null? (cdr last)))
161
"[inspector: fixing improper arglist in frame ~s]~%" f)
162
(set-cdr! last (cons (cdr last) '())))))))
163
(format #t "Inspector (type ? for help):~%")
165
(if (call-with-current-continuation
166
(lambda (control-point)
167
(push-frame control-point)
168
(inspect-command-loop)
175
(let ((next-frame (car rep-frames)))