首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否有可能在Chez-Scheme的调试模式下获得当前的raise继续?

是否有可能在Chez-Scheme的调试模式下获得当前的raise继续?
EN

Stack Overflow用户
提问于 2021-09-25 09:29:06
回答 1查看 58关注 0票数 0

我有以下程序:

debugging.scm

代码语言:javascript
复制
(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延续。

代码语言:javascript
复制
$ 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继续?

我想通过计算表达式来检查它,例如

代码语言:javascript
复制
(inspect/object current-raise-continuation)

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-27 07:01:21

您可以向调试器中的continuation发送一条消息,如下所示:

代码语言:javascript
复制
$ 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:

代码语言:javascript
复制
(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)))

然后像这样使用它:

代码语言:javascript
复制
$ 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)
> 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69324844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档