Next: , Previous: , Up: Operational Features   [Contents][Index]

3.9 Debugging Continuations

These functions are defined in debug.c, all operate on captured continuations:

Procedure: frame-trace cont n

Prints information about the code being executed and the environment scopes active for continuation frame n of continuation CONT. A "continuation frame" is an entry in the environment stack; a new frame is pushed when the environment is replaced or extended in a non-tail call context. Frame 0 is the top of the stack.

Procedure: frame->environment cont n

Prints the environment for continuation frame n of continuation cont. This contains just the names, not the values, of the environment.

Procedure: scope-trace env

will print information about active lexical scopes for environment env.

Procedure: frame-eval cont n expr

Evaluates expr in the environment defined by continuation frame n of continuation CONT and returns the result. Values in the environment may be returned or SET!.

stack-trace also now accepts an optional continuation argument. stack-trace differs from frame-trace in that it truncates long output using safeports and prints code from all available frames.

(define k #f)
(define (foo x y)
   (set! k (call-with-current-continuation identity))
   #f)
(let ((a 3) (b 4))
  (foo a b)
  #f)
(stack-trace k)
-|
;STACK TRACE
1; ((#@set! #@k (#@call-with-current-continuation #@identity)) #f ...
2; (#@let ((a 3) (b 4))  (#@foo #@a #@b) #f)
…
#t
(frame-trace k 0)
-|
(#@call-with-current-continuation #@identity)
; in scope:
;   (x y)  procedure foo#<unspecified>
(frame-trace k 1)
-|
((#@set! #@k (#@call-with-current-continuation #@identity)) #f)
; in scope:
;   (x y)  procedure foo#<unspecified>
(frame-trace k 2)
-|
(#@let ((a 3) (b 4))  (#@foo #@a #@b) #f)
; in scope:
;   (a b . #@let)#<unspecified>
(frame-trace k 3)
-|
(#@let ((a 3) (b 4))  (#@foo #@a #@b) #f)
; in top level environment.
(frame->environment k 0)
-|
((x y) 2 foo)
(scope-trace (frame->environment k 0))
-|
; in scope:
;   (x y)  procedure foo#<unspecified>
(frame-eval k 0 'x) ⇒ 3

(frame-eval k 0 '(set! x 8))
(frame-eval k 0 'x) ⇒ 8

Next: , Previous: , Up: Operational Features   [Contents][Index]