gpt4 book ai didi

debugging - 如何在 [Clozure] Common Lisp 中调试?

转载 作者:行者123 更新时间:2023-12-02 10:21:32 25 4
gpt4 key购买 nike

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

我特别感兴趣的是在代码中的某个位置设置断点,然后戳戳和刺探各种值,然后单步执行下一行代码,检查更多值等。

编辑:我已经阅读了 CCL 手册的调试部分(18.3 及相关内容),但不太明白它的意义。我来自 C/Java/等。后台和基于 IDE 的源代码级调试器,只需接触一点 gdb。

所以我想我正在寻找的是一个介绍/教程,引导我完成一些更简单的步骤。

(我是 Lisp(当然还有 CCL)新手,所以,如果我问了完全错误的问题或以完全错误的方式处理事情,请随时告诉我。)

谢谢!

最佳答案

我确信 CCL​​ 用户可能会将您指向 Debugging section in the CCL manual ,但事实上,ANSI Common Lisp 标准包含出色的调试工具,包括 break step 您询问过(除了 step 的粒度不是基于一行代码而是基于表单)。

事实上,整个Condition System值得研究。

有一个few tutorials也是。

要记住的最重要的一点是,调试工具为您提供了正常的 Lisp REPL(读取-求值-打印循环),您可以在其中执行初始 REPL 可以执行的任何操作:定义函数和变量、检查现有的变量(包括在进入调试器的函数中定义的变量)等。 此外,您也许可以发出其他命令,例如 stepnext (通常缩写为 :s:n )在步进器中或 continue (通常缩写为 :c )出现持续错误。

您需要注意的一个区别是gdb你检查一个变量x使用print x (缩写 p x )而在 Lisp 中,您只需输入 x并对其进行评估。

以下是一些简单的示例:

步骤

这里?提供有关可用命令的帮助;尝试help:h如果你的 lisp 呕吐了。

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

请注意,步进器内部的提示符为 step <level>哪里level是嵌套级别。

中断

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

这里的提示是Break <level> .

断言

> (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使用与 break 相同的提示.

关于debugging - 如何在 [Clozure] Common Lisp 中调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18093309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com