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 #+interpreter
(sb-ext:exit
:code
104)
17 ;; No stepper support on some platforms.
18 #-
(or x86 x86-64 ppc sparc mips arm arm64
)
19 (sb-ext:exit
:code
104)
21 ;; These tests should either with code in dynamic space
22 ;; or immobile space, but they only accidentally worked
23 ;; because the default is dynamic space.
24 ;; Make sure they work in the non-default.
25 ;; The issue was that when we elide the move to register
26 ;; of the jump address, there's no register for the stepper
27 ;; to mess with on return from the breakpoint.
28 #+immobile-code
(setq sb-c
::*compile-to-memory-space
* :immobile
)
31 (declare (optimize debug
))
37 (defvar *cerror-called
* nil
)
39 (define-condition cerror-break
(error) ())
42 (declare (optimize debug
))
45 (unless *cerror-called
*
46 (cerror "a" 'cerror-break
)
47 (setf *cerror-called
* t
))
50 (fib-break (- x
2)))))
53 (declare (optimize debug
))
60 (declare (optimize debug
))
63 (defun test-step-into ()
65 ;; The generic-< VOP on x86oids doesn't emit a full call
79 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)
83 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
))
92 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)
95 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)))
96 (*stepper-hook
* (lambda (condition)
99 (push (list (step-condition-form condition
)
100 (step-condition-args condition
))
102 (invoke-restart 'step-into
))))))
104 (assert (equal expected
(reverse results
)))))
106 (defun test-step-next ()
118 ("(FIB (- X 2))" (0))
119 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)
121 ("(FIB (- X 2))" (1))
122 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
))
130 ("(FIB (- X 2))" (0))
131 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)
133 ("(FIB (- X 2))" (1))
134 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)))
136 (*stepper-hook
* (lambda (condition)
139 (push (list (step-condition-form condition
)
140 (step-condition-args condition
))
145 (invoke-restart 'step-into
)
146 (invoke-restart 'step-next
)))))))
148 (assert (equal expected
(reverse results
)))))
150 (defun test-step-out ()
160 ("(FIB (- X 2))" (1))
162 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
))
170 ("(FIB (- X 2))" (1))
171 ("(+ (FIB (1- X)) (FIB (- X 2)))" :unknown
)))
173 (*stepper-hook
* (lambda (condition)
176 (push (list (step-condition-form condition
)
177 (step-condition-args condition
))
179 (if (= (incf count
) 5)
180 (invoke-restart 'step-out
)
181 (invoke-restart 'step-into
)))))))
183 (assert (equal expected
(reverse results
)))))
185 (defun test-step-start-from-break ()
189 '(("(- X 2)" :unknown
)
190 ("(FIB-BREAK (- X 2))" (0))
192 ("(+ (FIB-BREAK (1- X)) (FIB-BREAK (- X 2)))" :unknown
)
194 ("(FIB-BREAK (- X 2))" (1))
196 ("(+ (FIB-BREAK (1- X)) (FIB-BREAK (- X 2)))" :unknown
))
198 '(("(- X 2)" :unknown
)
199 ("(FIB-BREAK (- X 2))" (0))
200 ("(+ (FIB-BREAK (1- X)) (FIB-BREAK (- X 2)))" :unknown
)
202 ("(FIB-BREAK (- X 2))" (1))
203 ("(+ (FIB-BREAK (1- X)) (FIB-BREAK (- X 2)))" :unknown
)))
204 (*stepper-hook
* (lambda (condition)
207 (push (list (step-condition-form condition
)
208 (step-condition-args condition
))
210 (invoke-restart 'step-into
))))))
211 (setf *cerror-called
* nil
)
212 (handler-bind ((cerror-break
215 (sb-impl::enable-stepping
)
216 (invoke-restart 'continue
))))
218 (assert (equal expected
(reverse results
)))))
220 (defun test-step-frame ()
221 (declare (optimize (debug 0)))
223 (*stepper-hook
* (lambda (condition)
226 (let* ((frame (sb-di::find-stepped-frame
))
227 (dfun (sb-di::frame-debug-fun frame
))
228 (name (sb-di::debug-fun-name dfun
)))
229 (assert (equal name
'fib
))
231 (invoke-restart 'step-next
)))))))
233 (assert (= count
#-
(or x86 x86-64
) 6 #+(or x86 x86-64
) 5))))
235 (defun test-step-backtrace ()
236 (let* ((*stepper-hook
* (lambda (condition)
239 (let ((*debug-io
* (make-broadcast-stream)))
240 (print-backtrace)))))))
243 (defun test-step-next/2 ()
245 (expected '(("(OUT)" ())
251 (*stepper-hook
* (lambda (condition)
254 (push (list (step-condition-form condition
)
255 (step-condition-args condition
))
257 (invoke-restart 'step-into
))))))
259 (assert (equal expected
(reverse results
)))))
261 (defun test-step-out/2 ()
263 (expected '(("(OUT)" ())
268 (*stepper-hook
* (lambda (condition)
271 (push (list (step-condition-form condition
)
272 (step-condition-args condition
))
274 (if (>= (incf count
) 4)
275 (invoke-restart 'step-out
)
276 (invoke-restart 'step-into
)))))))
278 (assert (equal expected
(reverse results
)))))
280 (with-test (:name
:step-into
)
281 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
284 (with-test (:name
:step-next
)
285 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
288 (with-test (:name
:step-out
)
289 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
292 (with-test (:name
:step-start-from-break
)
293 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
294 (test-step-start-from-break)))
296 (with-test (:name
:step-frame
)
297 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
300 (with-test (:name
:step-backtrace
)
301 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
302 (test-step-backtrace)))
304 (with-test (:name
:step-next
/2)
305 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))
308 (with-test (:name
:step-out
/2)
309 (handler-bind ((step-condition #'sb-impl
::invoke-stepper
))