Next: , Previous: How to Set a Trap, Up: Traps


5.21.3.3 Specifying Trap Behaviour

Guile provides several “out-of-the-box” behaviours for common needs. All of the following can be used directly as the value of the #:behaviour option when creating a trap object.

— Procedure: debug-trap trap-context

Enter Guile's command line debugger to explore the stack at trap-context, and to single-step or continue program execution from that point.

— Procedure: gds-debug-trap trap-context

Use the GDS debugging interface, which displays the stack and corresponding source code via Emacs, to explore the stack at trap-context and to single-step or continue program execution from that point.

— Procedure: trace-trap trap-context

Display trace information to summarize the current trap-context.

— Procedure: trace-at-exit trap-context

Install a further trap to cause the return value of the application or evaluation just starting (as described by trap-context) to be traced using trace-trap, when this application or evaluation completes. The extra trap is automatically uninstalled after the return value has been traced.

— Procedure: trace-until-exit trap-context

Install a further trap so that every step that the evaluator performs as part of the application or evaluation just starting (as described by trap-context) is traced using trace-trap. The extra trap is automatically uninstalled when the application or evaluation is complete. trace-until-exit can be very useful as a first step when all you know is that there is a bug “somewhere in XXX or in something that XXX calls”.

debug-trap and gds-debug-trap are provided by the modules (ice-9 debugger) and (ice-9 gds-client) respectively, and their behaviours are fairly self-explanatory. For more information on the operation of the GDS interface via Emacs, see Using Guile in Emacs. The tracing behaviours are explained more fully below.

More generally, the behaviour specified for a trap can be any procedure that expects to be called with one trap context argument. A trivial example would be:

     (define (report-stack-depth trap-context)
       (display "Stack depth at the trap is: ")
       (display (tc:depth trap-context))
       (newline))