CLisp 12:使用CLisp的命令行模式的调试器

构造一个被零除的错误
(/ 10 0)
*** - /: division by zero
The following restarts are available:
ABORT          :R1      Abort main loop
Break 1 [11]>

 

出现错误后怎么办呢,前面讲过按ctrl+d可以退出调试模式,这里讲怎么使用调试功能。先输入help看一下帮助信息:
Break 1 [13]> help

Commands may be abbreviated as shown in the second column.
COMMAND        ABBR     DESCRIPTION
Help           :h, ?    print this command list
Error          :e       print the last error message
Inspect        :i       inspect the last error
Abort          :a       abort to the next recent input loop
Unwind         :uw      abort to the next recent input loop
Reset          :re      toggle *PACKAGE* and *READTABLE* between the
                          local bindings and the sane values
Quit           :q       quit to the top-level input loop
Where          :w       inspect this frame
Up             :u       go up one frame, inspect it
Top            :t       go to top frame, inspect it
Down           :d       go down one frame, inspect it
Bottom         :b       go to bottom (most recent) frame, inspect it
Mode mode      :m       set stack mode for Backtrace: 1=all the stack elements
             2=all the frames                         3=only lexical frames
             4=only EVAL and APPLY frames (default)   5=only APPLY frames
Frame-limit n  :fl      set the frame-limit for Backtrace. This many frames
                          will be printed in a backtrace at most.
Backtrace [mode [limit]] :bt  inspect the stack
Break+         :br+     set breakpoint in EVAL frame
Break-         :br-     disable breakpoint in EVAL frame
Redo           :rd      re-evaluate form in EVAL frame
Return value   :rt      leave EVAL frame, prescribing the return values
The following restarts are available:
ABORT          :R1      Abort main loop
Break 1 [13]>

 

help:打印帮助信息


Error:查看最后一次的错误提示信息


Abort、Unwind、Quit:退出调试器,Abort和Unwind功能相同,和Quit有差别,调试也是分层次的,在调试过程中又出现错误则进入下一层,

Abort退出当前调试回到上一层,Quit退出所有层次的调试。下面第一个例子用abort逐层退出,第二个例子用quit退出所有层。

 

[39]> (/ 1 0)
Break 1 [40]> (/ 2 0)
Break 2 [41]> (/ 3 0)
Break 3 [42]> abort
Break 2 [41]> unwind
Break 1 [40]> abort
[43]>

[43]> (/ 1 0)
Break 1 [44]> (/ 2 0)
Break 2 [45]> (/ 3 0)
Break 3 [46]> quit
[47]>

 

Return value:强制从出错的函数返回,返回值为输入的value,然后继续执行后面的指令,例如:
[62]> (print (/ 1 0))
*** - /: division by zero
The following restarts are available:
ABORT          :R1      Abort main loop
Break 1 [63]> return '(a b c)
(A B C)
(A B C)
[64]>
遇到被零除错误后,输入调试命令return '(a b c),相当于让(/ 1 0)返回列表(a b c),最后打印出该列表。


Where:显示出错的函数,注意不是整个调用栈
例如,执行(print (/ 1 0))出错后,执行Where后输出 [34] EVAL frame for form (/ 1 0)

 

Backtrace:打印调用栈,有5中模式,缺省是模式4,要改变模式时直接在Backtrace后面加数字1~5,例如Backtrace 1。

 1=all the stack elements
 2=all the frames
 3=only lexical frames
 4=only EVAL and APPLY frames (default)
 5=only APPLY frames

 

backtrace五种模式的区别
首先区分一下堆栈里面的对象类型
apply frame:对函数的调用,包括函数名和实际传入的参数
eval frame:执行的S表达式,也就是一层一层的括号
lexical frame:和LISP内部实现相关的东西,自己研究吧
模式1:显示堆栈中所有类型的对象
模式2:显示apply frame、eval frame和lexical frame
模式3:显示lexical frame
模式4:显示eval frame和apply frame
模式5:显示apply frame
如果只想看函数调用关系,用模式5;如果想看一层层的括号,用模式4,一般都用模式4。
有些版本的CLisp显示的东西比较多,注意找eval frame和apply frame即可。

 

Up、Down:在调用栈中爬上爬下,会改变Where命令的输出。例如,下面命令出错时调用栈有三层,用up、down可以改变层次
[71]> (print (+ (/ 1 0) 3))

此时执行backtrace 2,打印很多信息,其中最用用的是
[38] EVAL frame for form (/ 1 0)
[34] EVAL frame for form (+ (/ 1 0) 3)
[30] EVAL frame for form (PRINT (+ (/ 1 0) 3))

再执行up、down命令
Break 1 [72]> up
[34] EVAL frame for form (+ (/ 1 0) 3)
Break 1 [72]> up
[30] EVAL frame for form (PRINT (+ (/ 1 0) 3))
Break 1 [72]> down
[34] EVAL frame for form (+ (/ 1 0) 3)
Break 1 [72]> down
[38] EVAL frame for form (/ 1 0)
Break 1 [72]>

 

使用redo重新执行S表达式
先用where显示当前的表达式,再用up和down改变当前的表达式,最后执行redo,就能重新执行当前的表达式。

提示,使用return前,也可以用up和down改变当前的表达式。 


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值