如何在[Clozure] Common Lisp中进行调试? [英] How to debug in [Clozure] Common Lisp?

查看:82
本文介绍了如何在[Clozure] Common Lisp中进行调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac上使用CCL(1.8.1,这是本文撰写时的最新版本),想知道是否有任何调试教程可用。



我特别感兴趣的是在代码中的某处设置断点,然后戳&探究各种值,然后遍历下一行代码,检查更多值,等等。



编辑:
请阅读CCL手册的调试部分(18.3及更高版本),但不能完全理解它。我来自C / Java / etc。

所以我想我正在寻找的是一个介绍/指南,可以指导我几个简单的步骤。



(我是Lisp的新手(当然还有CCL),所以,如果我问的是完全错误的问题或打算事情完全以错误的方式进行,请随时让我知道。)



谢谢!

解决方案

我确信CCL用户可以将您指向调试部分, CCL手册,但实际上,ANSI Common Lisp标准包括出色的调试功能,其中包括 break 您问过的步骤 步骤的gr除外匿名性不是基于一行代码,而是一种形式。)



实际上,整个条件系统值得研究。



有一个很少 教程



最重要的是要记住,调试工具为您提供了普通的Lisp REPL(读取-评估-打印循环)。可以使用初始REPL做几乎所有事情:定义函数和变量,检查现有变量(包括在其中输入调试器的函数中定义的变量)等。 另外,您也许可以发出其他命令,例如 step next (通常在步进器中缩写为:s :n )或继续(通常缩写为:c )中的一个连续错误。



您需要注意的一个区别是 gdb 您使用 print x 检查变量 x (缩写 px ),而在Lisp中,您只需键入 x 即可进行评估。



这里有一些简单的示例:



Step



这里提供有关可用命令的帮助;如果您口齿不清,请尝试 help :h

 > (defun阶乘(n)(if(zerop n)1(* n(阶乘(1- n))))))
FACTORIAL
> (步骤(因数3))
步骤1-> (要素3)
步骤1> ?

命令可以缩写,如第二列所示。
命令缩写说明
帮助:h,?打印此命令列表
错误:e打印最后一条错误消息
检查:i检查最后一个错误
中止:中止到下一个最近的输入循环
展开:uw中止至下一个最近的输入循环
重置:re在
本地绑定和理智的值
之间切换* PACKAGE *和* READTABLE *退出:q退出顶级输入循环
位置:w检查此框架
向上:u向上上升一帧,对其进行检查
顶部:t转到顶部框架,对其进行检查
向下:d向下下降一帧,对其进行检查
底部:b转到底部(最近)帧,检查它
模式模式:m设置Backtrace的堆栈模式:1 =所有堆栈元素
2 =所有帧3 =仅词法框架
4 =仅评估和应用框架(默认)5 =仅应用框架fr ames
帧限制n:fl设置Backtrace的帧限制。这样多的帧
最多将以回溯打印。
Backtrace [mode [limit]]:bt检查堆栈
Break +:br +设置EVAL帧中的断点
Break-:br-禁用EVAL帧中的断点
重做:rd re -在EVAL框架
中评估表单返回值:rt离开EVAL框架,规定返回值
步骤:s进入表单:以单步模式评估该表单
接下来:n在表单上进行评估:立即评估此表单
超过:o越过该级别:立即评估直到下一次返回
继续:c关闭单步模式,继续评估
-逐步进行直到:su,下一个直到:nu,直到直到:ou,继续直到:cu-
与上述相同,指定何时停止
的条件步骤1> :s
步骤2-> 3
步骤2> :n
步骤2 ==>价值:3
步骤2-> (IF(零N)1(* N(出厂编号)))
步骤2> :s
步骤3-> (零N)
步骤3> :n
步骤3 ==>值:NIL
步骤3-> (* N(因子(1- N)))
步骤3> :s
步骤4-> N
步骤4> :n
步骤4 ==>价值:3
步骤4-> (要素(1-N))
步骤4> :s
步骤5-> (1-N)
步骤5> :n
步骤5 ==>价值:2
步骤5-> (IF(零N)1(* N(出厂编号)))
步骤5> :c
步骤5 ==>值:2
步骤4 ==>值:2
步骤3 ==>值:6
步骤2 ==>值:6
步骤1 ==>值:6
6

请注意,步进器内的提示是步骤< level> ,其中 level 是嵌套级别。



中断



 > (defun assert-0(x)(除非(eql x 0)(break Bad x:〜S x))0)
ASSERT-0
> (assert-0 0)
0
> (assert-0'assert-0)

**-连续错误
错误x:ASSERT-0
如果继续操作(输入 continue):从BREAK返回循环
也可以使用以下重新启动:
ABORT:R1中止主循环
中断1> x
ASSERT-0
突破1> :c
0

此处提示为 Break< level> ;



声明



 > ; (defun my + 1(x)(断言(numberp x)(x)必须是数字:〜S x)(1+ x))
MY + 1
> (我的+1 5)
6
> (my + 1'my + 1)

**-连续错误
必须为数字:MY + 1
如果继续操作(输入 continue):输入
也可以使用以下重新启动:
ABORT:R1中止主循环
中断1> :c
新X> 'foo

**-连续错误
必须为数字:FOO
如果继续(通过键入 continue):输入X的新值。
还提供以下重新启动:
ABORT:R1中止主循环
中断1> :c
新X> 6
7

断言使用与 break 相同的提示。


I'm using CCL on Mac (1.8.1 -- the latest available at this writing), and wondering if there's any sort of debugging tutorial available.

The thing I'm particularly interested in is setting a breakpoint somewhere in my code, then poking & prodding various values, then stepping over the next line of code, checking more values, etc.

EDIT: I've read the debugging section of the CCL manual (18.3 and thereabouts), but can't quite make sense of it. I'm coming from a C/Java/etc. background and IDE-based source level debuggers, with just a little exposure to gdb.

So I guess what I'm looking for is an introduction/tutorial that walks me through a few of the simpler steps.

(I'm new to Lisp (and CCL, of course) so, if I'm asking completely the wrong question or going about things completely the wrong way, feel free to let me know.)

Thanks!

解决方案

I am sure a CCL user might point you to the Debugging section in the CCL manual, but, in fact, the ANSI Common Lisp standard includes excellent debugging facilities, including break and step you asked about (except for step's granularity is not based on a line of code but rather a form).

In fact, the whole Condition System is worth examining.

There are a few tutorials too.

The most important thing to remember that the debugging tools give you the normal Lisp REPL (Read-Eval-Print Loop) where you can do just about anything you can do with the initial REPL: define functions and variables, examine the existing variable (including those defined in the functions in which the debugger was entered) et al. Additionally, you might be able to issue additional commands, like step and next (often abbreviated :s and :n) in the stepper or continue (often abbreviated :c) in a continuable error.

One difference you need to watch for is that in gdb you examine a variable x using print x (abbreviated p x) while in Lisp you just type x and it is evaluated.

Here are some simple examples:

Step

Here ? gives help on available commands; try help or :h if your lisp barfs.

> (defun factorial (n) (if (zerop n) 1 (* n (factorial (1- n)))))
FACTORIAL
> (step (factorial 3))
step 1 --> (FACTORIAL 3)
Step 1 > ?

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
Step           :s       step into form: evaluate this form in single step mode
Next           :n       step over form: evaluate this form at once
Over           :o       step over this level: evaluate at once up to the next return
Continue       :c       switch off single step mode, continue evaluation
-- Step-until :su, Next-until :nu, Over-until :ou, Continue-until :cu --
           same as above, specify a condition when to stop
Step 1 > :s
step 2 --> 3
Step 2 > :n
step 2 ==> value: 3
step 2 --> (IF (ZEROP N) 1 (* N (FACTORIAL #)))
Step 2 > :s
step 3 --> (ZEROP N)
Step 3 > :n
step 3 ==> value: NIL
step 3 --> (* N (FACTORIAL (1- N)))
Step 3 > :s
step 4 --> N
Step 4 > :n
step 4 ==> value: 3
step 4 --> (FACTORIAL (1- N))
Step 4 > :s
step 5 --> (1- N)
Step 5 > :n
step 5 ==> value: 2
step 5 --> (IF (ZEROP N) 1 (* N (FACTORIAL #)))
Step 5 > :c
step 5 ==> value: 2
step 4 ==> value: 2
step 3 ==> value: 6
step 2 ==> value: 6
step 1 ==> value: 6
6

Note that the prompt inside the stepper is step <level> where level is the nesting level.

Break

> (defun assert-0 (x) (unless (eql x 0) (break "Bad x: ~S" x)) 0)
ASSERT-0
> (assert-0 0)
0
> (assert-0 'assert-0)

** - Continuable Error
Bad x: ASSERT-0
If you continue (by typing 'continue'): Return from BREAK loop
The following restarts are also available:
ABORT          :R1      Abort main loop
Break 1 > x
ASSERT-0
Break 1 > :c
0

Here the prompt is Break <level>.

Assert

> (defun my+1 (x) (assert (numberp x) (x) "must be a number: ~S" x) (1+ x))
MY+1
> (my+1 5)
6
> (my+1 'my+1)

** - Continuable Error
must be a number: MY+1
If you continue (by typing 'continue'): Input a new value for X.
The following restarts are also available:
ABORT          :R1      Abort main loop
Break 1 > :c
New X> 'foo

** - Continuable Error
must be a number: FOO
If you continue (by typing 'continue'): Input a new value for X.
The following restarts are also available:
ABORT          :R1      Abort main loop
Break 1 > :c
New X> 6
7

assert uses the same prompt as break.

这篇关于如何在[Clozure] Common Lisp中进行调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆