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 (in-package "SB!DEBUG")
14 ;;;; variables and constants
16 ;;; things to consider when tweaking these values:
17 ;;; * We're afraid to just default them to NIL and NIL, in case the
18 ;;; user inadvertently causes a hairy data structure to be printed
19 ;;; when he inadvertently enters the debugger.
20 ;;; * We don't want to truncate output too much. These days anyone
21 ;;; can easily run their Lisp in a windowing system or under Emacs,
22 ;;; so it's not the end of the world even if the worst case is a
23 ;;; few thousand lines of output.
24 ;;; * As condition :REPORT methods are converted to use the pretty
25 ;;; printer, they acquire *PRINT-LEVEL* constraints, so e.g. under
26 ;;; sbcl-0.7.1.28's old value of *DEBUG-PRINT-LEVEL*=3, an
27 ;;; ARG-COUNT-ERROR printed as
28 ;;; error while parsing arguments to DESTRUCTURING-BIND:
29 ;;; invalid number of elements in
31 ;;; to satisfy lambda list
33 ;;; exactly 2 expected, but 5 found
34 (defvar *debug-print-variable-alist* nil
36 "an association list describing new bindings for special variables
37 to be used within the debugger. Eg.
39 ((*PRINT-LENGTH* . 10) (*PRINT-LEVEL* . 6) (*PRINT-PRETTY* . NIL))
41 The variables in the CAR positions are bound to the values in the CDR
42 during the execution of some debug commands. When evaluating arbitrary
43 expressions in the debugger, the normal values of the printer control
44 variables are in effect.
46 Initially empty, *DEBUG-PRINT-VARIABLE-ALIST* is typically used to
47 provide bindings for printer control variables.")
49 (defvar *debug-readtable*
50 ;; KLUDGE: This can't be initialized in a cold toplevel form,
51 ;; because the *STANDARD-READTABLE* isn't initialized until after
52 ;; cold toplevel forms have run. So instead we initialize it
53 ;; immediately after *STANDARD-READTABLE*. -- WHN 20000205
56 "*READTABLE* for the debugger")
58 (defvar *in-the-debugger* nil
60 "This is T while in the debugger.")
62 ;;; nestedness inside debugger command loops
63 (defvar *debug-command-level* 0)
65 ;;; If this is bound before the debugger is invoked, it is used as the
66 ;;; stack top by the debugger.
67 (defvar *stack-top-hint* nil)
69 (defvar *stack-top* nil)
70 (defvar *real-stack-top* nil)
72 (defvar *current-frame* nil)
74 ;;; Beginner-oriented help messages are important because you end up
75 ;;; in the debugger whenever something bad happens, or if you try to
76 ;;; get out of the system with Ctrl-C or (EXIT) or EXIT or whatever.
77 ;;; But after memorizing them the wasted screen space gets annoying..
78 (defvar *debug-beginner-help-p* t
79 "Should the debugger display beginner-oriented help messages?")
81 (defun debug-prompt (stream)
82 (sb!thread::get-foreground)
85 (sb!di:frame-number *current-frame*)
86 (> *debug-command-level* 1)
87 *debug-command-level*))
89 (defparameter *debug-help-string*
90 "The debug prompt is square brackets, with number(s) indicating the current
91 control stack level and, if you've entered the debugger recursively, how
92 deeply recursed you are.
93 Any command -- including the name of a restart -- may be uniquely abbreviated.
94 The debugger rebinds various special variables for controlling i/o, sometimes
95 to defaults (much like WITH-STANDARD-IO-SYNTAX does) and sometimes to
96 its own special values, based on SB-EXT:*DEBUG-PRINT-VARIABLE-ALIST*.
97 Debug commands do not affect *, //, and similar variables, but evaluation in
98 the debug loop does affect these variables.
99 SB-DEBUG:*FLUSH-DEBUG-ERRORS* controls whether errors at the debug prompt
100 drop you deeper into the debugger. The default NIL allows recursive entry
103 Getting in and out of the debugger:
104 TOPLEVEL, TOP exits debugger and returns to top level REPL
105 RESTART invokes restart numbered as shown (prompt if not given).
106 ERROR prints the error condition and restart cases.
108 The number of any restart, or its name, or a unique abbreviation for its
109 name, is a valid command, and is the same as using RESTART to invoke
113 UP up frame DOWN down frame
114 BOTTOM bottom frame FRAME n frame n (n=0 for top frame)
117 BACKTRACE [n] shows n frames going down the stack.
118 LIST-LOCALS, L lists locals in current frame.
119 PRINT, P displays function call for current frame.
120 SOURCE [n] displays frame's source form with n levels of enclosing forms.
123 STEP Selects the CONTINUE restart if one exists and starts
124 single-stepping. Single stepping affects only code compiled with
125 under high DEBUG optimization quality. See User Manual for details.
127 Function and macro commands:
129 Return the n'th argument in the current frame.
130 (SB-DEBUG:VAR string-or-symbol [id])
131 Returns the value of the specified variable in the current frame.
135 Return the values resulting from evaluation of expr from the
136 current frame, if this frame was compiled with a sufficiently high
137 DEBUG optimization quality.
140 Discard all pending input on *STANDARD-INPUT*. (This can be
141 useful when the debugger was invoked to handle an error in
142 deeply nested input syntax, and now the reader is confused.)")
145 ;;; If LOC is an unknown location, then try to find the block start
146 ;;; location. Used by source printing to some information instead of
147 ;;; none for the user.
148 (defun maybe-block-start-location (loc)
149 (if (sb!di:code-location-unknown-p loc)
150 (let* ((block (sb!di:code-location-debug-block loc))
151 (start (sb!di:do-debug-block-locations (loc block)
153 (cond ((and (not (sb!di:debug-block-elsewhere-p block))
155 (format *debug-io* "~%unknown location: using block start~%")
163 (defun backtrace (&optional (count most-positive-fixnum) (stream *debug-io*))
165 "Show a listing of the call stack going down from the current frame.
166 In the debugger, the current frame is indicated by the prompt. COUNT
167 is how many frames to show."
169 (do ((frame (if *in-the-debugger* *current-frame* (sb!di:top-frame))
170 (sb!di:frame-down frame))
171 (count count (1- count)))
172 ((or (null frame) (zerop count)))
173 (print-frame-call frame stream :number t))
177 (defun backtrace-as-list (&optional (count most-positive-fixnum))
178 #!+sb-doc "Return a list representing the current BACKTRACE."
179 (do ((reversed-result nil)
180 (frame (if *in-the-debugger* *current-frame* (sb!di:top-frame))
181 (sb!di:frame-down frame))
182 (count count (1- count)))
183 ((or (null frame) (zerop count))
184 (nreverse reversed-result))
185 (push (frame-call-as-list frame) reversed-result)))
187 (defun frame-call-as-list (frame)
188 (multiple-value-bind (name args) (frame-call frame)
193 (eval-when (:compile-toplevel :execute)
195 ;;; This is a convenient way to express what to do for each type of
196 ;;; lambda-list element.
197 (sb!xc:defmacro lambda-list-element-dispatch (element
208 (ecase (car ,element)
209 (:optional ,@optional)
211 (:keyword ,@keyword)))
213 (aver (eq ,element :deleted))
216 (sb!xc:defmacro lambda-var-dispatch (variable location deleted valid other)
217 (let ((var (gensym)))
218 `(let ((,var ,variable))
219 (cond ((eq ,var :deleted) ,deleted)
220 ((eq (sb!di:debug-var-validity ,var ,location) :valid)
226 ;;; This is used in constructing arg lists for debugger printing when
227 ;;; the arg list is unavailable, some arg is unavailable or unused, etc.
228 (defstruct (unprintable-object
229 (:constructor make-unprintable-object (string))
230 (:print-object (lambda (x s)
231 (print-unreadable-object (x s)
232 (write-string (unprintable-object-string x)
237 ;;; Extract the function argument values for a debug frame.
238 (defun frame-args-as-list (frame)
239 (let ((debug-fun (sb!di:frame-debug-fun frame))
240 (loc (sb!di:frame-code-location frame))
241 (reversed-result nil))
244 (dolist (ele (sb!di:debug-fun-lambda-list debug-fun))
245 (lambda-list-element-dispatch ele
246 :required ((push (frame-call-arg ele loc frame) reversed-result))
247 :optional ((push (frame-call-arg (second ele) loc frame)
249 :keyword ((push (second ele) reversed-result)
250 (push (frame-call-arg (third ele) loc frame)
252 :deleted ((push (frame-call-arg ele loc frame) reversed-result))
253 :rest ((lambda-var-dispatch (second ele) loc
256 (setf reversed-result
257 (append (reverse (sb!di:debug-var-value
261 (push (make-unprintable-object
262 "unavailable &REST argument")
264 ;; As long as we do an ordinary return (as opposed to SIGNALing
265 ;; a CONDITION) from the DOLIST above:
266 (nreverse reversed-result))
267 (sb!di:lambda-list-unavailable
269 (make-unprintable-object "unavailable lambda list")))))
270 (legal-fun-name-p '(lambda ()))
271 (defvar *show-entry-point-details* nil)
273 (defun clean-xep (name args)
274 (values (second name)
276 (let ((count (first args))
277 (real-args (rest args)))
280 (min count (length real-args)))
284 (defun clean-&more-processor (name args)
285 (values (second name)
287 (let* ((more (last args 2))
288 (context (first more))
289 (count (second more)))
294 (sb!c:%more-arg-values context 0 count))
296 (make-unprintable-object "more unavailable arguments")))))
299 (defun frame-call (frame)
300 (labels ((clean-name-and-args (name args)
301 (if (and (consp name) (not *show-entry-point-details*))
302 ;; FIXME: do we need to deal with
303 ;; HAIRY-FUNCTION-ENTRY here? I can't make it or
304 ;; &AUX-BINDINGS appear in backtraces, so they are
305 ;; left alone for now. --NS 2005-02-28
307 ((sb!c::xep sb!c::tl-xep)
308 (clean-xep name args))
309 ((sb!c::&more-processor)
310 (clean-&more-processor name args))
311 ((sb!c::hairy-arg-processor
312 sb!c::varargs-entry sb!c::&optional-processor)
313 (clean-name-and-args (second name) args))
316 (values name args))))
317 (let ((debug-fun (sb!di:frame-debug-fun frame)))
318 (multiple-value-bind (name args)
319 (clean-name-and-args (sb!di:debug-fun-name debug-fun)
320 (frame-args-as-list frame))
322 (when *show-entry-point-details*
323 (sb!di:debug-fun-kind debug-fun)))))))
325 (defun ensure-printable-object (object)
327 (with-open-stream (out (make-broadcast-stream))
331 (declare (ignore cond))
332 (make-unprintable-object "error printing object"))))
334 (defun frame-call-arg (var location frame)
335 (lambda-var-dispatch var location
336 (make-unprintable-object "unused argument")
337 (sb!di:debug-var-value var frame)
338 (make-unprintable-object "unavailable argument")))
340 ;;; Prints a representation of the function call causing FRAME to
341 ;;; exist. VERBOSITY indicates the level of information to output;
342 ;;; zero indicates just printing the DEBUG-FUN's name, and one
343 ;;; indicates displaying call-like, one-liner format with argument
345 (defun print-frame-call (frame stream &key (verbosity 1) (number nil))
347 (format stream "~&~S: " (sb!di:frame-number frame)))
348 (if (zerop verbosity)
349 (let ((*print-readably* nil))
350 (prin1 frame stream))
351 (multiple-value-bind (name args kind) (frame-call frame)
352 (pprint-logical-block (stream nil :prefix "(" :suffix ")")
353 ;; Since we go to some trouble to make nice informative function
354 ;; names like (PRINT-OBJECT :AROUND (CLOWN T)), let's make sure
355 ;; that they aren't truncated by *PRINT-LENGTH* and *PRINT-LEVEL*.
356 ;; For the function arguments, we can just print normally.
357 (let ((*print-length* nil)
359 (prin1 (ensure-printable-object name) stream))
360 ;; If we hit a &REST arg, then print as many of the values as
361 ;; possible, punting the loop over lambda-list variables since any
362 ;; other arguments will be in the &REST arg's list of values.
363 (let ((args (ensure-printable-object args)))
365 (format stream "~{ ~_~S~}" args)
366 (format stream " ~S" args))))
368 (format stream "[~S]" kind))))
369 (when (>= verbosity 2)
370 (let ((loc (sb!di:frame-code-location frame)))
373 ;; FIXME: Is this call really necessary here? If it is,
374 ;; then the reason for it should be unobscured.
375 (sb!di:code-location-debug-block loc)
376 (format stream "~%source: ")
377 (prin1 (code-location-source-form loc 0) stream))
378 (sb!di:debug-condition (ignore)
381 (format stream "~&error finding source: ~A" c))))))
385 (defvar *debugger-hook* nil
387 "This is either NIL or a function of two arguments, a condition and the value
388 of *DEBUGGER-HOOK*. This function can either handle the condition or return
389 which causes the standard debugger to execute. The system passes the value
390 of this variable to the function because it binds *DEBUGGER-HOOK* to NIL
391 around the invocation.")
393 (defvar *invoke-debugger-hook* nil
395 "This is either NIL or a designator for a function of two arguments,
396 to be run when the debugger is about to be entered. The function is
397 run with *INVOKE-DEBUGGER-HOOK* bound to NIL to minimize recursive
398 errors, and receives as arguments the condition that triggered
399 debugger entry and the previous value of *INVOKE-DEBUGGER-HOOK*
401 This mechanism is an SBCL extension similar to the standard *DEBUGGER-HOOK*.
402 In contrast to *DEBUGGER-HOOK*, it is observed by INVOKE-DEBUGGER even when
405 ;;; These are bound on each invocation of INVOKE-DEBUGGER.
406 (defvar *debug-restarts*)
407 (defvar *debug-condition*)
408 (defvar *nested-debug-condition*)
410 ;;; Oh, what a tangled web we weave when we preserve backwards
411 ;;; compatibility with 1968-style use of global variables to control
412 ;;; per-stream i/o properties; there's really no way to get this
413 ;;; quite right, but we do what we can.
414 (defun funcall-with-debug-io-syntax (fun &rest rest)
415 (declare (type function fun))
416 ;; Try to force the other special variables into a useful state.
417 (let (;; Protect from WITH-STANDARD-IO-SYNTAX some variables where
418 ;; any default we might use is less useful than just reusing
419 ;; the global values.
420 (original-package *package*)
421 (original-print-pretty *print-pretty*))
422 (with-standard-io-syntax
424 (let (;; We want the printer and reader to be in a useful
425 ;; state, regardless of where the debugger was invoked
426 ;; in the program. WITH-STANDARD-IO-SYNTAX and
427 ;; WITH-SANE-IO-SYNTAX do much of what we want, but
428 ;; * It doesn't affect our internal special variables
429 ;; like *CURRENT-LEVEL-IN-PRINT*.
430 ;; * It isn't customizable.
431 ;; * It sets *PACKAGE* to COMMON-LISP-USER, which is not
432 ;; helpful behavior for a debugger.
433 ;; * There's no particularly good debugger default for
434 ;; *PRINT-PRETTY*, since T is usually what you want
435 ;; -- except absolutely not what you want when you're
436 ;; debugging failures in PRINT-OBJECT logic.
437 ;; We try to address all these issues with explicit
439 (sb!kernel:*current-level-in-print* 0)
440 (*package* original-package)
441 (*print-pretty* original-print-pretty)
442 ;; Clear the circularity machinery to try to to reduce the
443 ;; pain from sharing the circularity table across all
444 ;; streams; if these are not rebound here, then setting
445 ;; *PRINT-CIRCLE* within the debugger when debugging in a
446 ;; state where something circular was being printed (e.g.,
447 ;; because the debugger was entered on an error in a
448 ;; PRINT-OBJECT method) makes a hopeless mess. Binding them
449 ;; here does seem somewhat ugly because it makes it more
450 ;; difficult to debug the printing-of-circularities code
451 ;; itself; however, as far as I (WHN, 2004-05-29) can see,
452 ;; that's almost entirely academic as long as there's one
453 ;; shared *C-H-T* for all streams (i.e., it's already
454 ;; unreasonably difficult to debug print-circle machinery
455 ;; given the buggy crosstalk between the debugger streams
456 ;; and the stream you're trying to watch), and any fix for
457 ;; that buggy arrangement will likely let this hack go away
459 (sb!impl::*circularity-hash-table* . nil)
460 (sb!impl::*circularity-counter* . nil)
461 (*readtable* *debug-readtable*))
463 ;; (Why NREVERSE? PROGV makes the later entries have
464 ;; precedence over the earlier entries.
465 ;; *DEBUG-PRINT-VARIABLE-ALIST* is called an alist, so it's
466 ;; expected that its earlier entries have precedence. And
467 ;; the earlier-has-precedence behavior is mostly more
468 ;; convenient, so that programmers can use PUSH or LIST* to
469 ;; customize *DEBUG-PRINT-VARIABLE-ALIST*.)
470 (nreverse (mapcar #'car *debug-print-variable-alist*))
471 (nreverse (mapcar #'cdr *debug-print-variable-alist*))
472 (apply fun rest)))))))
474 (defun invoke-debugger (condition)
476 "Enter the debugger."
478 ;; call *INVOKE-DEBUGGER-HOOK* first, so that *DEBUGGER-HOOK* is not
479 ;; called when the debugger is disabled
480 (let ((old-hook *invoke-debugger-hook*))
482 (let ((*invoke-debugger-hook* nil))
483 (funcall old-hook condition old-hook))))
484 (let ((old-hook *debugger-hook*))
486 (let ((*debugger-hook* nil))
487 (funcall old-hook condition old-hook))))
489 ;; We definitely want *PACKAGE* to be of valid type.
491 ;; Elsewhere in the system, we use the SANE-PACKAGE function for
492 ;; this, but here causing an exception just as we're trying to handle
493 ;; an exception would be confusing, so instead we use a special hack.
494 (unless (and (packagep *package*)
495 (package-name *package*))
496 (setf *package* (find-package :cl-user))
497 (format *error-output*
498 "The value of ~S was not an undeleted PACKAGE. It has been
500 '*package* *package*))
502 ;; Before we start our own output, finish any pending output.
503 ;; Otherwise, if the user tried to track the progress of his program
504 ;; using PRINT statements, he'd tend to lose the last line of output
505 ;; or so, which'd be confusing.
506 (flush-standard-output-streams)
508 (funcall-with-debug-io-syntax #'%invoke-debugger condition))
510 (defun %print-debugger-invocation-reason (condition stream)
511 (format stream "~2&")
512 ;; Note: Ordinarily it's only a matter of taste whether to use
513 ;; FORMAT "~<...~:>" or to use PPRINT-LOGICAL-BLOCK directly, but
514 ;; until bug 403 is fixed, PPRINT-LOGICAL-BLOCK (STREAM NIL) is
515 ;; definitely preferred, because the FORMAT alternative was acting odd.
516 (pprint-logical-block (stream nil)
518 "debugger invoked on a ~S~@[ in thread ~A~]: ~2I~_~A"
520 #!+sb-thread sb!thread:*current-thread*
525 (defun %invoke-debugger (condition)
527 (let ((*debug-condition* condition)
528 (*debug-restarts* (compute-restarts condition))
529 (*nested-debug-condition* nil))
531 ;; (The initial output here goes to *ERROR-OUTPUT*, because the
532 ;; initial output is not interactive, just an error message, and
533 ;; when people redirect *ERROR-OUTPUT*, they could reasonably
534 ;; expect to see error messages logged there, regardless of what
535 ;; the debugger does afterwards.)
536 (%print-debugger-invocation-reason condition *error-output*)
538 (setf *nested-debug-condition* condition)
539 (let ((ndc-type (type-of *nested-debug-condition*)))
540 (format *error-output*
541 "~&~@<(A ~S was caught when trying to print ~S when ~
542 entering the debugger. Printing was aborted and the ~
543 ~S was stored in ~S.)~@:>~%"
547 '*nested-debug-condition*))
548 (when (typep *nested-debug-condition* 'cell-error)
549 ;; what we really want to know when it's e.g. an UNBOUND-VARIABLE:
550 (format *error-output*
551 "~&(CELL-ERROR-NAME ~S) = ~S~%"
552 '*nested-debug-condition*
553 (cell-error-name *nested-debug-condition*)))))
555 (let ((background-p (sb!thread::debugger-wait-until-foreground-thread
558 ;; After the initial error/condition/whatever announcement to
559 ;; *ERROR-OUTPUT*, we become interactive, and should talk on
560 ;; *DEBUG-IO* from now on. (KLUDGE: This is a normative
561 ;; statement, not a description of reality.:-| There's a lot of
562 ;; older debugger code which was written to do i/o on whatever
563 ;; stream was in fashion at the time, and not all of it has
564 ;; been converted to behave this way. -- WHN 2000-11-16)
567 (let (;; We used to bind *STANDARD-OUTPUT* to *DEBUG-IO*
568 ;; here as well, but that is probably bogus since it
569 ;; removes the users ability to do output to a redirected
570 ;; *S-O*. Now we just rebind it so that users can temporarily
571 ;; frob it. FIXME: This and other "what gets bound when"
572 ;; behaviour should be documented in the manual.
573 (*standard-output* *standard-output*)
574 ;; This seems reasonable: e.g. if the user has redirected
575 ;; *ERROR-OUTPUT* to some log file, it's probably wrong
576 ;; to send errors which occur in interactive debugging to
577 ;; that file, and right to send them to *DEBUG-IO*.
578 (*error-output* *debug-io*))
579 (unless (typep condition 'step-condition)
580 (when *debug-beginner-help-p*
582 "~%~@<Type HELP for debugger help, or ~
583 (SB-EXT:QUIT) to exit from SBCL.~:@>~2%"))
584 (show-restarts *debug-restarts* *debug-io*))
587 (sb!thread::release-foreground))))))
589 ;;; this function is for use in *INVOKE-DEBUGGER-HOOK* when ordinary
590 ;;; ANSI behavior has been suppressed by the "--disable-debugger"
591 ;;; command-line option
592 (defun debugger-disabled-hook (condition me)
593 (declare (ignore me))
594 ;; There is no one there to interact with, so report the
595 ;; condition and terminate the program.
596 (flet ((failure-quit (&key recklessly-p)
597 (/show0 "in FAILURE-QUIT (in --disable-debugger debugger hook)")
598 (quit :unix-status 1 :recklessly-p recklessly-p)))
599 ;; This HANDLER-CASE is here mostly to stop output immediately
600 ;; (and fall through to QUIT) when there's an I/O error. Thus,
601 ;; when we're run under a shell script or something, we can die
602 ;; cleanly when the script dies (and our pipes are cut), instead
603 ;; of falling into ldb or something messy like that. Similarly, we
604 ;; can terminate cleanly even if BACKTRACE dies because of bugs in
605 ;; user PRINT-OBJECT methods.
608 (format *error-output*
609 "~&~@<unhandled ~S~@[ in thread ~S~]: ~2I~_~A~:>~2%"
611 #!+sb-thread sb!thread:*current-thread*
614 ;; Flush *ERROR-OUTPUT* even before the BACKTRACE, so that
615 ;; even if we hit an error within BACKTRACE (e.g. a bug in
616 ;; the debugger's own frame-walking code, or a bug in a user
617 ;; PRINT-OBJECT method) we'll at least have the CONDITION
618 ;; printed out before we die.
619 (finish-output *error-output*)
620 ;; (Where to truncate the BACKTRACE is of course arbitrary, but
621 ;; it seems as though we should at least truncate it somewhere.)
622 (sb!debug:backtrace 128 *error-output*)
625 "~%unhandled condition in --disable-debugger mode, quitting~%")
626 (finish-output *error-output*)
629 ;; We IGNORE-ERRORS here because even %PRIMITIVE PRINT can
630 ;; fail when our output streams are blown away, as e.g. when
631 ;; we're running under a Unix shell script and it dies somehow
632 ;; (e.g. because of a SIGINT). In that case, we might as well
633 ;; just give it up for a bad job, and stop trying to notify
634 ;; the user of anything.
636 ;; Actually, the only way I've run across to exercise the
637 ;; problem is to have more than one layer of shell script.
638 ;; I have a shell script which does
639 ;; time nice -10 sh make.sh "$1" 2>&1 | tee make.tmp
640 ;; and the problem occurs when I interrupt this with Ctrl-C
641 ;; under Linux 2.2.14-5.0 and GNU bash, version 1.14.7(1).
642 ;; I haven't figured out whether it's bash, time, tee, Linux, or
643 ;; what that is responsible, but that it's possible at all
644 ;; means that we should IGNORE-ERRORS here. -- WHN 2001-04-24
647 "Argh! error within --disable-debugger error handling"))
648 (failure-quit :recklessly-p t)))))
650 (defvar *old-debugger-hook* nil)
652 ;;; halt-on-failures and prompt-on-failures modes, suitable for
653 ;;; noninteractive and interactive use respectively
654 (defun disable-debugger ()
655 ;; *DEBUG-IO* used to be set here to *ERROR-OUTPUT* which is sort
656 ;; of unexpected but mostly harmless, but then ENABLE-DEBUGGER had
657 ;; to set it to a suitable value again and be very careful,
658 ;; especially if the user has also set it. -- MG 2005-07-15
659 (unless (eq *invoke-debugger-hook* 'debugger-disabled-hook)
660 (setf *old-debugger-hook* *invoke-debugger-hook*
661 *invoke-debugger-hook* 'debugger-disabled-hook))
662 ;; This is not inside the UNLESS to ensure that LDB is disabled
663 ;; regardless of what the old value of *INVOKE-DEBUGGER-HOOK* was.
664 ;; This might matter for example when restoring a core.
665 (sb!alien:alien-funcall (sb!alien:extern-alien "disable_lossage_handler"
666 (function sb!alien:void))))
668 (defun enable-debugger ()
669 (when (eql *invoke-debugger-hook* 'debugger-disabled-hook)
670 (setf *invoke-debugger-hook* *old-debugger-hook*
671 *old-debugger-hook* nil))
672 (sb!alien:alien-funcall (sb!alien:extern-alien "enable_lossage_handler"
673 (function sb!alien:void))))
675 (defun show-restarts (restarts s)
676 (cond ((null restarts)
678 "~&(no restarts: If you didn't do this on purpose, ~
679 please report it as a bug.)~%"))
681 (format s "~&restarts (invokable by number or by ~
682 possibly-abbreviated name):~%")
686 (dolist (restart restarts)
687 (let ((name (restart-name restart)))
689 (let ((len (length (princ-to-string name))))
690 (when (> len max-name-len)
691 (setf max-name-len len))))))
692 (unless (zerop max-name-len)
693 (incf max-name-len 3))
694 (dolist (restart restarts)
695 (let ((name (restart-name restart)))
696 ;; FIXME: maybe it would be better to display later names
697 ;; in parens instead of brakets, not just omit them fully.
698 ;; Call BREAK, call BREAK in the debugger, and tell me
699 ;; it's not confusing looking. --NS 20050310
700 (cond ((member name names-used)
701 (format s "~& ~2D: ~V@T~A~%" count max-name-len restart))
703 (format s "~& ~2D: [~VA] ~A~%"
704 count (- max-name-len 3) name restart)
705 (push name names-used))))
708 (defvar *debug-loop-fun* #'debug-loop-fun
709 "a function taking no parameters that starts the low-level debug loop")
711 ;;; This calls DEBUG-LOOP, performing some simple initializations
712 ;;; before doing so. INVOKE-DEBUGGER calls this to actually get into
713 ;;; the debugger. SB!KERNEL::ERROR-ERROR calls this in emergencies
714 ;;; to get into a debug prompt as quickly as possible with as little
715 ;;; risk as possible for stepping on whatever is causing recursive
717 (defun internal-debug ()
718 (let ((*in-the-debugger* t)
719 (*read-suppress* nil))
720 (unless (typep *debug-condition* 'step-condition)
721 (clear-input *debug-io*))
722 (funcall *debug-loop-fun*)))
726 ;;; Note: This defaulted to T in CMU CL. The changed default in SBCL
727 ;;; was motivated by desire to play nicely with ILISP.
728 (defvar *flush-debug-errors* nil
730 "When set, avoid calling INVOKE-DEBUGGER recursively when errors occur while
731 executing in the debugger.")
733 (defun debug-read (stream)
734 (declare (type stream stream))
735 (let* ((eof-marker (cons nil nil))
736 (form (read stream nil eof-marker)))
737 (if (eq form eof-marker)
741 (defun debug-loop-fun ()
742 (let* ((*debug-command-level* (1+ *debug-command-level*))
743 (*real-stack-top* (sb!di:top-frame))
744 (*stack-top* (or *stack-top-hint* *real-stack-top*))
745 (*stack-top-hint* nil)
746 (*current-frame* *stack-top*))
747 (handler-bind ((sb!di:debug-condition
749 (princ condition *debug-io*)
750 (/show0 "handling d-c by THROWing DEBUG-LOOP-CATCHER")
751 (throw 'debug-loop-catcher nil))))
753 (print-frame-call *current-frame* *debug-io* :verbosity 2)
755 (catch 'debug-loop-catcher
756 (handler-bind ((error (lambda (condition)
757 (when *flush-debug-errors*
758 (clear-input *debug-io*)
759 (princ condition *debug-io*)
761 "~&error flushed (because ~
763 '*flush-debug-errors*)
764 (/show0 "throwing DEBUG-LOOP-CATCHER")
765 (throw 'debug-loop-catcher nil)))))
766 ;; We have to bind LEVEL for the restart function created by
767 ;; WITH-SIMPLE-RESTART.
768 (let ((level *debug-command-level*)
769 (restart-commands (make-restart-commands)))
770 (flush-standard-output-streams)
771 (debug-prompt *debug-io*)
772 (force-output *debug-io*)
773 (let* ((exp (debug-read *debug-io*))
774 (cmd-fun (debug-command-p exp restart-commands)))
775 (with-simple-restart (abort
776 "~@<Reduce debugger level (to debug level ~W).~@:>"
779 (debug-eval-print exp))
782 "~&Your command, ~S, is ambiguous:~%"
784 (dolist (ele cmd-fun)
785 (format *debug-io* " ~A~%" ele)))
787 (funcall cmd-fun))))))))))))
789 (defun debug-eval-print (expr)
790 (/noshow "entering DEBUG-EVAL-PRINT" expr)
791 (let ((values (multiple-value-list (interactive-eval expr))))
792 (/noshow "done with EVAL in DEBUG-EVAL-PRINT")
793 (dolist (value values)
794 (fresh-line *debug-io*)
795 (prin1 value *debug-io*)))
796 (force-output *debug-io*))
798 ;;;; debug loop functions
800 ;;; These commands are functions, not really commands, so that users
801 ;;; can get their hands on the values returned.
803 (eval-when (:execute :compile-toplevel)
805 (sb!xc:defmacro define-var-operation (ref-or-set &optional value-var)
806 `(let* ((temp (etypecase name
807 (symbol (sb!di:debug-fun-symbol-vars
808 (sb!di:frame-debug-fun *current-frame*)
810 (simple-string (sb!di:ambiguous-debug-vars
811 (sb!di:frame-debug-fun *current-frame*)
813 (location (sb!di:frame-code-location *current-frame*))
814 ;; Let's only deal with valid variables.
815 (vars (remove-if-not (lambda (v)
816 (eq (sb!di:debug-var-validity v location)
819 (declare (list vars))
821 (error "No known valid variables match ~S." name))
825 '(sb!di:debug-var-value (car vars) *current-frame*))
827 `(setf (sb!di:debug-var-value (car vars) *current-frame*)
830 ;; Since we have more than one, first see whether we have
831 ;; any variables that exactly match the specification.
832 (let* ((name (etypecase name
833 (symbol (symbol-name name))
834 (simple-string name)))
835 ;; FIXME: REMOVE-IF-NOT is deprecated, use STRING/=
837 (exact (remove-if-not (lambda (v)
838 (string= (sb!di:debug-var-symbol-name v)
841 (vars (or exact vars)))
842 (declare (simple-string name)
845 ;; Check now for only having one variable.
849 '(sb!di:debug-var-value (car vars) *current-frame*))
851 `(setf (sb!di:debug-var-value (car vars) *current-frame*)
853 ;; If there weren't any exact matches, flame about
854 ;; ambiguity unless all the variables have the same
859 (string= (sb!di:debug-var-symbol-name v)
860 (sb!di:debug-var-symbol-name (car vars))))
862 (error "specification ambiguous:~%~{ ~A~%~}"
863 (mapcar #'sb!di:debug-var-symbol-name
866 :key #'sb!di:debug-var-symbol-name))))
867 ;; All names are the same, so see whether the user
868 ;; ID'ed one of them.
870 (let ((v (find id vars :key #'sb!di:debug-var-id)))
873 "invalid variable ID, ~W: should have been one of ~S"
875 (mapcar #'sb!di:debug-var-id vars)))
878 '(sb!di:debug-var-value v *current-frame*))
880 `(setf (sb!di:debug-var-value v *current-frame*)
883 (error "Specify variable ID to disambiguate ~S. Use one of ~S."
885 (mapcar #'sb!di:debug-var-id vars)))))))))
889 ;;; FIXME: This doesn't work. It would be real nice we could make it
890 ;;; work! Alas, it doesn't seem to work in CMU CL X86 either..
891 (defun var (name &optional (id 0 id-supplied))
893 "Return a variable's value if possible. NAME is a simple-string or symbol.
894 If it is a simple-string, it is an initial substring of the variable's name.
895 If name is a symbol, it has the same name and package as the variable whose
896 value this function returns. If the symbol is uninterned, then the variable
897 has the same name as the symbol, but it has no package.
899 If name is the initial substring of variables with different names, then
900 this return no values after displaying the ambiguous names. If name
901 determines multiple variables with the same name, then you must use the
902 optional id argument to specify which one you want. If you left id
903 unspecified, then this returns no values after displaying the distinguishing
906 The result of this function is limited to the availability of variable
907 information. This is SETF'able."
908 (define-var-operation :ref))
909 (defun (setf var) (value name &optional (id 0 id-supplied))
910 (define-var-operation :set value))
912 ;;; This returns the COUNT'th arg as the user sees it from args, the
913 ;;; result of SB!DI:DEBUG-FUN-LAMBDA-LIST. If this returns a
914 ;;; potential DEBUG-VAR from the lambda-list, then the second value is
915 ;;; T. If this returns a keyword symbol or a value from a rest arg,
916 ;;; then the second value is NIL.
918 ;;; FIXME: There's probably some way to merge the code here with
919 ;;; FRAME-ARGS-AS-LIST. (A fair amount of logic is already shared
920 ;;; through LAMBDA-LIST-ELEMENT-DISPATCH, but I suspect more could be.)
921 (declaim (ftype (function (index list)) nth-arg))
922 (defun nth-arg (count args)
924 (dolist (ele args (error "The argument specification ~S is out of range."
926 (lambda-list-element-dispatch ele
927 :required ((if (zerop n) (return (values ele t))))
928 :optional ((if (zerop n) (return (values (second ele) t))))
929 :keyword ((cond ((zerop n)
930 (return (values (second ele) nil)))
932 (return (values (third ele) t)))))
933 :deleted ((if (zerop n) (return (values ele t))))
934 :rest ((let ((var (second ele)))
935 (lambda-var-dispatch var (sb!di:frame-code-location
937 (error "unused &REST argument before n'th argument")
939 (sb!di:debug-var-value var *current-frame*)
941 "The argument specification ~S is out of range."
944 (return-from nth-arg (values value nil))
946 (error "invalid &REST argument before n'th argument")))))
951 "Return the N'th argument's value if possible. Argument zero is the first
952 argument in a frame's default printed representation. Count keyword/value
953 pairs as separate arguments."
954 (multiple-value-bind (var lambda-var-p)
955 (nth-arg n (handler-case (sb!di:debug-fun-lambda-list
956 (sb!di:frame-debug-fun *current-frame*))
957 (sb!di:lambda-list-unavailable ()
958 (error "No argument values are available."))))
960 (lambda-var-dispatch var (sb!di:frame-code-location *current-frame*)
961 (error "Unused arguments have no values.")
962 (sb!di:debug-var-value var *current-frame*)
963 (error "invalid argument value"))
966 ;;;; machinery for definition of debug loop commands
968 (defvar *debug-commands* nil)
970 ;;; Interface to *DEBUG-COMMANDS*. No required arguments in args are
972 (defmacro !def-debug-command (name args &rest body)
973 (let ((fun-name (symbolicate name "-DEBUG-COMMAND")))
975 (setf *debug-commands*
976 (remove ,name *debug-commands* :key #'car :test #'string=))
977 (defun ,fun-name ,args
978 (unless *in-the-debugger*
979 (error "invoking debugger command while outside the debugger"))
981 (push (cons ,name #',fun-name) *debug-commands*)
984 (defun !def-debug-command-alias (new-name existing-name)
985 (let ((pair (assoc existing-name *debug-commands* :test #'string=)))
986 (unless pair (error "unknown debug command name: ~S" existing-name))
987 (push (cons new-name (cdr pair)) *debug-commands*))
990 ;;; This takes a symbol and uses its name to find a debugger command,
991 ;;; using initial substring matching. It returns the command function
992 ;;; if form identifies only one command, but if form is ambiguous,
993 ;;; this returns a list of the command names. If there are no matches,
994 ;;; this returns nil. Whenever the loop that looks for a set of
995 ;;; possibilities encounters an exact name match, we return that
996 ;;; command function immediately.
997 (defun debug-command-p (form &optional other-commands)
998 (if (or (symbolp form) (integerp form))
1002 (format nil "~W" form)))
1005 (declare (simple-string name)
1009 ;; Find matching commands, punting if exact match.
1010 (flet ((match-command (ele)
1011 (let* ((str (car ele))
1012 (str-len (length str)))
1013 (declare (simple-string str)
1015 (cond ((< str-len len))
1017 (when (string= name str :end1 len :end2 len)
1018 (return-from debug-command-p (cdr ele))))
1019 ((string= name str :end1 len :end2 len)
1021 (mapc #'match-command *debug-commands*)
1022 (mapc #'match-command other-commands))
1024 ;; Return the right value.
1025 (cond ((not res) nil)
1028 (t ; Just return the names.
1029 (do ((cmds res (cdr cmds)))
1031 (setf (car cmds) (caar cmds))))))))
1033 ;;; Return a list of debug commands (in the same format as
1034 ;;; *DEBUG-COMMANDS*) that invoke each active restart.
1036 ;;; Two commands are made for each restart: one for the number, and
1037 ;;; one for the restart name (unless it's been shadowed by an earlier
1038 ;;; restart of the same name, or it is NIL).
1039 (defun make-restart-commands (&optional (restarts *debug-restarts*))
1041 (num 0)) ; better be the same as show-restarts!
1042 (dolist (restart restarts)
1043 (let ((name (string (restart-name restart))))
1046 (/show0 "in restart-command closure, about to i-r-i")
1047 (invoke-restart-interactively restart))))
1048 (push (cons (prin1-to-string num) restart-fun) commands)
1049 (unless (or (null (restart-name restart))
1050 (find name commands :key #'car :test #'string=))
1051 (push (cons name restart-fun) commands))))
1055 ;;;; frame-changing commands
1057 (!def-debug-command "UP" ()
1058 (let ((next (sb!di:frame-up *current-frame*)))
1060 (setf *current-frame* next)
1061 (print-frame-call next *debug-io*))
1063 (format *debug-io* "~&Top of stack.")))))
1065 (!def-debug-command "DOWN" ()
1066 (let ((next (sb!di:frame-down *current-frame*)))
1068 (setf *current-frame* next)
1069 (print-frame-call next *debug-io*))
1071 (format *debug-io* "~&Bottom of stack.")))))
1073 (!def-debug-command-alias "D" "DOWN")
1075 (!def-debug-command "BOTTOM" ()
1076 (do ((prev *current-frame* lead)
1077 (lead (sb!di:frame-down *current-frame*) (sb!di:frame-down lead)))
1079 (setf *current-frame* prev)
1080 (print-frame-call prev *debug-io*))))
1082 (!def-debug-command-alias "B" "BOTTOM")
1084 (!def-debug-command "FRAME" (&optional
1085 (n (read-prompting-maybe "frame number: ")))
1086 (setf *current-frame*
1087 (multiple-value-bind (next-frame-fun limit-string)
1088 (if (< n (sb!di:frame-number *current-frame*))
1089 (values #'sb!di:frame-up "top")
1090 (values #'sb!di:frame-down "bottom"))
1091 (do ((frame *current-frame*))
1092 ((= n (sb!di:frame-number frame))
1094 (let ((next-frame (funcall next-frame-fun frame)))
1096 (setf frame next-frame))
1099 "The ~A of the stack was encountered.~%"
1101 (return frame)))))))
1102 (print-frame-call *current-frame* *debug-io*))
1104 (!def-debug-command-alias "F" "FRAME")
1106 ;;;; commands for entering and leaving the debugger
1108 (!def-debug-command "TOPLEVEL" ()
1109 (throw 'toplevel-catcher nil))
1112 (!def-debug-command-alias "TOP" "TOPLEVEL")
1114 (!def-debug-command "RESTART" ()
1115 (/show0 "doing RESTART debug-command")
1116 (let ((num (read-if-available :prompt)))
1117 (when (eq num :prompt)
1118 (show-restarts *debug-restarts* *debug-io*)
1119 (write-string "restart: " *debug-io*)
1120 (force-output *debug-io*)
1121 (setf num (read *debug-io*)))
1122 (let ((restart (typecase num
1124 (nth num *debug-restarts*))
1126 (find num *debug-restarts* :key #'restart-name
1127 :test (lambda (sym1 sym2)
1128 (string= (symbol-name sym1)
1129 (symbol-name sym2)))))
1131 (format *debug-io* "~S is invalid as a restart name.~%"
1133 (return-from restart-debug-command nil)))))
1134 (/show0 "got RESTART")
1136 (invoke-restart-interactively restart)
1137 (princ "There is no such restart." *debug-io*)))))
1139 ;;;; information commands
1141 (!def-debug-command "HELP" ()
1142 ;; CMU CL had a little toy pager here, but "if you aren't running
1143 ;; ILISP (or a smart windowing system, or something) you deserve to
1144 ;; lose", so we've dropped it in SBCL. However, in case some
1145 ;; desperate holdout is running this on a dumb terminal somewhere,
1146 ;; we tell him where to find the message stored as a string.
1148 "~&~A~2%(The HELP string is stored in ~S.)~%"
1150 '*debug-help-string*))
1152 (!def-debug-command-alias "?" "HELP")
1154 (!def-debug-command "ERROR" ()
1155 (format *debug-io* "~A~%" *debug-condition*)
1156 (show-restarts *debug-restarts* *debug-io*))
1158 (!def-debug-command "BACKTRACE" ()
1159 (backtrace (read-if-available most-positive-fixnum)))
1161 (!def-debug-command "PRINT" ()
1162 (print-frame-call *current-frame* *debug-io*))
1164 (!def-debug-command-alias "P" "PRINT")
1166 (!def-debug-command "LIST-LOCALS" ()
1167 (let ((d-fun (sb!di:frame-debug-fun *current-frame*)))
1168 (if (sb!di:debug-var-info-available d-fun)
1169 (let ((*standard-output* *debug-io*)
1170 (location (sb!di:frame-code-location *current-frame*))
1171 (prefix (read-if-available nil))
1174 (dolist (v (sb!di:ambiguous-debug-vars
1176 (if prefix (string prefix) "")))
1178 (when (eq (sb!di:debug-var-validity v location) :valid)
1179 (setf any-valid-p t)
1180 (format *debug-io* "~S~:[#~W~;~*~] = ~S~%"
1181 (sb!di:debug-var-symbol v)
1182 (zerop (sb!di:debug-var-id v))
1183 (sb!di:debug-var-id v)
1184 (sb!di:debug-var-value v *current-frame*))))
1189 "There are no local variables ~@[starting with ~A ~]~
1194 "All variables ~@[starting with ~A ~]currently ~
1195 have invalid values."
1197 (write-line "There is no variable information available."
1200 (!def-debug-command-alias "L" "LIST-LOCALS")
1202 (!def-debug-command "SOURCE" ()
1203 (print (code-location-source-form (sb!di:frame-code-location *current-frame*)
1204 (read-if-available 0))
1207 ;;;; source location printing
1209 ;;; We cache a stream to the last valid file debug source so that we
1210 ;;; won't have to repeatedly open the file.
1212 ;;; KLUDGE: This sounds like a bug, not a feature. Opening files is fast
1213 ;;; in the 1990s, so the benefit is negligible, less important than the
1214 ;;; potential of extra confusion if someone changes the source during
1215 ;;; a debug session and the change doesn't show up. And removing this
1216 ;;; would simplify the system, which I like. -- WHN 19990903
1217 (defvar *cached-debug-source* nil)
1218 (declaim (type (or sb!di:debug-source null) *cached-debug-source*))
1219 (defvar *cached-source-stream* nil)
1220 (declaim (type (or stream null) *cached-source-stream*))
1222 ;;; To suppress the read-time evaluation #. macro during source read,
1223 ;;; *READTABLE* is modified. *READTABLE* is cached to avoid
1224 ;;; copying it each time, and invalidated when the
1225 ;;; *CACHED-DEBUG-SOURCE* has changed.
1226 (defvar *cached-readtable* nil)
1227 (declaim (type (or readtable null) *cached-readtable*))
1229 ;;; Stuff to clean up before saving a core
1230 (defun debug-deinit ()
1231 (setf *cached-debug-source* nil
1232 *cached-source-stream* nil
1233 *cached-readtable* nil))
1235 ;;; We also cache the last toplevel form that we printed a source for
1236 ;;; so that we don't have to do repeated reads and calls to
1237 ;;; FORM-NUMBER-TRANSLATIONS.
1238 (defvar *cached-toplevel-form-offset* nil)
1239 (declaim (type (or index null) *cached-toplevel-form-offset*))
1240 (defvar *cached-toplevel-form*)
1241 (defvar *cached-form-number-translations*)
1243 ;;; Given a code location, return the associated form-number
1244 ;;; translations and the actual top level form. We check our cache ---
1245 ;;; if there is a miss, we dispatch on the kind of the debug source.
1246 (defun get-toplevel-form (location)
1247 (let ((d-source (sb!di:code-location-debug-source location)))
1248 (if (and (eq d-source *cached-debug-source*)
1249 (eql (sb!di:code-location-toplevel-form-offset location)
1250 *cached-toplevel-form-offset*))
1251 (values *cached-form-number-translations* *cached-toplevel-form*)
1252 (let* ((offset (sb!di:code-location-toplevel-form-offset location))
1254 (ecase (sb!di:debug-source-from d-source)
1255 (:file (get-file-toplevel-form location))
1256 (:lisp (svref (sb!di:debug-source-name d-source) offset)))))
1257 (setq *cached-toplevel-form-offset* offset)
1258 (values (setq *cached-form-number-translations*
1259 (sb!di:form-number-translations res offset))
1260 (setq *cached-toplevel-form* res))))))
1262 ;;; Locate the source file (if it still exists) and grab the top level
1263 ;;; form. If the file is modified, we use the top level form offset
1264 ;;; instead of the recorded character offset.
1265 (defun get-file-toplevel-form (location)
1266 (let* ((d-source (sb!di:code-location-debug-source location))
1267 (tlf-offset (sb!di:code-location-toplevel-form-offset location))
1268 (local-tlf-offset (- tlf-offset
1269 (sb!di:debug-source-root-number d-source)))
1271 (aref (or (sb!di:debug-source-start-positions d-source)
1272 (error "no start positions map"))
1274 (name (sb!di:debug-source-name d-source)))
1275 (unless (eq d-source *cached-debug-source*)
1276 (unless (and *cached-source-stream*
1277 (equal (pathname *cached-source-stream*)
1279 (setq *cached-readtable* nil)
1280 (when *cached-source-stream* (close *cached-source-stream*))
1281 (setq *cached-source-stream* (open name :if-does-not-exist nil))
1282 (unless *cached-source-stream*
1283 (error "The source file no longer exists:~% ~A" (namestring name)))
1284 (format *debug-io* "~%; file: ~A~%" (namestring name)))
1286 (setq *cached-debug-source*
1287 (if (= (sb!di:debug-source-created d-source)
1288 (file-write-date name))
1292 ((eq *cached-debug-source* d-source)
1293 (file-position *cached-source-stream* char-offset))
1296 "~%; File has been modified since compilation:~%; ~A~@
1297 ; Using form offset instead of character position.~%"
1299 (file-position *cached-source-stream* 0)
1300 (let ((*read-suppress* t))
1301 (dotimes (i local-tlf-offset)
1302 (read *cached-source-stream*)))))
1303 (unless *cached-readtable*
1304 (setq *cached-readtable* (copy-readtable))
1305 (set-dispatch-macro-character
1307 (lambda (stream sub-char &rest rest)
1308 (declare (ignore rest sub-char))
1309 (let ((token (read stream t nil t)))
1310 (format nil "#.~S" token)))
1311 *cached-readtable*))
1312 (let ((*readtable* *cached-readtable*))
1313 (read *cached-source-stream*))))
1315 (defun code-location-source-form (location context)
1316 (let* ((location (maybe-block-start-location location))
1317 (form-num (sb!di:code-location-form-number location)))
1318 (multiple-value-bind (translations form) (get-toplevel-form location)
1319 (unless (< form-num (length translations))
1320 (error "The source path no longer exists."))
1321 (sb!di:source-path-context form
1322 (svref translations form-num)
1325 ;;; step to the next steppable form
1326 (!def-debug-command "STEP" ()
1327 (let ((restart (find-restart 'continue *debug-condition*)))
1331 (invoke-restart restart))
1333 (format *debug-io* "~&Non-continuable error, cannot step.~%")))))
1335 ;;; miscellaneous commands
1337 (!def-debug-command "DESCRIBE" ()
1338 (let* ((curloc (sb!di:frame-code-location *current-frame*))
1339 (debug-fun (sb!di:code-location-debug-fun curloc))
1340 (function (sb!di:debug-fun-fun debug-fun)))
1343 (format *debug-io* "can't figure out the function for this frame"))))
1345 (!def-debug-command "SLURP" ()
1346 (loop while (read-char-no-hang *standard-input*)))
1348 (!def-debug-command "RETURN" (&optional
1349 (return (read-prompting-maybe
1351 (let ((tag (find-if (lambda (x)
1352 (and (typep (car x) 'symbol)
1353 (not (symbol-package (car x)))
1354 (string= (car x) "SB-DEBUG-CATCH-TAG")))
1355 (sb!di::frame-catches *current-frame*))))
1358 (funcall (sb!di:preprocess-for-eval
1360 (sb!di:frame-code-location *current-frame*))
1363 "~@<can't find a tag for this frame ~
1364 ~2I~_(hint: try increasing the DEBUG optimization quality ~
1365 and recompiling)~:@>"))))
1367 ;;;; debug loop command utilities
1369 (defun read-prompting-maybe (prompt)
1370 (unless (sb!int:listen-skip-whitespace *debug-io*)
1371 (princ prompt *debug-io*)
1372 (force-output *debug-io*))
1375 (defun read-if-available (default)
1376 (if (sb!int:listen-skip-whitespace *debug-io*)