diff options
| author | Lars Ingebrigtsen | 2022-05-01 13:40:13 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-05-01 13:40:13 +0200 |
| commit | 7c8bec9e1ffe087918f6f218fc4560fc968aebb2 (patch) | |
| tree | 2546ec6c38b293890826a0b93e2f66a2ea8f7e2f | |
| parent | 81ce4b0e4ee18520f174cc5b46219e4475fcc956 (diff) | |
| download | emacs-7c8bec9e1ffe087918f6f218fc4560fc968aebb2.tar.gz emacs-7c8bec9e1ffe087918f6f218fc4560fc968aebb2.zip | |
Don't enter the debugger from *Backtrace* or edebug on eval errors
* doc/lispref/debugging.texi (Error Debugging): Document it.
* doc/lispref/edebug.texi (Edebug Eval): Mention it.
* lisp/emacs-lisp/debug.el (debug-allow-recursive-debug): New user
option (bug#36145).
(debugger-eval-expression): Use it.
* lisp/emacs-lisp/edebug.el (edebug-eval-expression): Ditto.
This patch is based on a patch by Noam Postavsky.
| -rw-r--r-- | doc/lispref/debugging.texi | 18 | ||||
| -rw-r--r-- | doc/lispref/edebug.texi | 8 | ||||
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | lisp/emacs-lisp/debug.el | 13 | ||||
| -rw-r--r-- | lisp/emacs-lisp/edebug.el | 5 |
5 files changed, 47 insertions, 5 deletions
diff --git a/doc/lispref/debugging.texi b/doc/lispref/debugging.texi index c258a9adc0e..058c9319544 100644 --- a/doc/lispref/debugging.texi +++ b/doc/lispref/debugging.texi | |||
| @@ -196,6 +196,17 @@ echo area. For example, this can be useful when trying to find the | |||
| 196 | cause of a particular message. | 196 | cause of a particular message. |
| 197 | @end defvar | 197 | @end defvar |
| 198 | 198 | ||
| 199 | @defvar debug-allow-recursive-debug | ||
| 200 | You can evaluate forms in the current stack frame in the | ||
| 201 | @samp{*Backtrace*} buffer with the @key{e} command, and while | ||
| 202 | edebugging you can use the @key{e} and @key{C-x C-e} commands to do | ||
| 203 | something similar. By default, the debugger is inhibited by these | ||
| 204 | commands (because (re-)entering the debugger at this point will | ||
| 205 | usually take you out of the debugging context you're in). Set | ||
| 206 | @code{debug-allow-recursive-debug} to a non-@code{nil} value to allow | ||
| 207 | these commands to enter the debugger recursively. | ||
| 208 | @end defvar | ||
| 209 | |||
| 199 | To debug an error that happens during loading of the init | 210 | To debug an error that happens during loading of the init |
| 200 | file, use the option @samp{--debug-init}. This binds | 211 | file, use the option @samp{--debug-init}. This binds |
| 201 | @code{debug-on-error} to @code{t} while loading the init file, and | 212 | @code{debug-on-error} to @code{t} while loading the init file, and |
| @@ -520,6 +531,7 @@ Flag the current frame like @kbd{b}. Then continue execution like | |||
| 520 | @kbd{c}, but temporarily disable break-on-entry for all functions that | 531 | @kbd{c}, but temporarily disable break-on-entry for all functions that |
| 521 | are set up to do so by @code{debug-on-entry}. | 532 | are set up to do so by @code{debug-on-entry}. |
| 522 | 533 | ||
| 534 | @vindex debug-allow-recursive-debug | ||
| 523 | @item e | 535 | @item e |
| 524 | Read a Lisp expression in the minibuffer, evaluate it (with the | 536 | Read a Lisp expression in the minibuffer, evaluate it (with the |
| 525 | relevant lexical environment, if applicable), and print the | 537 | relevant lexical environment, if applicable), and print the |
| @@ -528,7 +540,11 @@ variables, and the current buffer, as part of its operation; @kbd{e} | |||
| 528 | temporarily restores their values from outside the debugger, so you can | 540 | temporarily restores their values from outside the debugger, so you can |
| 529 | examine and change them. This makes the debugger more transparent. By | 541 | examine and change them. This makes the debugger more transparent. By |
| 530 | contrast, @kbd{M-:} does nothing special in the debugger; it shows you | 542 | contrast, @kbd{M-:} does nothing special in the debugger; it shows you |
| 531 | the variable values within the debugger. | 543 | the variable values within the debugger. By default, this command |
| 544 | suppresses the debugger during evaluation, so that an error in the | ||
| 545 | evaluated expression won't add a new error on top of the existing one. | ||
| 546 | Set the @code{debug-allow-recursive-debug} user option to a | ||
| 547 | non-@code{nil} value to override this. | ||
| 532 | 548 | ||
| 533 | @item R | 549 | @item R |
| 534 | Like @kbd{e}, but also save the result of evaluation in the | 550 | Like @kbd{e}, but also save the result of evaluation in the |
diff --git a/doc/lispref/edebug.texi b/doc/lispref/edebug.texi index eff9621628e..0fc5271d5ad 100644 --- a/doc/lispref/edebug.texi +++ b/doc/lispref/edebug.texi | |||
| @@ -700,8 +700,12 @@ on this process. | |||
| 700 | @table @kbd | 700 | @table @kbd |
| 701 | @item e @var{exp} @key{RET} | 701 | @item e @var{exp} @key{RET} |
| 702 | Evaluate expression @var{exp} in the context outside of Edebug | 702 | Evaluate expression @var{exp} in the context outside of Edebug |
| 703 | (@code{edebug-eval-expression}). That is, Edebug tries to minimize its | 703 | (@code{edebug-eval-expression}). That is, Edebug tries to minimize |
| 704 | interference with the evaluation. | 704 | its interference with the evaluation. By default, this command |
| 705 | suppresses the debugger during evaluation, so that an error in the | ||
| 706 | evaluated expression won't add a new error on top of the existing one. | ||
| 707 | Set the @code{debug-allow-recursive-debug} user option to a | ||
| 708 | non-@code{nil} value to override this. | ||
| 705 | 709 | ||
| 706 | @item M-: @var{exp} @key{RET} | 710 | @item M-: @var{exp} @key{RET} |
| 707 | Evaluate expression @var{exp} in the context of Edebug itself | 711 | Evaluate expression @var{exp} in the context of Edebug itself |
| @@ -686,6 +686,14 @@ script that was used in ancient South Asia. A new input method, | |||
| 686 | 686 | ||
| 687 | * Changes in Specialized Modes and Packages in Emacs 29.1 | 687 | * Changes in Specialized Modes and Packages in Emacs 29.1 |
| 688 | 688 | ||
| 689 | ** Debugging | ||
| 690 | |||
| 691 | *** New user option 'debug-allow-recursive-debug'. | ||
| 692 | This user option controls whether the 'e' (in a *Backtrace* | ||
| 693 | buffer or while edebugging) and 'C-x C-e' (while edebugging) commands | ||
| 694 | lead to a (further) backtrace. By default, this variable is nil, | ||
| 695 | which is a change in behaviour from previous Emacs versions. | ||
| 696 | |||
| 689 | ** Compile | 697 | ** Compile |
| 690 | 698 | ||
| 691 | +++ | 699 | +++ |
diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el index 46b0306d64f..91e9b0716d0 100644 --- a/lisp/emacs-lisp/debug.el +++ b/lisp/emacs-lisp/debug.el | |||
| @@ -90,6 +90,11 @@ The value used here is passed to `quit-restore-window'." | |||
| 90 | :group 'debugger | 90 | :group 'debugger |
| 91 | :version "24.3") | 91 | :version "24.3") |
| 92 | 92 | ||
| 93 | (defcustom debug-allow-recursive-debug nil | ||
| 94 | "If non-nil, erroring in debug and edebug won't recursively debug." | ||
| 95 | :type 'boolean | ||
| 96 | :version "29.1") | ||
| 97 | |||
| 93 | (defvar debugger-step-after-exit nil | 98 | (defvar debugger-step-after-exit nil |
| 94 | "Non-nil means \"single-step\" after the debugger exits.") | 99 | "Non-nil means \"single-step\" after the debugger exits.") |
| 95 | 100 | ||
| @@ -534,7 +539,13 @@ The environment used is the one when entering the activation frame at point." | |||
| 534 | (error 0)))) ;; If on first line. | 539 | (error 0)))) ;; If on first line. |
| 535 | (base (debugger--backtrace-base))) | 540 | (base (debugger--backtrace-base))) |
| 536 | (debugger-env-macro | 541 | (debugger-env-macro |
| 537 | (let ((val (backtrace-eval exp nframe base))) | 542 | (let ((val (if debug-allow-recursive-debug |
| 543 | (backtrace-eval exp nframe base) | ||
| 544 | (condition-case err | ||
| 545 | (backtrace-eval exp nframe base) | ||
| 546 | (error (format "%s: %s" | ||
| 547 | (get (car err) 'error-message) | ||
| 548 | (car (cdr err)))))))) | ||
| 538 | (prog1 | 549 | (prog1 |
| 539 | (debugger--print val t) | 550 | (debugger--print val t) |
| 540 | (let ((str (eval-expression-print-format val))) | 551 | (let ((str (eval-expression-print-format val))) |
diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index 722283b88ff..85545f9f351 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el | |||
| @@ -57,6 +57,7 @@ | |||
| 57 | (require 'cl-lib) | 57 | (require 'cl-lib) |
| 58 | (require 'seq) | 58 | (require 'seq) |
| 59 | (eval-when-compile (require 'pcase)) | 59 | (eval-when-compile (require 'pcase)) |
| 60 | (require 'debug) | ||
| 60 | 61 | ||
| 61 | ;;; Options | 62 | ;;; Options |
| 62 | 63 | ||
| @@ -3713,7 +3714,9 @@ Print result in minibuffer." | |||
| 3713 | (interactive (list (read--expression "Eval: "))) | 3714 | (interactive (list (read--expression "Eval: "))) |
| 3714 | (princ | 3715 | (princ |
| 3715 | (edebug-outside-excursion | 3716 | (edebug-outside-excursion |
| 3716 | (let ((result (edebug-eval expr))) | 3717 | (let ((result (if debug-allow-recursive-debug |
| 3718 | (edebug-eval expr) | ||
| 3719 | (edebug-safe-eval expr)))) | ||
| 3717 | (values--store-value result) | 3720 | (values--store-value result) |
| 3718 | (concat (edebug-safe-prin1-to-string result) | 3721 | (concat (edebug-safe-prin1-to-string result) |
| 3719 | (eval-expression-print-format result)))))) | 3722 | (eval-expression-print-format result)))))) |