[英]difference between continue and quit in Emacs Lisp debugger
(progn
(print 11)
(/ 1 0)
(print 22)
(/ 2 0)
(print 33))
When I press CMx on that expression, Emacs invokes debugger when it fails at (/ 1 0). 当我在该表达式上按CMx时,Emacs在(/ 1 0)失败时调用调试器。 When I press c for continue instead of q for quit, debugger still exits without executing (print 22) or (/ 2 0). 当我按c继续而不是q退出时,调试器仍然退出而不执行(打印22)或(/ 2 0)。 The only difference here is that c exits with the message 唯一的区别是c随消息退出
progn: Arithmetic error
What is an example code where c and q make big difference and when should I type c rather than q? c和q的区别很大,什么时候应该键入c而不是q的示例代码是什么?
可以在不停止执行的任何代码中显示差异,即不包含错误(例如,在debug
调用时)。
The difference is easiest to see when you use debug-on-signal
. 使用debug-on-signal
时最容易看到区别。 With this setting, the debugger gets called when an error is signalled, even if that error is handled by an enclosing condition-case
. 使用此设置,即使发出了错误信号,即使由封闭的condition-case
处理该错误,调试器也会被调用。 In such a situation c
will continue the normal execution (ie signal the error, which in turn causes the handler code to be run, which may then continue execution normally). 在这种情况下, c
将继续正常执行(即发出错误信号,进而导致处理程序代码运行,然后可以继续正常执行)。
At first it seemed to me like a very obvious question, but after trying to build an example, I actually had to look in the info
. 最初,在我看来,这是一个非常明显的问题,但是在尝试构建示例之后,我实际上不得不查看info
。 So let me summarize what I've clarified for myself: 因此,让我总结一下我为自己澄清的内容:
c in edebug
is not the same as c in gdb
. 下在edebug
是不一样为c在gdb
。 This one just stops for one second at each breakpoint and eventually quits. 这个只是在每个断点处停止一秒钟,然后最终退出。 I don't see at the moment how it can be useful to anyone. 目前,我还没有看到它对任何人都有用。 The equivalent is instead g : this one will continue until next breakpoint and stop there. 等效的是g :该值将继续到下一个断点并在此停止。
Here's a code example: 这是一个代码示例:
(defun foo ()
(setq x (loop for i from 1 to 100
collecting (* i i)))
(setq y (nth 5 x))
(incf y))
(foo)
To edebug
it: 要edebug
:
*scratch*
将此代码粘贴到*scratch*
foo
and Cu CMx (calls edebug-defun
) 在foo
和Cu CMx内部移动点(调用edebug-defun
) y
in setq y
and Mx edebug-set-breakpoint 在setq y
和Mx edebug-set-breakpoint中将点移动到y
(foo)
and Cj 将点移到(foo)
和Cj中的结束括号 edebug
. 您现在在edebug
。 Here you could do step 3 with the shortcut b instead of Mx ... 在这里,您可以使用快捷键b而不是Mx来执行步骤3 。 Another difference is with respect to recursive edit. 另一个区别在于递归编辑。 For example, I could invoke query-replace and then enter recursive edit and then type (/ 1 0)
and evaluate it to enter debugger. 例如,我可以调用query-replace,然后输入递归编辑,然后键入(/ 1 0)
并对其求值以进入调试器。 Now if I press q, we are back to top level and no longer running query-replace. 现在,如果按q,我们将返回顶层,并且不再运行查询替换。 But if I press c instead, I am still inside recursive edit. 但是,如果我改按c,则我仍在递归编辑中。
Update another difference. 更新另一个差异。 While in debugger, c
is bound to debugger-continue
which is a wrapper around exit-recursive-edit
and q
is bound to top-level
. 在调试器中, c
绑定到debugger-continue
,后者是exit-recursive-edit
的包装,而q
绑定到top-level
。 That means any difference known about exit-recursive-edit
vs top-level
applies. 这意味着适用于已知的exit-recursive-edit
和top-level
区别。 See Recursive Edit - Emacs Manual for difference. 有关差异,请参见递归编辑-Emacs手册 。
Here's an example adapted from an example in Recursive Editing - Emacs Lisp Manual to test differences. 这是从“ 递归编辑-Emacs Lisp手册”中的示例改编来测试差异的示例。
(defun simple-rec ()
(forward-word 1)
(message "111")
(debug)
(message "222")
(forward-word 1))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.