2 @comment node-name, next, previous, up
6 This chapter documents the debugging facilities of SBCL, including
7 the debugger, single-stepper and @code{trace}, and the effect of
8 @code{(optimize debug)} declarations.
12 * Debugger Command Loop::
15 * Source Location Printing::
16 * Debugger Policy Control::
18 * Information Commands::
21 * Enabling and Disabling the Debugger::
25 @comment node-name, next, previous, up
26 @section Debugger Entry
30 * Debugger Invocation::
34 @comment node-name, next, previous, up
35 @subsection Debugger Banner
37 When you enter the debugger, it looks something like this:
40 debugger invoked on a TYPE-ERROR in thread 11184:
41 The value 3 is not of type LIST.
43 You can type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
45 restarts (invokable by number or by possibly-abbreviated name):
46 0: [ABORT ] Reduce debugger level (leaving debugger, returning to toplevel).
47 1: [TOPLEVEL] Restart at toplevel READ/EVAL/PRINT loop.
52 The first group of lines describe what the error was that put us in
53 the debugger. In this case @code{car} was called on @code{3}, causing
56 This is followed by the ``beginner help line'', which appears only if
57 @code{sb-ext:*debug-beginner-help-p*} is true (default).
59 Next comes a listing of the active restart names, along with their
60 descriptions -- the ways we can restart execution after this error. In
61 this case, both options return to top-level. Restarts can be selected
62 by entering the corresponding number or name.
64 The current frame appears right underneath the restarts, immediately
65 followed by the debugger prompt.
67 @node Debugger Invocation
68 @comment node-name, next, previous, up
69 @subsection Debugger Invocation
71 The debugger is invoked when:
76 @code{error} is called, and the condition it signals is not handled.
79 @code{break} is called, or @code{signal} is called with a condition
80 that matches the current @code{*break-on-signals*}.
83 the debugger is explicitly entered with the @code{invoke-debugger}
88 When the debugger is invoked by a condition, ANSI mandates that the
89 value of @code{*debugger-hook*}, if any, be called with two arguments:
90 the condition that caused the debugger to be invoked and the previous
91 value of @code{*debugger-hook*}. When this happens,
92 @code{*debugger-hook*} is bound to NIL to prevent recursive errors.
93 However, ANSI also mandates that @code{*debugger-hook*} not be invoked
94 when the debugger is to be entered by the @code{break} function. For
95 users who wish to provide an alternate debugger interface (and thus
96 catch @code{break} entries into the debugger), SBCL provides
97 @code{sb-ext:*invoke-debugger-hook*}, which is invoked during any
98 entry into the debugger.
100 @include var-sb-ext-star-invoke-debugger-hook-star.texinfo
102 @node Debugger Command Loop
103 @comment node-name, next, previous, up
104 @section Debugger Command Loop
106 The debugger is an interactive read-eval-print loop much like the
107 normal top level, but some symbols are interpreted as debugger
108 commands instead of being evaluated. A debugger command starts with
109 the symbol name of the command, possibly followed by some arguments on
110 the same line. Some commands prompt for additional input. Debugger
111 commands can be abbreviated by any unambiguous prefix: @command{help}
112 can be typed as @samp{h}, @samp{he}, etc.
114 The package is not significant in debugger commands; any symbol with
115 the name of a debugger command will work. If you want to show the
116 value of a variable that happens also to be the name of a debugger
117 command you can wrap the variable in a @code{progn} to hide it from
120 The debugger prompt is ``@code{@var{frame}]}'', where @var{frame} is
121 the number of the current frame. Frames are numbered starting from
122 zero at the top (most recent call), increasing down to the bottom.
123 The current frame is the frame that commands refer to.
125 It is possible to override the normal printing behaviour in the
126 debugger by using the @code{sb-ext:*debug-print-variable-alist*}.
128 @include var-sb-ext-star-debug-print-variable-alist-star.texinfo
131 @comment node-name, next, previous, up
132 @section Stack Frames
135 A @dfn{stack frame} is the run-time representation of a call to a
136 function; the frame stores the state that a function needs to remember
137 what it is doing. Frames have:
142 @dfn{variables} (@pxref{Variable Access}), which are the values being operated
146 @dfn{arguments} to the call (which are really just particularly
147 interesting variables).
150 a current source location (@pxref{Source Location Printing}), which is
151 the place in the program where the function was running when it
152 stopped to call another function, or because of an interrupt or error.
158 * How Arguments are Printed::
160 * Debug Tail Recursion::
161 * Unknown Locations and Interrupts::
165 @comment node-name, next, previous, up
166 @subsection Stack Motion
168 These commands move to a new stack frame and print the name of the
169 function and the values of its arguments in the style of a Lisp
172 @deffn {Debugger Command} @nopkg{up}
173 Move up to the next higher frame. More recent function calls are
174 considered to be higher on the stack.
177 @deffn {Debugger Command} @nopkg{down}
178 Move down to the next lower frame.
181 @deffn {Debugger Command} @nopkg{top}
182 Move to the highest frame, that is, the frame where the debugger was
186 @deffn {Debugger Command} @nopkg{bottom}
187 Move to the lowest frame.
190 @deffn {Debugger Command} @nopkg{frame} [@var{n}]
191 Move to the frame with the specified number. Prompts for the number if not
192 supplied. The frame with number 0 is the frame where the debugger
197 @node How Arguments are Printed
198 @comment node-name, next, previous, up
199 @subsection How Arguments are Printed
201 A frame is printed to look like a function call, but with the actual
202 argument values in the argument positions. So the frame for this call
209 would look like this:
215 All keyword and optional arguments are displayed with their actual
216 values; if the corresponding argument was not supplied, the value will
217 be the default. So this call:
223 would look like this:
232 (string-upcase "test case")
235 would look like this:
238 (STRING-UPCASE "test case" :START 0 :END NIL)
241 The arguments to a function call are displayed by accessing the
242 argument variables. Although those variables are initialized to the
243 actual argument values, they can be set inside the function; in this
244 case the new value will be displayed.
246 @code{&rest} arguments are handled somewhat differently. The value of
247 the rest argument variable is displayed as the spread-out arguments to
251 (format t "~A is a ~A." "This" 'test)
254 would look like this:
257 (FORMAT T "~A is a ~A." "This" 'TEST)
260 Rest arguments cause an exception to the normal display of keyword
261 arguments in functions that have both @code{&rest} and @code{&key}
262 arguments. In this case, the keyword argument variables are not
263 displayed at all; the rest arg is displayed instead. So for these
264 functions, only the keywords actually supplied will be shown, and the
265 values displayed will be the argument values, not values of the
266 (possibly modified) variables.
268 If the variable for an argument is never referenced by the function,
269 it will be deleted. The variable value is then unavailable, so the
270 debugger prints @samp{#<unused-arg>} instead of the value. Similarly,
271 if for any of a number of reasons the value of the variable is
272 unavailable or not known to be available (@pxref{Variable Access}),
273 then @samp{#<unavailable-arg>} will be printed instead of the argument
276 Note that inline expansion and open-coding affect what frames
277 are present in the debugger, see @ref{Debugger Policy Control}.
278 @comment FIXME: link here to section about open coding once it exists.
283 @comment node-name, next, previous, up
284 @subsection Function Names
286 If a function is defined by @code{defun} it will appear in backtrace
287 by that name. Functions defined by @code{labels} and @code{flet} will
288 appear as @code{(FLET <name>)} and @code{(LABELS <name>)} respectively.
289 Anonymous lambdas will appear as @code{(LAMDBA <lambda-list>)}.
292 * Entry Point Details::
295 @node Entry Point Details
296 @comment node-name, next, previous, up
297 @subsubsection Entry Point Details
298 @cindex External entry points
299 @cindex Entry points, external
300 @cindex Block compilation, debugger implications
301 @cindex External, stack frame kind
302 @cindex Optional, stack frame kind
303 @cindex Cleanup, stack frame kind
305 Sometimes the compiler introduces new functions that are used to
306 implement a user function, but are not directly specified in the
307 source. This is mostly done for argument type and count checking.
309 @c FIXME: the following bits talked about block-compilation, but
310 @c we don't currently support it...
314 @c functions, an additional @code{:EXTERNAL} frame
315 @c may appear before the frame representing the first call to the
316 @c recursive function
317 @c or entry to the compiled block.
319 @c consequence of the way the compiler works: there is
320 @c nothing odd with your program. You will also see @code{:CLEANUP}
321 @c frames during the execution of @code{unwind-protect} cleanup
324 With recursive functions, an additional @code{external} frame may
325 appear before the frame representing the first call to the recursive
326 function. This is a consequence of the way the compiler works: there
327 is nothing odd with your program. You may also see @code{cleanup}
328 frames during the execution of @code{unwind-protect} cleanup code, and
329 @code{optional} for variable argument entry points.
331 @node Debug Tail Recursion
332 @comment node-name, next, previous, up
333 @subsection Debug Tail Recursion
334 @cindex Tail recursion
335 @cindex Recursion, tail
337 The compiler is ``properly tail recursive.'' If a function call is in
338 a tail-recursive position, the stack frame will be deallocated
339 @emph{at the time of the call}, rather than after the call returns.
340 Consider this backtrace:
347 Because of tail recursion, it is not necessarily the case that
348 @code{FOO} directly called @code{BAR}. It may be that @code{FOO}
349 called some other function @code{FOO2} which then called @code{BAR}
350 tail-recursively, as in this example:
366 Usually the elimination of tail-recursive frames makes debugging more
367 pleasant, since these frames are mostly uninformative. If there is any
368 doubt about how one function called another, it can usually be
369 eliminated by finding the source location in the calling frame.
370 @xref{Source Location Printing}.
372 The elimination of tail-recursive frames can be prevented by disabling
373 tail-recursion optimization, which happens when the @code{debug}
374 optimization quality is greater than @code{2}.
375 @xref{Debugger Policy Control}.
377 @comment FIXME: reinstate this link once the chapter is in the manual.
378 @c For a more thorough discussion of tail recursion, @ref{tail-recursion}.
380 @node Unknown Locations and Interrupts
381 @comment node-name, next, previous, up
382 @subsection Unknown Locations and Interrupts
383 @cindex Unknown code locations
384 @cindex Locations, unknown
386 @cindex Errors, run-time
388 The debugger operates using special debugging information attached to
389 the compiled code. This debug information tells the debugger what it
390 needs to know about the locations in the code where the debugger can
391 be invoked. If the debugger somehow encounters a location not
392 described in the debug information, then it is said to be
393 @dfn{unknown}. If the code location for a frame is unknown, then some
394 variables may be inaccessible, and the source location cannot be
397 There are three reasons why a code location could be unknown:
402 There is inadequate debug information due to the value of the @code{debug}
403 optimization quality. @xref{Debugger Policy Control}.
406 The debugger was entered because of an interrupt such as @key{C-c}.
409 A hardware error such as ``@samp{bus error}'' occurred in code that was
410 compiled unsafely due to the value of the @code{safety} optimization
412 @comment FIXME: reinstate link when section on optimize qualities exists.
413 @c @xref{optimize-declaration}.
417 In the last two cases, the values of argument variables are
418 accessible, but may be incorrect. For more details on when variable
419 values are accessible, @ref{Variable Value Availability}.
421 It is possible for an interrupt to happen when a function call or
422 return is in progress. The debugger may then flame out with some
423 obscure error or insist that the bottom of the stack has been reached,
424 when the real problem is that the current stack frame can't be
425 located. If this happens, return from the interrupt and try again.
428 @node Variable Access
429 @comment node-name, next, previous, up
430 @section Variable Access
431 @cindex Debug variables
432 @cindex Variables, debugger access
434 There are two ways to access the current frame's local variables in
435 the debugger: @command{list-locals} and @code{sb-debug:var}.
437 The debugger doesn't really understand lexical scoping; it has just
438 one namespace for all the variables in the current stack frame. If a
439 symbol is the name of multiple variables in the same function, then
440 the reference appears ambiguous, even though lexical scoping specifies
441 which value is visible at any given source location. If the scopes of
442 the two variables are not nested, then the debugger can resolve the
443 ambiguity by observing that only one variable is accessible.
445 When there are ambiguous variables, the evaluator assigns each one a
446 small integer identifier. The @code{sb-debug:var} function uses this
447 identifier to distinguish between ambiguous variables. The
448 @command{list-locals} command prints the identifier. In the
449 following example, there are two variables named @code{X}. The first
450 one has identifier 0 (which is not printed), the second one has
458 @deffn {Debugger Command} @nopkg{list-locals} [@var{prefix}]
459 This command prints the name and value of all variables in the current
460 frame whose name has the specified @var{prefix}. @var{prefix} may be
461 a string or a symbol. If no @var{prefix} is given, then all available
462 variables are printed. If a variable has a potentially ambiguous
463 name, then the name is printed with a ``@code{#@var{identifier}}''
464 suffix, where @var{identifier} is the small integer used to make the
468 @defun @sbdebug{var} @var{name} &optional @var{identifier}
469 This function returns the value of the variable in the current frame
470 with the specified @var{name}. If supplied, @var{identifier}
471 determines which value to return when there are ambiguous variables.
473 When @var{name} is a symbol, it is interpreted as the symbol name of
474 the variable, i.e. the package is significant. If @var{name} is an
475 uninterned symbol (gensym), then return the value of the uninterned
476 variable with the same name. If @var{name} is a string,
477 @code{sb-debug:var} interprets it as the prefix of a variable name
478 that must unambiguously complete to the name of a valid variable.
480 @var{identifier} is used to disambiguate the variable name; use
481 @command{list-locals} to find out the identifiers.
486 * Variable Value Availability::
487 * Note On Lexical Variable Access::
490 @node Variable Value Availability
491 @comment node-name, next, previous, up
492 @subsection Variable Value Availability
493 @cindex Availability of debug variables
494 @cindex Validity of debug variables
495 @cindex Debug optimization quality
497 The value of a variable may be unavailable to the debugger in portions
498 of the program where Lisp says that the variable is defined. If a
499 variable value is not available, the debugger will not let you read or
500 write that variable. With one exception, the debugger will never
501 display an incorrect value for a variable. Rather than displaying
502 incorrect values, the debugger tells you the value is unavailable.
504 The one exception is this: if you interrupt (e.g., with @key{C-c}) or
505 if there is an unexpected hardware error such as ``@samp{bus error}''
506 (which should only happen in unsafe code), then the values displayed
507 for arguments to the interrupted frame might be
508 incorrect.@footnote{Since the location of an interrupt or hardware
509 error will always be an unknown location, non-argument variable values
510 will never be available in the interrupted frame. @xref{Unknown
511 Locations and Interrupts}.} This exception applies only to the
512 interrupted frame: any frame farther down the stack will be fine.
514 The value of a variable may be unavailable for these reasons:
519 The value of the @code{debug} optimization quality may have omitted debug
520 information needed to determine whether the variable is available.
521 Unless a variable is an argument, its value will only be available when
522 @code{debug} is at least @code{2}.
525 The compiler did lifetime analysis and determined that the value was no longer
526 needed, even though its scope had not been exited. Lifetime analysis is
527 inhibited when the @code{debug} optimization quality is @code{3}.
530 The variable's name is an uninterned symbol (gensym). To save space, the
531 compiler only dumps debug information about uninterned variables when the
532 @code{debug} optimization quality is @code{3}.
535 The frame's location is unknown (@pxref{Unknown Locations and
536 Interrupts}) because the debugger was entered due to an interrupt or
537 unexpected hardware error. Under these conditions the values of
538 arguments will be available, but might be incorrect. This is the
539 exception mentioned above.
542 The variable (or the code referencing it) was optimized out
543 of existence. Variables with no reads are always optimized away. The
544 degree to which the compiler deletes variables will depend on the
545 value of the @code{compilation-speed} optimization quality, but most
546 source-level optimizations are done under all compilation policies.
549 The variable is never set and its definition looks like
554 In this case, @code{var1} is substituted with @code{var2}.
557 The variable is never set and is referenced exactly once. In this
558 case, the reference is substituted with the variable initial value.
562 Since it is especially useful to be able to get the arguments to a
563 function, argument variables are treated specially when the
564 @code{speed} optimization quality is less than @code{3} and the
565 @code{debug} quality is at least @code{1}. With this compilation
566 policy, the values of argument variables are almost always available
567 everywhere in the function, even at unknown locations. For
568 non-argument variables, @code{debug} must be at least @code{2} for
569 values to be available, and even then, values are only available at
573 @node Note On Lexical Variable Access
574 @comment node-name, next, previous, up
575 @subsection Note On Lexical Variable Access
577 When the debugger command loop establishes variable bindings for
578 available variables, these variable bindings have lexical scope and
579 dynamic extent.@footnote{The variable bindings are actually created
580 using the Lisp @code{symbol-macrolet} special form.} You can close
581 over them, but such closures can't be used as upward funargs.
583 You can also set local variables using @code{setq}, but if the
584 variable was closed over in the original source and never set, then
585 setting the variable in the debugger may not change the value in all
586 the functions the variable is defined in. Another risk of setting
587 variables is that you may assign a value of a type that the compiler
588 proved the variable could never take on. This may result in bad
592 @node Source Location Printing
593 @comment node-name, next, previous, up
594 @section Source Location Printing
595 @cindex Source location printing, debugger
597 One of the debugger's capabilities is source level debugging of
598 compiled code. These commands display the source location for the
601 @deffn {Debugger Command} @nopkg{source} [@var{context}]
602 This command displays the file that the current frame's function was
603 defined from (if it was defined from a file), and then the source form
604 responsible for generating the code that the current frame was
605 executing. If @var{context} is specified, then it is an integer
606 specifying the number of enclosing levels of list structure to print.
609 The source form for a location in the code is the innermost list present
610 in the original source that encloses the form responsible for generating
611 that code. If the actual source form is not a list, then some enclosing
612 list will be printed. For example, if the source form was a reference
613 to the variable @code{*some-random-special*}, then the innermost
614 enclosing evaluated form will be printed. Here are some possible
618 (let ((a *some-random-special*))
621 (+ *some-random-special* ...)
624 If the code at a location was generated from the expansion of a macro
625 or a source-level compiler optimization, then the form in the original
626 source that expanded into that code will be printed. Suppose the file
627 @file{/usr/me/mystuff.lisp} looked like this:
638 If @code{foo} has called @code{myfun}, and is waiting for it to
639 return, then the @command{source} command would print:
642 ; File: /usr/me/mystuff.lisp
647 Note that the macro use was printed, not the actual function call form,
650 If enclosing source is printed by giving an argument to
651 @command{source} or @command{vsource}, then the actual source form is
652 marked by wrapping it in a list whose first element is
653 @samp{#:***HERE***}. In the previous example, @code{source 1} would
657 ; File: /usr/me/mystuff.lisp
667 * How the Source is Found::
668 * Source Location Availability::
671 @node How the Source is Found
672 @comment node-name, next, previous, up
673 @subsection How the Source is Found
675 If the code was defined from Lisp by @code{compile} or
676 @code{eval}, then the source can always be reliably located. If the
677 code was defined from a @file{fasl} file created by
678 @code{compile-file}, then the debugger gets the source forms it
679 prints by reading them from the original source file. This is a
680 potential problem, since the source file might have moved or changed
681 since the time it was compiled.
683 The source file is opened using the @code{truename} of the source file
684 pathname originally given to the compiler. This is an absolute pathname
685 with all logical names and symbolic links expanded. If the file can't
686 be located using this name, then the debugger gives up and signals an
689 If the source file can be found, but has been modified since the time it was
690 compiled, the debugger prints this warning:
693 ; File has been modified since compilation:
695 ; Using form offset instead of character position.
698 where @var{filename} is the name of the source file. It then proceeds
699 using a robust but not foolproof heuristic for locating the source.
700 This heuristic works if:
705 No top-level forms before the top-level form containing the source
706 have been added or deleted, and
709 The top-level form containing the source has not been modified much.
710 (More precisely, none of the list forms beginning before the source
711 form have been added or deleted.)
715 If the heuristic doesn't work, the displayed source will be wrong, but will
716 probably be near the actual source. If the ``shape'' of the top-level form in
717 the source file is too different from the original form, then an error will be
718 signaled. When the heuristic is used, the source location commands are
721 Source location printing can also be confused if (after the source was
722 compiled) a read-macro you used in the code was redefined to expand
723 into something different, or if a read-macro ever returns the same
724 @code{eq} list twice. If you don't define read macros and don't use
725 @code{##} in perverted ways, you don't need to worry about this.
728 @node Source Location Availability
729 @comment node-name, next, previous, up
730 @subsection Source Location Availability
731 @cindex Debug optimization quality
733 @cindex Block, start location
735 Source location information is only available when the @code{debug}
736 optimization quality is at least @code{2}. If source location
737 information is unavailable, the source commands will give an error
740 If source location information is available, but the source location
741 is unknown because of an interrupt or unexpected hardware error
742 (@pxref{Unknown Locations and Interrupts}), then the command will
746 Unknown location: using block start.
749 and then proceed to print the source location for the start of the
750 @emph{basic block} enclosing the code location. It's a bit
751 complicated to explain exactly what a basic block is, but here are
752 some properties of the block start location:
756 @item The block start location may be the same as the true location.
758 @item The block start location will never be later in the
759 program's flow of control than the true location.
761 @item No conditional control structures (such as @code{if},
762 @code{cond}, @code{or}) will intervene between the block start and the
763 true location (but note that some conditionals present in the original
764 source could be optimized away.) Function calls @emph{do not} end
767 @item The head of a loop will be the start of a block.
769 @item The programming language concept of ``block structure'' and the
770 Lisp @code{block} special form are totally unrelated to the compiler's
775 In other words, the true location lies between the printed location and the
776 next conditional (but watch out because the compiler may have changed the
780 @node Debugger Policy Control
781 @comment node-name, next, previous, up
782 @section Debugger Policy Control
783 @cindex Policy, debugger
784 @cindex Debug optimization quality
785 @cindex Optimize declaration
786 @cindex Inline expansion
787 @cindex Semi-inline expansion
789 The compilation policy specified by @code{optimize} declarations
790 affects the behavior seen in the debugger. The @code{debug} quality
791 directly affects the debugger by controlling the amount of debugger
792 information dumped. Other optimization qualities have indirect but
793 observable effects due to changes in the way compilation is done.
795 Unlike the other optimization qualities (which are compared in relative value
796 to evaluate tradeoffs), the @code{debug} optimization quality is directly
797 translated to a level of debug information. This absolute interpretation
798 allows the user to count on a particular amount of debug information being
799 available even when the values of the other qualities are changed during
800 compilation. These are the levels of debug information that correspond to the
801 values of the @code{debug} quality:
806 Only the function name and enough information to allow the stack to
810 Any level greater than @code{0} gives level @code{0} plus all argument
811 variables. Values will only be accessible if the argument variable is
812 never set and @code{speed} is not @code{3}. SBCL allows any real
813 value for optimization qualities. It may be useful to specify
814 @code{0.5} to get backtrace argument display without argument
818 Level @code{1} provides argument documentation (printed arglists) and
819 derived argument/result type information. This makes @code{describe}
820 more informative, and allows the compiler to do compile-time argument
821 count and type checking for any calls compiled at run-time. This is
825 Level @code{1} plus all interned local variables, source location
826 information, and lifetime information that tells the debugger when
827 arguments are available (even when @code{speed} is @code{3} or the
831 Any level greater than @code{2} gives level @code{2} and in addition
832 disables tail-call optimization, so that the backtrace will contain
833 frames for all invoked functions, even those in tail positions.
836 Level @code{2} plus all uninterned variables. In addition, lifetime
837 analysis is disabled (even when @code{speed} is @code{3}), ensuring
838 that all variable values are available at any known location within
839 the scope of the binding. This has a speed penalty in addition to the
840 obvious space penalty.
842 @item > (max speed space)
843 If @code{debug} is greater than both @code{speed} and @code{space},
844 the command @command{return} can be used to continue execution by
845 returning a value from the current stack frame.
847 @item > (max speed space compilation-speed)
848 If @code{debug} is greater than all of @code{speed}, @code{space} and
849 @code{compilation-speed} the code will be steppable (@pxref{Single Stepping}).
853 As you can see, if the @code{speed} quality is @code{3}, debugger performance is
854 degraded. This effect comes from the elimination of argument variable
855 special-casing (@pxref{Variable Value Availability}). Some degree of
856 speed/debuggability tradeoff is unavoidable, but the effect is not too drastic
857 when @code{debug} is at least @code{2}.
859 In addition to @code{inline} and @code{notinline} declarations, the
860 relative values of the @code{speed} and @code{space} qualities also
861 change whether functions are inline expanded.
862 @comment FIXME: link to section about inline expansion when it exists
863 @c (\pxlref{inline-expansion}.)
864 If a function is inline expanded, then
865 there will be no frame to represent the call, and the arguments will
866 be treated like any other local variable. Functions may also be
867 ``semi-inline'', in which case there is a frame to represent the call,
868 but the call is to an optimized local version of the function, not to
869 the original function.
872 @node Exiting Commands
873 @comment node-name, next, previous, up
874 @section Exiting Commands
876 These commands get you out of the debugger.
878 @deffn {Debugger Command} @nopkg{toplevel}
882 @deffn {Debugger Command} @nopkg{restart} [@var{n}]
883 Invokes the @var{n}th restart case as displayed by the @code{error}
884 command. If @var{n} is not specified, the available restart cases are
888 @deffn {Debugger Command} @nopkg{continue}
889 Calls @code{continue} on the condition given to @code{debug}. If there is no
890 restart case named @var{continue}, then an error is signaled.
893 @deffn {Debugger Command} @nopkg{abort}
894 Calls @code{abort} on the condition given to @code{debug}. This is
895 useful for popping debug command loop levels or aborting to top level,
899 @deffn {Debugger Command} @nopkg{return} @var{value}
900 Returns @var{value} from the current stack frame. This command is
901 available when the @code{debug} optimization quality is greater than
902 both @code{speed} and @code{space}. Care must be taken that the value
903 is of the same type as SBCL expects the stack frame to return.
906 @deffn {Debugger Command} @nopkg{restart-frame}
907 Restarts execution of the current stack frame. This command is
908 available when the @code{debug} optimization quality is greater than
909 both @code{speed} and @code{space} and when the frame is for is a global
910 function. If the function is redefined in the debugger before the frame
911 is restarted, the new function will be used.
914 @node Information Commands
915 @comment node-name, next, previous, up
916 @section Information Commands
918 Most of these commands print information about the current frame or
919 function, but a few show general information.
921 @deffn {Debugger Command} @nopkg{help}
922 @deffnx {Debugger Command} @nopkg{?}
923 Displays a synopsis of debugger commands.
926 @deffn {Debugger Command} @nopkg{describe}
927 Calls @code{describe} on the current function and displays the number of
931 @deffn {Debugger Command} @nopkg{print}
932 Displays the current function call as it would be displayed by moving to
936 @deffn {Debugger Command} @nopkg{error}
937 Prints the condition given to @code{invoke-debugger} and the active
941 @deffn {Debugger Command} @nopkg{backtrace} [@var{n}]
942 Displays all the frames from the current to the bottom. Only shows
943 @var{n} frames if specified. The printing is controlled by
944 @code{*debug-print-variable-alist*}.
947 @c The new instrumentation based single stepper doesn't support
948 @c the following commands, but BREAKPOINT at least should be
949 @c resurrectable via (TRACE FOO :BREAK T).
951 @c @cindex Breakpoints
953 @c SBCL supports setting of breakpoints inside compiled functions and
954 @c stepping of compiled code. Breakpoints can only be set at known
955 @c locations (@pxref{Unknown Locations and Interrupts}), so these
956 @c commands are largely useless unless the @code{debug} optimize quality
957 @c is at least @code{2} (@pxref{Debugger Policy Control}). These
958 @c commands manipulate breakpoints:
960 @c @deffn {Debugger Command} breakpoint @var{location} [@var{option} @var{value}]*
961 @c Set a breakpoint in some function. @var{location} may be an integer
962 @c code location number (as displayed by @command{list-locations}) or a
963 @c keyword. The keyword can be used to indicate setting a breakpoint at
964 @c the function start (@code{:start}, @code{:s}) or function end
965 @c (@code{:end}, @code{:e}). The @command{breakpoint} command has
966 @c @code{:condition}, @code{:break}, @code{:print} and @code{:function}
967 @c options which work similarly to the @code{trace} options.
970 @c @deffn {Debugger Command} list-locations [@var{function}]
971 @c @deffnx {Debugger Command} ll [@var{function}]
972 @c List all the code locations in the current frame's function, or in
973 @c @var{function} if it is supplied. The display format is the code
974 @c location number, a colon and then the source form for that location:
980 @c If consecutive locations have the same source, then a numeric range
981 @c like @code{3-5:} will be printed. For example, a default function
982 @c call has a known location both immediately before and after the call,
983 @c which would result in two code locations with the same source. The
984 @c listed function becomes the new default function for breakpoint
985 @c setting (via the @command{breakpoint}) command.
988 @c @deffn {Debugger Command} list-breakpoints
989 @c @deffnx {Debugger Command} lb
990 @c List all currently active breakpoints with their breakpoint number.
993 @c @deffn {Debugger Command} delete-breakpoint [@var{number}]
994 @c @deffnx {Debugger Command} db [@var{number}]
995 @c Delete a breakpoint specified by its breakpoint number. If no number
996 @c is specified, delete all breakpoints.
1000 @c * Breakpoint Example::
1003 @c @node Breakpoint Example, , Breakpoint Commands, Breakpoint Commands
1004 @c @comment node-name, next, previous, up
1005 @c @subsection Breakpoint Example
1007 @c Consider this definition of the factorial function:
1013 @c (* n (! (1- n)))))
1016 @c This debugger session demonstrates the use of breakpoints:
1019 @c * (break) ; invoke debugger
1021 @c debugger invoked on a SIMPLE-CONDITION in thread 11184: break
1023 @c restarts (invokable by number or by possibly-abbreviated name):
1024 @c 0: [CONTINUE] Return from BREAK.
1025 @c 1: [ABORT ] Reduce debugger level (leaving debugger, returning to toplevel).
1026 @c 2: [TOPLEVEL] Restart at toplevel READ/EVAL/PRINT loop.
1027 @c ("varargs entry for top level local call BREAK" "break")
1030 @c 0-1: (SB-INT:NAMED-LAMBDA ! (N) (BLOCK ! (IF (ZEROP N) 1 (* N (! #)))))
1031 @c 2: (BLOCK ! (IF (ZEROP N) 1 (* N (! (1- N)))))
1033 @c 4: (* N (! (1- N)))
1036 @c 7-8: (* N (! (1- N)))
1037 @c 9-10: (IF (ZEROP N) 1 (* N (! (1- N))))
1045 @c FIXME: SBCL errored out, and not in the expected way ... Copying the
1046 @c output verbatim from the CMUCL manual for now.
1048 @c common-lisp-user> (! 10) ; Call the function
1053 @c 0: [CONTINUE] Return from BREAK.
1054 @c 1: [ABORT ] Return to Top-Level.
1056 @c Debug (type H for help)
1058 @c (! 10) ; We are now in first call (arg 10) before the multiply
1059 @c Source: (* N (! (1- N)))
1064 @c (! 10) ; We have finished evaluation of (1- n)
1071 @c 0: [CONTINUE] Return from BREAK.
1072 @c 1: [ABORT ] Return to Top-Level.
1074 @c Debug (type H for help)
1076 @c (! 9) ; We hit the breakpoint in the recursive call
1077 @c Source: (* N (! (1- N)))
1082 @node Function Tracing
1083 @comment node-name, next, previous, up
1084 @section Function Tracing
1086 @cindex Function, tracing
1088 The tracer causes selected functions to print their arguments and
1089 their results whenever they are called. Options allow conditional
1090 printing of the trace information and conditional breakpoints on
1091 function entry or exit.
1093 @include macro-common-lisp-trace.texinfo
1095 @include macro-common-lisp-untrace.texinfo
1097 @include var-sb-debug-star-trace-indentation-step-star.texinfo
1099 @include var-sb-debug-star-max-trace-indentation-star.texinfo
1101 @include var-sb-debug-star-trace-encapsulate-default-star.texinfo
1103 @include var-sb-debug-star-trace-values-star.texinfo
1105 @comment FIXME rudi 2004-03-26: encapsulate is (per TODO file as of
1106 @comment 0.8.9) in a state of flux. When it's sorted out, revive the
1107 @comment cmucl documentation.
1109 @node Single Stepping
1110 @comment node-name, next, previous, up
1111 @section Single Stepping
1113 @cindex Single Stepping
1115 SBCL includes an instrumentation based single-stepper for compiled
1116 code, that can be invoked via the @code{step} macro, or from within
1117 the debugger. @xref{Debugger Policy Control}, for details on enabling
1118 stepping for compiled code.
1120 The following debugger commands are used for controlling single stepping.
1122 @deffn {Debugger Command} @nopkg{start}
1123 Selects the @code{continue} restart if one exists and starts single stepping.
1124 None of the other single stepping commands can be used before stepping has
1125 been started either by using @code{start} or by using the standard
1129 @deffn {Debugger Command} @nopkg{step}
1130 Steps into the current form. Stepping will be resumed when the next
1131 form that has been compiled with stepper instrumentation is evaluated.
1134 @deffn {Debugger Command} @nopkg{next}
1135 Steps over the current form. Stepping will be disabled until evaluation of
1136 the form is complete.
1139 @deffn {Debugger Command} @nopkg{out}
1140 Steps out of the current frame. Stepping will be disabled until the
1141 topmost stack frame that had been stepped into returns.
1144 @deffn {Debugger Command} @nopkg{stop}
1145 Stops the single stepper and resumes normal execution.
1148 @include macro-common-lisp-step.texinfo
1150 @node Enabling and Disabling the Debugger
1151 @comment node-name, next, previous, up
1152 @section Enabling and Disabling the Debugger
1154 @cindex debugger, enabling
1155 @cindex debugger, disabling
1156 @cindex disabling debugger
1157 @cindex ldb, enabling
1158 @cindex ldb, disabling
1159 @cindex disabling ldb
1161 In certain contexts (e.g., non-interactive applications), it may be
1162 desirable to turn off the SBCL debugger (and possibly re-enable it).
1163 The functions here control the debugger.
1165 @include fun-sb-ext-disable-debugger.texinfo
1167 @include fun-sb-ext-enable-debugger.texinfo