我有以下程序:
debugging.scm
(define (fn1 x)
(printf "fn1/ x=~a\n" x)
(fn2 x)
(printf "fn1/ end\n"))
(define (fn2 x)
(printf "fn2/ x=~a\n" x)
(fn3 x)
(printf "fn2/ end\n"))
(define (fn3 x)
(printf "fn3/ x=~a\n" x)
(cdr x)
(printf "fn3/ end\n"))我在REPL中运行它。不出所料,它崩溃了。
然后,我进入了调试模式,并检查了raise延续。
$ scheme
Chez Scheme Version 9.5.2
Copyright 1984-2019 Cisco Systems, Inc.
> (load "debugging.scm")
> (fn1 100)
fn1/ x=100
fn2/ x=100
fn3/ x=100
Exception in cdr: 100 is not a pair
Type (debug) to enter the debugger.
> (debug)
debug> ?
Type i to inspect the raise continuation (if available)
s to display the condition
c to inspect the condition
e or eof to exit the debugger, retaining error continuation
q to exit the debugger, discarding error continuation
debug> i
#<continuation in fn2> : ?
length(l) ........... display number of frame and closure variables
depth ............... display number of frames in continuation stack
ref(r) .............. inspect [named or nth] variable
set!(!) ............. set [named or nth] variable to value, if assignable
forward(f) .......... move to [nth] next frame
back(b) ............. move to [nth] previous frame
down(d) ............. inspect [nth] next frame
closure(cp) ......... inspect the frame's closure, if any
eval(e) ............. evaluate expression in context of current frame
show(s) ............. show frame with free variables
show-local(sl) ...... show frame without free variables
show-frames(sf) ..... show the next [n] frames
call ................ inspect the code for the pending call
code(c) ............. inspect the code for the pending procedure
file ................ switch to source file containing the pending call
?? .................. display more options
#<continuation in fn2> : sf
0: #<continuation in fn2>
1: #<continuation in fn1>
2: #<system continuation in new-cafe>
#<continuation in fn2> : e
_ ????我的问题是,是否有可能在调试模式下获得当前的raise继续?
我想通过计算表达式来检查它,例如
(inspect/object current-raise-continuation)谢谢。
发布于 2021-09-27 07:01:21
您可以向调试器中的continuation发送一条消息,如下所示:
$ scheme
Chez Scheme Version 9.5.2
Copyright 1984-2019 Cisco Systems, Inc.
> (load "debugging.scm")
> (fn1 100)
fn1/ x=100
fn2/ x=100
fn3/ x=100
Exception in cdr: 100 is not a pair
Type (debug) to enter the debugger.
> (debug)
debug> i
#<continuation in fn2> : => (lambda (x) ((inspect/object x) 'source-path))
"debugging.scm"
8
5
#<continuation in fn2> : 或者,您可以将此代码添加到debugging.scm:
(define (message-continuation-on-exception thunk symbol)
;; (note: no error checks, may be Chez version dependent?)
(guard (condition
[else (call-with-values (lambda ()
(((inspect/object
(list-ref (simple-conditions condition) 5))
'ref 'k) symbol))
(lambda vs (for-each display `("Exception, " ,symbol ": " ,vs))))])
(thunk)))然后像这样使用它:
$ scheme
Chez Scheme Version 9.5.2
Copyright 1984-2019 Cisco Systems, Inc.
> (load "debugging.scm")
> (message-continuation-on-exception
(lambda () (fn1 100)) 'source-path)
fn1/ x=100
fn2/ x=100
fn3/ x=100
Exception, source-path: (debugging.scm 8 5)
> https://stackoverflow.com/questions/69324844
复制相似问题