Next: Tracing Compared, Previous: Old Tracing, Up: Tracing
Guile's newer mechanism implements tracing as an optional behaviour for any kind of breakpoint.
To trace a procedure (in the same kind of way as the older tracing), use
the trace!
procedure to set a procedure breakpoint with
trace-here
behaviour:
(trace! fact1) -| Set breakpoint 1: [fact1] => #<<procedure-breakpoint> 40337bf0> (fact1 4) -| | [fact1 4] | | [fact1 3] | | | [fact1 2] | | | | [fact1 1] | | | | | [fact1 0] | | | | | 1 | | | | 2 | | | 6 | | 24 | 24 => 24
To trace evaluation of a source expression, evaluate code containing a
breakpoint marker ##
in the appropriate place, then use
set-breakpoint
to change the behaviour of the new breakpoint to
trace-here
:
(define (fact1 n) (if ##(= n 0) 1 (* n (fact1 (- n 1))))) -| Set breakpoint 4: standard input:13:9: (= n 0) (use-modules (ice-9 debugger behaviour)) (set-breakpoint! trace-here 4) -| Breakpoint 4: standard input:13:9: (= n 0) enabled? = #t behaviour = #<procedure trace-here ()> (fact1 4) -| | (= n 0) | #f | (= n 0) | #f | (= n 0) | #f | (= n 0) | #f | (= n 0) | #t => 24
(Note — this example reveals a bug: each occurrence of (= n 0)
should be shown indented with respect to the one before it, as
fact1
does not call itself tail-recursively.)
You can also give a breakpoint the trace-subtree
behaviour, which
means to trace the breakpoint location itself plus any evaluations and
applications that occur below it in the call stack. In the following
example, this allows us to see the evaluated arguments that are being
compared by the =
procedure:
(set-breakpoint! trace-subtree 4) -| Breakpoint 4: standard input:13:9: (= n 0) enabled? = #t behaviour = #<procedure trace-subtree ()> (fact1 4) -| | (= n 0) | [= 4 0] | #f | (= n 0) | [= 3 0] | #f | (= n 0) | [= 2 0] | #f | (= n 0) | [= 1 0] | #f | (= n 0) | [= 0 0] | #t => 24