1 ;;;; single stepper for SBCL
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 ;;;; Single stepping works by having compiler insert STEP-CONDITION
13 ;;;; signalling forms into code compiled at high debug settings, and
14 ;;;; having a handler for them at the toplevel.
16 (in-package "SB-IMPL") ; in warm SBCL
18 (defun step-form (form args
)
20 (signal 'step-form-condition
24 :report
"Resume normal execution"
26 (setf *step-out
* nil
))
28 :report
"Resume stepping after returning from this function"
31 (error "Can't STEP-OUT: No STEP-IN on the call-stack"))
37 :report
"Step over call"
40 :report
"Step into call"
43 (defun step-values (form &rest values
)
44 (declare (dynamic-extent values
))
45 (signal 'step-values-condition
:form form
:result values
)
48 (defun step-finished ()
50 (signal 'step-finished-condition
)
53 (defgeneric single-step
(condition))
55 (defmethod single-step ((condition step-values-condition
))
56 (let ((values (step-condition-result condition
)))
57 (format *debug-io
* "; ~A => ~:[#<no value>~;~{~S~^, ~}~]~%"
58 (step-condition-form condition
)
61 (defmethod single-step ((condition step-form-condition
))
62 (let ((form (step-condition-form condition
))
63 (args (step-condition-args condition
)))
64 (let ((*print-circle
* t
)
66 (*print-readably
* nil
))
68 "; Evaluating call:~%~<; ~@; ~A~:>~%~
69 ; ~:[With arguments:~%~<; ~@;~{ ~S~^~%~}~:>~;With unknown arguments~]~%"
73 (finish-output *debug-io
*)
74 (let ((*stack-top-hint
* (sb-di::find-stepped-frame
)))
75 (invoke-debugger condition
))))
77 ;;; In the TTY debugger we're not interested in STEP returning
78 (defmethod single-step ((condition step-finished-condition
))
81 (defvar *stepper-hook
* 'single-step
82 #+sb-doc
"Customization hook for alternative single-steppers.
83 *STEPPER-HOOK* is bound to NIL prior to calling the bound function
84 with the STEP-CONDITION as argument.")
86 (defun invoke-stepper (condition)
87 (when (and (stepping-enabled-p)
89 (with-stepping-disabled
90 (let ((hook *stepper-hook
*)
92 (funcall hook condition
)))))
96 "The form is evaluated with single stepping enabled. Function calls
97 outside the lexical scope of the form can be stepped into only if the
98 functions in question have been compiled with sufficient DEBUG policy
99 to be at least partially steppable."
101 (declare (optimize debug
(sb-c:insert-step-conditions
0)))
102 ;; Allow stepping out of the STEP form.
103 (let ((*step-out
* :maybe
))
105 (with-stepping-enabled
106 (multiple-value-prog1
107 (locally (declare (optimize (sb-c:insert-step-conditions
3)))
109 (step-finished)))))))