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 (expected '(("(< X 2)" :unknown
)
65 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)
69 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)))
70 (*stepper-hook
* (lambda (condition)
73 (push (list (step-condition-form condition
)
74 (step-condition-args condition
))
76 (invoke-restart 'step-into
))))))
78 (assert (equal expected
(reverse results
)))))
80 (defun test-step-next ()
82 (expected '(("(< X 2)" :unknown
)
90 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)
93 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)))
95 (*stepper-hook
* (lambda (condition)
98 (push (list (step-condition-form condition
)
99 (step-condition-args condition
))
101 (if (< (incf count
) 4)
102 (invoke-restart 'step-into
)
103 (invoke-restart 'step-next
)))))))
105 (assert (equal expected
(reverse results
)))))
107 (defun test-step-out ()
109 (expected '(("(< X 2)" :unknown
)
114 ("(FIB (- X 2))" (1))
116 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)))
118 (*stepper-hook
* (lambda (condition)
121 (push (list (step-condition-form condition
)
122 (step-condition-args condition
))
124 (if (= (incf count
) 4)
125 (invoke-restart 'step-out
)
126 (invoke-restart 'step-into
)))))))
128 (assert (equal expected
(reverse results
)))))
130 (defun test-step-start-from-break ()
132 (expected '(("(- X 2)" :unknown
)
133 ("(FIB-BREAK (- X 2))" (0))
135 ("(+ (FIB-BREAK (1- X)) (FIB-BREAK (- X 2)))" :unknown
)
137 ("(FIB-BREAK (- X 2))" (1))
139 ("(+ (FIB-BREAK (1- X)) (FIB-BREAK (- X 2)))" :unknown
)))
141 (*stepper-hook
* (lambda (condition)
144 (push (list (step-condition-form condition
)
145 (step-condition-args condition
))
147 (invoke-restart 'step-into
))))))
148 (setf *cerror-called
* nil
)
149 (handler-bind ((cerror-break
151 (sb-impl::enable-stepping
)
152 (invoke-restart 'continue
))))
154 (assert (equal expected
(reverse results
)))))
156 (defun test-step-frame ()
158 (*stepper-hook
* (lambda (condition)
161 (let* ((frame (sb-di::find-stepped-frame
))
162 (dfun (sb-di::frame-debug-fun frame
))
163 (name (sb-di::debug-fun-name dfun
)))
164 (assert (equal name
'fib
))
166 (invoke-restart 'step-next
)))))))
168 (assert (= count
6))))
170 (defun test-step-backtrace ()
171 (let* ((*stepper-hook
* (lambda (condition)
174 (let ((*debug-io
* (make-broadcast-stream)))
178 (defun test-step-next/2 ()
180 (expected '(("(IN)" ())
186 (*stepper-hook
* (lambda (condition)
189 (push (list (step-condition-form condition
)
190 (step-condition-args condition
))
192 (if (>= (incf count
) 3)
193 (invoke-restart 'step-into
)
194 (invoke-restart 'step-into
)))))))
196 (assert (equal expected
(reverse results
)))))
198 (defun test-step-out/2 ()
200 (expected '(("(IN)" ())
204 (*stepper-hook
* (lambda (condition)
207 (push (list (step-condition-form condition
)
208 (step-condition-args condition
))
210 (if (>= (incf count
) 3)
211 (invoke-restart 'step-out
)
212 (invoke-restart 'step-into
)))))))
214 (assert (equal expected
(reverse results
)))))
216 (with-test (:name
:step-into
)
217 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
220 (with-test (:name
:step-next
)
221 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
224 (with-test (:name
:step-out
)
225 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
228 (with-test (:name
:step-start-from-break
230 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
231 (test-step-start-from-break)))
233 (with-test (:name
:step-frame
)
234 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
237 (with-test (:name
:step-backtrace
)
238 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
239 (test-step-backtrace)))
241 (with-test (:name
:step-next
/2)
242 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
245 (with-test (:name
:step-out
/2)
246 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))