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
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]>