diff options
| author | Gemini Lasswell | 2018-06-19 07:27:41 -0700 |
|---|---|---|
| committer | Gemini Lasswell | 2018-08-03 08:53:02 -0700 |
| commit | e09120d68694272ea5efbe13b16936b4382389d8 (patch) | |
| tree | 99f072a54e22202ee74969370722564a519e27a7 /doc | |
| parent | 8a7620955b4d859caecd9a5dc9f2a986baf994fd (diff) | |
| download | emacs-e09120d68694272ea5efbe13b16936b4382389d8.tar.gz emacs-e09120d68694272ea5efbe13b16936b4382389d8.zip | |
Add backtrace-mode and use it in the debugger, ERT and Edebug
* doc/lispref/debugging.texi (Using Debugger): Remove explanation of
backtrace buffer. Refer to new node.
(Backtraces): New node.
(Debugger Commands): Refer to new node. Remove 'v'.
* doc/lispref/edebug.texi (Edebug Misc): Refer to new node.
* doc/misc/ert.texi (Running Tests Interactively): Refer to new node.
* lisp/emacs-lisp-backtrace.el: New file.
* test/lisp/emacs-lisp/backtrace-tests.el: New file.
* lisp/emacs-lisp/debug.el: (debugger-buffer-state): New cl-defstruct.
(debugger--restore-buffer-state): New function.
(debug): Use a debugger-buffer-state object to save and restore buffer
state. Fix bug#15749 by leaving an unused buffer in debugger-mode,
empty, instead of in fundamental-mode, and then when reusing a buffer,
not calling debugger-mode if the buffer is already in debugger-mode.
(debugger-insert-backtrace): Remove.
(debugger-setup-buffer): Use backtrace-mode.
(debugger--insert-header): New function.
(debugger-continue, debugger-return-value): Change check for flags to
use backtrace-frames.
(debugger-frame-number): Determine backtrace frame number from
backtrace-frames.
(debugger--locals-visible-p, debugger--insert-locals)
(debugger--show-locals, debugger--hide-locals)
(debugger-toggle-locals): Remove.
(debugger-mode-map): Make a child of backtrace-mode-map. Move
navigation commands to backtrace-mode-map. Bind 'q' to debugger-quit
instead of top-level. Make Help Follow menu item call
backtrace-help-follow-symbol.
(debugger-mode): Derive from backtrace-mode.
(debug-help-follow): Remove. Move body of this function to
'backtrace-help-follow-symbol' in backtrace.el.
(debugger-quit): New function.
* lisp/emacs-lisp/edebug.el (edebug-unwrap-results): Remove warning
in docstring about circular results.
(edebug-unwrap): Use pcase.
(edebug-unwrap1): New function to unwrap circular objects.
(edebug-unwrap*): Use it.
(edebug--frame): New cl-defstruct.
(edebug-backtrace): Call the buffer *Edebug Backtrace* and use
backtrace-mode. Get the frames from edebug--backtrace-frames.
(edebug--backtrace-frames, edebug--unwrap-and-add-info)
(edebug--symbol-not-prefixed-p): New functions.
* lisp/emacs-lisp/lisp-mode.el
(lisp-el-font-lock-keywords-for-backtraces)
(lisp-el-font-lock-keywords-for-backtraces-1)
(lisp-el-font-lock-keywords-for-backtraces-2): New constants.
* lisp/emacs-lisp/ert.el (ert--print-backtrace): Remove.
(ert--run-test-debugger): Use backtrace-get-frames.
(ert-run-tests-batch): Use backtrace-to-string.
(ert-results-pop-to-backtrace-for-test-at-point): Use backtrace-mode.
(ert--insert-backtrace-header): New function.
* tests/lisp/emacs-lisp/ert-tests.el (ert-test--which-file):
Use backtrace-frame slot accessor.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/debugging.texi | 93 | ||||
| -rw-r--r-- | doc/lispref/edebug.texi | 4 | ||||
| -rw-r--r-- | doc/misc/ert.texi | 8 |
3 files changed, 79 insertions, 26 deletions
diff --git a/doc/lispref/debugging.texi b/doc/lispref/debugging.texi index 1b1f87465db..b5a73a255af 100644 --- a/doc/lispref/debugging.texi +++ b/doc/lispref/debugging.texi | |||
| @@ -81,7 +81,8 @@ debugger recursively. @xref{Recursive Editing}. | |||
| 81 | * Function Debugging:: Entering it when a certain function is called. | 81 | * Function Debugging:: Entering it when a certain function is called. |
| 82 | * Variable Debugging:: Entering it when a variable is modified. | 82 | * Variable Debugging:: Entering it when a variable is modified. |
| 83 | * Explicit Debug:: Entering it at a certain point in the program. | 83 | * Explicit Debug:: Entering it at a certain point in the program. |
| 84 | * Using Debugger:: What the debugger does; what you see while in it. | 84 | * Using Debugger:: What the debugger does. |
| 85 | * Backtraces:: What you see while in the debugger. | ||
| 85 | * Debugger Commands:: Commands used while in the debugger. | 86 | * Debugger Commands:: Commands used while in the debugger. |
| 86 | * Invoking the Debugger:: How to call the function @code{debug}. | 87 | * Invoking the Debugger:: How to call the function @code{debug}. |
| 87 | * Internals of Debugger:: Subroutines of the debugger, and global variables. | 88 | * Internals of Debugger:: Subroutines of the debugger, and global variables. |
| @@ -392,32 +393,79 @@ this is not what you want, you can either set | |||
| 392 | @code{eval-expression-debug-on-error} to @code{nil}, or set | 393 | @code{eval-expression-debug-on-error} to @code{nil}, or set |
| 393 | @code{debug-on-error} to @code{nil} in @code{debugger-mode-hook}. | 394 | @code{debug-on-error} to @code{nil} in @code{debugger-mode-hook}. |
| 394 | 395 | ||
| 396 | The debugger itself must be run byte-compiled, since it makes | ||
| 397 | assumptions about the state of the Lisp interpreter. These | ||
| 398 | assumptions are false if the debugger is running interpreted. | ||
| 399 | |||
| 400 | @node Backtraces | ||
| 401 | @subsection Backtraces | ||
| 402 | @cindex backtrace buffer | ||
| 403 | |||
| 404 | Debugger mode is derived from Backtrace mode, which is also used to | ||
| 405 | show backtraces by Edebug and ERT. (@pxref{Edebug} and @ref{Top,the | ||
| 406 | ERT manual,, ert, ERT: Emacs Lisp Regression Testing}) | ||
| 407 | |||
| 408 | @cindex stack frame | ||
| 409 | The backtrace buffer shows you the functions that are executing and | ||
| 410 | their argument values. When a backtrace buffer is created, it shows | ||
| 411 | each stack frame on one, possibly very long, line. (A stack frame is | ||
| 412 | the place where the Lisp interpreter records information about a | ||
| 413 | particular invocation of a function.) The most recently called | ||
| 414 | function will be at the top. | ||
| 415 | |||
| 395 | @cindex current stack frame | 416 | @cindex current stack frame |
| 396 | The backtrace buffer shows you the functions that are executing and | 417 | In a backtrace you can specify a stack frame by moving point to a line |
| 397 | their argument values. It also allows you to specify a stack frame by | 418 | describing that frame. The frame whose line point is on is considered |
| 398 | moving point to the line describing that frame. (A stack frame is the | 419 | the @dfn{current frame}. |
| 399 | place where the Lisp interpreter records information about a particular | 420 | |
| 400 | invocation of a function.) The frame whose line point is on is | 421 | If a function name is underlined, that means Emacs knows where its |
| 401 | considered the @dfn{current frame}. Some of the debugger commands | 422 | source code is located. You can click with the mouse on that name, or |
| 402 | operate on the current frame. If a line starts with a star, that means | 423 | move to it and type @key{RET}, to visit the source code. You can also |
| 403 | that exiting that frame will call the debugger again. This is useful | 424 | type @key{RET} while point is on any name of a function or variable |
| 404 | for examining the return value of a function. | 425 | which is not underlined, to see help information for that symbol in a |
| 405 | 426 | help buffer, if any exists. The @code{xref-find-definitions} command, | |
| 406 | If a function name is underlined, that means the debugger knows | 427 | bound to @key{M-.}, can also be used on any identifier in a backtrace |
| 407 | where its source code is located. You can click with the mouse on | 428 | (@pxref{Looking Up Identifiers,,,emacs,Emacs manual}). |
| 408 | that name, or move to it and type @key{RET}, to visit the source code. | 429 | |
| 430 | In backtraces, the tails of long lists and the ends of long strings, | ||
| 431 | vectors or structures, as well as objects which are deeply nested, | ||
| 432 | will be printed as underlined ``...''. You can click with the mouse | ||
| 433 | on a ``...'', or type @key{RET} while point is on it, to show the part | ||
| 434 | of the object that was hidden. To control how much abbreviation is | ||
| 435 | done, customize @code{backtrace-line-length}. | ||
| 436 | |||
| 437 | Here is a list of commands for navigating and viewing backtraces: | ||
| 409 | 438 | ||
| 410 | The debugger itself must be run byte-compiled, since it makes | 439 | @table @kbd |
| 411 | assumptions about how many stack frames are used for the debugger | 440 | @item v |
| 412 | itself. These assumptions are false if the debugger is running | 441 | Toggle the display of local variables of the current stack frame. |
| 413 | interpreted. | 442 | |
| 443 | @item p | ||
| 444 | Move to the beginning of the frame, or to the beginning | ||
| 445 | of the previous frame. | ||
| 446 | |||
| 447 | @item n | ||
| 448 | Move to the beginning of the next frame. | ||
| 449 | |||
| 450 | @item + | ||
| 451 | Add line breaks and indentation to the top-level Lisp form at point to | ||
| 452 | make it more readable. | ||
| 453 | |||
| 454 | @item = | ||
| 455 | Collapse the top-level Lisp form at point back to a single line. | ||
| 456 | |||
| 457 | @item # | ||
| 458 | Toggle @code{print-circle} for the frame at point. | ||
| 459 | |||
| 460 | @end table | ||
| 414 | 461 | ||
| 415 | @node Debugger Commands | 462 | @node Debugger Commands |
| 416 | @subsection Debugger Commands | 463 | @subsection Debugger Commands |
| 417 | @cindex debugger command list | 464 | @cindex debugger command list |
| 418 | 465 | ||
| 419 | The debugger buffer (in Debugger mode) provides special commands in | 466 | The debugger buffer (in Debugger mode) provides special commands in |
| 420 | addition to the usual Emacs commands. The most important use of | 467 | addition to the usual Emacs commands and to the Backtrace mode commands |
| 468 | described in the previous section. The most important use of | ||
| 421 | debugger commands is for stepping through code, so that you can see | 469 | debugger commands is for stepping through code, so that you can see |
| 422 | how control flows. The debugger can step through the control | 470 | how control flows. The debugger can step through the control |
| 423 | structures of an interpreted function, but cannot do so in a | 471 | structures of an interpreted function, but cannot do so in a |
| @@ -427,6 +475,11 @@ the same function. (To do this, visit the source for the function and | |||
| 427 | type @kbd{C-M-x} on its definition.) You cannot use the Lisp debugger | 475 | type @kbd{C-M-x} on its definition.) You cannot use the Lisp debugger |
| 428 | to step through a primitive function. | 476 | to step through a primitive function. |
| 429 | 477 | ||
| 478 | Some of the debugger commands operate on the current frame. If a | ||
| 479 | frame starts with a star, that means that exiting that frame will call the | ||
| 480 | debugger again. This is useful for examining the return value of a | ||
| 481 | function. | ||
| 482 | |||
| 430 | @c FIXME: Add @findex for the following commands? --xfq | 483 | @c FIXME: Add @findex for the following commands? --xfq |
| 431 | Here is a list of Debugger mode commands: | 484 | Here is a list of Debugger mode commands: |
| 432 | 485 | ||
| @@ -502,8 +555,6 @@ Display a list of functions that will invoke the debugger when called. | |||
| 502 | This is a list of functions that are set to break on entry by means of | 555 | This is a list of functions that are set to break on entry by means of |
| 503 | @code{debug-on-entry}. | 556 | @code{debug-on-entry}. |
| 504 | 557 | ||
| 505 | @item v | ||
| 506 | Toggle the display of local variables of the current stack frame. | ||
| 507 | @end table | 558 | @end table |
| 508 | 559 | ||
| 509 | @node Invoking the Debugger | 560 | @node Invoking the Debugger |
diff --git a/doc/lispref/edebug.texi b/doc/lispref/edebug.texi index b9cc1d5afc2..0e0a2e8a643 100644 --- a/doc/lispref/edebug.texi +++ b/doc/lispref/edebug.texi | |||
| @@ -442,8 +442,8 @@ Redisplay the most recently known expression result in the echo area | |||
| 442 | Display a backtrace, excluding Edebug's own functions for clarity | 442 | Display a backtrace, excluding Edebug's own functions for clarity |
| 443 | (@code{edebug-backtrace}). | 443 | (@code{edebug-backtrace}). |
| 444 | 444 | ||
| 445 | You cannot use debugger commands in the backtrace buffer in Edebug as | 445 | @xref{Debugging,, Backtraces, elisp}, for the commands which work |
| 446 | you would in the standard debugger. | 446 | in a backtrace buffer. |
| 447 | 447 | ||
| 448 | The backtrace buffer is killed automatically when you continue | 448 | The backtrace buffer is killed automatically when you continue |
| 449 | execution. | 449 | execution. |
diff --git a/doc/misc/ert.texi b/doc/misc/ert.texi index 82e0e27ed1c..e2aeeb1353a 100644 --- a/doc/misc/ert.texi +++ b/doc/misc/ert.texi | |||
| @@ -273,9 +273,11 @@ moving point to it and typing @kbd{@key{RET}} jumps to its definition. | |||
| 273 | @cindex backtrace of a failed test | 273 | @cindex backtrace of a failed test |
| 274 | Pressing @kbd{r} re-runs the test near point on its own. Pressing | 274 | Pressing @kbd{r} re-runs the test near point on its own. Pressing |
| 275 | @kbd{d} re-runs it with the debugger enabled. @kbd{.} jumps to the | 275 | @kbd{d} re-runs it with the debugger enabled. @kbd{.} jumps to the |
| 276 | definition of the test near point (@kbd{@key{RET}} has the same effect if | 276 | definition of the test near point (@kbd{@key{RET}} has the same effect |
| 277 | point is on the name of the test). On a failed test, @kbd{b} shows | 277 | if point is on the name of the test). On a failed test, @kbd{b} shows |
| 278 | the backtrace of the failure. | 278 | the backtrace of the failure. @xref{Debugging,, Backtraces, elisp, |
| 279 | the Emacs Lisp Reference Manual}, for more information about | ||
| 280 | backtraces. | ||
| 279 | 281 | ||
| 280 | @kindex l@r{, in ert results buffer} | 282 | @kindex l@r{, in ert results buffer} |
| 281 | @kbd{l} shows the list of @code{should} forms executed in the test. | 283 | @kbd{l} shows the list of @code{should} forms executed in the test. |