1 ;;;; This file is for testing the single-stepper.
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
16 ;; No stepper support on some platforms.
17 #-(or x86 x86-64 ppc sparc mips)
18 (sb-ext:quit :unix-status 104)
21 (declare (optimize debug))
27 (defvar *cerror-called* nil)
29 (define-condition cerror-break (error) ())
32 (declare (optimize debug))
35 (unless *cerror-called*
36 (cerror "a" 'cerror-break)
37 (setf *cerror-called* t))
40 (fib-break (- x 2)))))
43 (declare (optimize debug))
50 (declare (optimize debug))
53 (defun test-step-into ()
55 ;; The generic-< VOP on x86oids doesn't emit a full call
58 '(("(< X 2)" :unknown)
68 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown)
72 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown))
74 '(("(- X 1)" :unknown)
80 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown)
83 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown)))
84 (*stepper-hook* (lambda (condition)
87 (push (list (step-condition-form condition)
88 (step-condition-args condition))
90 (invoke-restart 'step-into))))))
92 (assert (equal expected (reverse results)))))
94 (defun test-step-next ()
98 '(("(< X 2)" :unknown)
105 ("(FIB (- X 2))" (0))
106 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown)
108 ("(FIB (- X 2))" (1))
109 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown))
111 '(("(- X 1)" :unknown)
116 ("(FIB (- X 2))" (0))
117 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown)
119 ("(FIB (- X 2))" (1))
120 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown)))
122 (*stepper-hook* (lambda (condition)
125 (push (list (step-condition-form condition)
126 (step-condition-args condition))
128 (if (< (incf count) 4)
129 (invoke-restart 'step-into)
130 (invoke-restart 'step-next)))))))
132 (assert (equal expected (reverse results)))))
134 (defun test-step-out ()
138 '(("(< X 2)" :unknown)
143 ("(FIB (- X 2))" (1))
145 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown))
147 '(("(- X 1)" :unknown)
152 ("(FIB (- X 2))" (1))
153 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown)))
155 (*stepper-hook* (lambda (condition)
158 (push (list (step-condition-form condition)
159 (step-condition-args condition))
161 (if (= (incf count) 4)
162 (invoke-restart 'step-out)
163 (invoke-restart 'step-into)))))))
165 (assert (equal expected (reverse results)))))
167 (defun test-step-start-from-break ()
171 '(("(- X 2)" :unknown)
172 ("(FIB-BREAK (- X 2))" (0))
174 ("(+ (FIB-BREAK (1- X)) (FIB-BREAK (- X 2)))" :unknown)
176 ("(FIB-BREAK (- X 2))" (1))
178 ("(+ (FIB-BREAK (1- X)) (FIB-BREAK (- X 2)))" :unknown))
180 '(("(- X 2)" :unknown)
181 ("(FIB-BREAK (- X 2))" (0))
182 ("(+ (FIB-BREAK (1- X)) (FIB-BREAK (- X 2)))" :unknown)
184 ("(FIB-BREAK (- X 2))" (1))
185 ("(+ (FIB-BREAK (1- X)) (FIB-BREAK (- X 2)))" :unknown)))
187 (*stepper-hook* (lambda (condition)
190 (push (list (step-condition-form condition)
191 (step-condition-args condition))
193 (invoke-restart 'step-into))))))
194 (setf *cerror-called* nil)
195 (handler-bind ((cerror-break
197 (sb-impl::enable-stepping)
198 (invoke-restart 'continue))))
200 (assert (equal expected (reverse results)))))
202 (defun test-step-frame ()
204 (*stepper-hook* (lambda (condition)
207 (let* ((frame (sb-di::find-stepped-frame))
208 (dfun (sb-di::frame-debug-fun frame))
209 (name (sb-di::debug-fun-name dfun)))
210 (assert (equal name 'fib))
212 (invoke-restart 'step-next)))))))
214 (assert (= count #-(or x86 x86-64) 6 #+(or x86 x86-64) 5))))
216 (defun test-step-backtrace ()
217 (let* ((*stepper-hook* (lambda (condition)
220 (let ((*debug-io* (make-broadcast-stream)))
224 (defun test-step-next/2 ()
226 (expected '(("(IN)" ())
232 (*stepper-hook* (lambda (condition)
235 (push (list (step-condition-form condition)
236 (step-condition-args condition))
238 (if (>= (incf count) 3)
239 (invoke-restart 'step-into)
240 (invoke-restart 'step-into)))))))
242 (assert (equal expected (reverse results)))))
244 (defun test-step-out/2 ()
246 (expected '(("(IN)" ())
250 (*stepper-hook* (lambda (condition)
253 (push (list (step-condition-form condition)
254 (step-condition-args condition))
256 (if (>= (incf count) 3)
257 (invoke-restart 'step-out)
258 (invoke-restart 'step-into)))))))
260 (assert (equal expected (reverse results)))))
262 (with-test (:name :step-into)
263 (handler-bind ((step-condition #'sb-impl::invoke-stepper))
266 (with-test (:name :step-next)
267 (handler-bind ((step-condition #'sb-impl::invoke-stepper))
270 (with-test (:name :step-out)
271 (handler-bind ((step-condition #'sb-impl::invoke-stepper))
274 (with-test (:name :step-start-from-break)
275 (handler-bind ((step-condition #'sb-impl::invoke-stepper))
276 (test-step-start-from-break)))
278 (with-test (:name :step-frame)
279 (handler-bind ((step-condition #'sb-impl::invoke-stepper))
282 (with-test (:name :step-backtrace)
283 (handler-bind ((step-condition #'sb-impl::invoke-stepper))
284 (test-step-backtrace)))
286 (with-test (:name :step-next/2)
287 (handler-bind ((step-condition #'sb-impl::invoke-stepper))
290 (with-test (:name :step-out/2)
291 (handler-bind ((step-condition #'sb-impl::invoke-stepper))