2 @node Debugging Features
3 @chapter Debugging Features
5 @c --- The title and introduction of this appendix need to
6 @c distinguish this clearly from the chapter on the internal
7 @c debugging interface.
9 When debugging a program, programmers often find it helpful to examine
10 the program's internal status while it runs: the values of internal
11 variables, the choices made in @code{if} and @code{cond} statements, and
12 so forth. Guile Scheme provides a debugging interface that programmers
13 can use to single-step through Scheme functions and examine symbol
14 bindings. This is different from the @ref{Debugging}, which permits
15 programmers to debug the Guile interpreter itself. Most programmers
16 will be more interested in debugging their own Scheme programs than the
17 interpreter which evaluates them.
19 [FIXME: should we include examples of traditional debuggers
20 and explain why they can't be used to debug interpreted Scheme or Lisp?]
23 * Single-Step:: Execute a program or function one step at a time.
24 * Trace:: Print a report each time a given function is called.
25 * Backtrace:: See a list of the statements that caused an error.
36 When a function is @dfn{traced}, it means that every call to that
37 function is reported to the user during a program run. This can help a
38 programmer determine whether a function is being called at the wrong
39 time or with the wrong set of arguments.
42 Enable debug tracing on @code{function}. While a program is being run, Guile
43 will print a brief report at each call to a traced function,
44 advising the user which function was called and the arguments that were
48 @defun untrace function
49 Disable debug tracing for @code{function}.
58 (append (rev (cdr ls))
59 (cons (car ls) '())))) @result{} rev
61 (trace rev) @result{} (rev)
64 @result{} [rev (a b c d e)]
79 Note the way Guile indents the output, illustrating the depth of
80 execution at each function call. This can be used to demonstrate, for
81 example, that Guile implements self-tail-recursion properly:
88 (cons (car ls) sl)))) @result{} rev
90 (trace rev) @result{} (rev)
92 (rev '(a b c d e) '())
93 @result{} [rev (a b c d e) ()]
103 Since the tail call is effectively optimized to a @code{goto} statement,
104 there is no need for Guile to create a new stack frame for each
105 iteration. Using @code{trace} here helps us see why this is so.
111 @deffn {Scheme Procedure} backtrace
112 @deffnx {C Function} scm_backtrace ()
113 Display a backtrace of the stack saved by the last error
114 to the current output port.