Emacs提供了大量调试工具,包括M-x toggle-debug-on-error
,,M-x toggle-debug-on-quit
信号调试(可以USR2
从外部发送到Emacs 来使用),debug-on-entry
(功能的)调试,debug-on-message
(当看到消息的特定正则表达式匹配时),以及最终将debug
其自身替代用C-u C-M-x
。
双方debug
并edebug
提供足够的功能来检查状态评估代码,您有兴趣,命中时的Emacs e
和输入表达式。
但是,虽然edebug
跳转到已检测功能中的位置并因此为您提供了寻找位置的线索(这很愚蠢,因为您已经确切地了解了所检测的内容),debug
却根本不这样做。在发现每当debug
评估一个缓冲区时,它都会发出与错误关联的point的值,因此,我进行了一个较小的讨论。换句话说,在缓冲区上使用此信息可以为您提供回溯中的行号!
(with-eval-after-load 'debug
(defun debugger-setup-buffer (debugger-args)
"Initialize the `*Backtrace*' buffer for entry to the debugger.
That buffer should be current already."
(setq buffer-read-only nil)
(erase-buffer)
(set-buffer-multibyte t) ;Why was it nil ? -stef
(setq buffer-undo-list t)
(let ((standard-output (current-buffer))
(print-escape-newlines t)
(print-level 8)
(print-length 50))
(backtrace))
(goto-char (point-min))
(delete-region (point)
(progn
(search-forward "\n debug(")
(forward-line (if (eq (car debugger-args) 'debug)
2 ; Remove implement-debug-on-entry frame.
1))
(point)))
(insert "Debugger entered")
;; lambda is for debug-on-call when a function call is next.
;; debug is for debug-on-entry function called.
(pcase (car debugger-args)
((or `lambda `debug)
(insert "--entering a function:\n"))
;; Exiting a function.
(`exit
(insert "--returning value: ")
(setq debugger-value (nth 1 debugger-args))
(prin1 debugger-value (current-buffer))
(insert ?\n)
(delete-char 1)
(insert ? )
(beginning-of-line))
;; Debugger entered for an error.
(`error
(insert "--Lisp error: ")
(prin1 (nth 1 debugger-args) (current-buffer))
(insert ?\n))
;; debug-on-call, when the next thing is an eval.
(`t
(insert "--beginning evaluation of function call form:\n"))
;; User calls debug directly.
(_
(insert ": ")
(prin1 (if (eq (car debugger-args) 'nil)
(cdr debugger-args) debugger-args)
(current-buffer))
(insert ?\n)))
;; After any frame that uses eval-buffer,
;; insert a line that states the buffer position it's reading at.
(save-excursion
(let ((tem eval-buffer-list))
(while (and tem
(re-search-forward "^ eval-\\(buffer\\|region\\)(" nil t))
(beginning-of-line)
(insert (format "Error at line %d in %s: "
(with-current-buffer (car tem)
(line-number-at-pos (point)))
(with-current-buffer (car tem)
(buffer-name))))
(pop tem))))
(debugger-make-xrefs)))
这样就可以回答标题中的原始问题。至于您首先遇到回溯的问题,我没有有用的想法。
nil
debug-on-error
?那没有帮助吗?