aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorGemini Lasswell2018-06-19 07:27:41 -0700
committerGemini Lasswell2018-08-03 08:53:02 -0700
commite09120d68694272ea5efbe13b16936b4382389d8 (patch)
tree99f072a54e22202ee74969370722564a519e27a7 /doc
parent8a7620955b4d859caecd9a5dc9f2a986baf994fd (diff)
downloademacs-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.texi93
-rw-r--r--doc/lispref/edebug.texi4
-rw-r--r--doc/misc/ert.texi8
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
397assumptions about the state of the Lisp interpreter. These
398assumptions are false if the debugger is running interpreted.
399
400@node Backtraces
401@subsection Backtraces
402@cindex backtrace buffer
403
404Debugger mode is derived from Backtrace mode, which is also used to
405show backtraces by Edebug and ERT. (@pxref{Edebug} and @ref{Top,the
406ERT manual,, ert, ERT: Emacs Lisp Regression Testing})
407
408@cindex stack frame
409The backtrace buffer shows you the functions that are executing and
410their argument values. When a backtrace buffer is created, it shows
411each stack frame on one, possibly very long, line. (A stack frame is
412the place where the Lisp interpreter records information about a
413particular invocation of a function.) The most recently called
414function 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 417In a backtrace you can specify a stack frame by moving point to a line
397their argument values. It also allows you to specify a stack frame by 418describing that frame. The frame whose line point is on is considered
398moving point to the line describing that frame. (A stack frame is the 419the @dfn{current frame}.
399place where the Lisp interpreter records information about a particular 420
400invocation of a function.) The frame whose line point is on is 421If a function name is underlined, that means Emacs knows where its
401considered the @dfn{current frame}. Some of the debugger commands 422source code is located. You can click with the mouse on that name, or
402operate on the current frame. If a line starts with a star, that means 423move to it and type @key{RET}, to visit the source code. You can also
403that exiting that frame will call the debugger again. This is useful 424type @key{RET} while point is on any name of a function or variable
404for examining the return value of a function. 425which is not underlined, to see help information for that symbol in a
405 426help buffer, if any exists. The @code{xref-find-definitions} command,
406 If a function name is underlined, that means the debugger knows 427bound to @key{M-.}, can also be used on any identifier in a backtrace
407where its source code is located. You can click with the mouse on 428(@pxref{Looking Up Identifiers,,,emacs,Emacs manual}).
408that name, or move to it and type @key{RET}, to visit the source code. 429
430In backtraces, the tails of long lists and the ends of long strings,
431vectors or structures, as well as objects which are deeply nested,
432will be printed as underlined ``...''. You can click with the mouse
433on a ``...'', or type @key{RET} while point is on it, to show the part
434of the object that was hidden. To control how much abbreviation is
435done, customize @code{backtrace-line-length}.
436
437Here 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
411assumptions about how many stack frames are used for the debugger 440@item v
412itself. These assumptions are false if the debugger is running 441Toggle the display of local variables of the current stack frame.
413interpreted. 442
443@item p
444Move to the beginning of the frame, or to the beginning
445of the previous frame.
446
447@item n
448Move to the beginning of the next frame.
449
450@item +
451Add line breaks and indentation to the top-level Lisp form at point to
452make it more readable.
453
454@item =
455Collapse the top-level Lisp form at point back to a single line.
456
457@item #
458Toggle @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
420addition to the usual Emacs commands. The most important use of 467addition to the usual Emacs commands and to the Backtrace mode commands
468described in the previous section. The most important use of
421debugger commands is for stepping through code, so that you can see 469debugger commands is for stepping through code, so that you can see
422how control flows. The debugger can step through the control 470how control flows. The debugger can step through the control
423structures of an interpreted function, but cannot do so in a 471structures 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
427type @kbd{C-M-x} on its definition.) You cannot use the Lisp debugger 475type @kbd{C-M-x} on its definition.) You cannot use the Lisp debugger
428to step through a primitive function. 476to step through a primitive function.
429 477
478Some of the debugger commands operate on the current frame. If a
479frame starts with a star, that means that exiting that frame will call the
480debugger again. This is useful for examining the return value of a
481function.
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.
502This is a list of functions that are set to break on entry by means of 555This 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
506Toggle 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
442Display a backtrace, excluding Edebug's own functions for clarity 442Display a backtrace, excluding Edebug's own functions for clarity
443(@code{edebug-backtrace}). 443(@code{edebug-backtrace}).
444 444
445You cannot use debugger commands in the backtrace buffer in Edebug as 445@xref{Debugging,, Backtraces, elisp}, for the commands which work
446you would in the standard debugger. 446in a backtrace buffer.
447 447
448The backtrace buffer is killed automatically when you continue 448The backtrace buffer is killed automatically when you continue
449execution. 449execution.
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
274Pressing @kbd{r} re-runs the test near point on its own. Pressing 274Pressing @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
276definition of the test near point (@kbd{@key{RET}} has the same effect if 276definition of the test near point (@kbd{@key{RET}} has the same effect
277point is on the name of the test). On a failed test, @kbd{b} shows 277if point is on the name of the test). On a failed test, @kbd{b} shows
278the backtrace of the failure. 278the backtrace of the failure. @xref{Debugging,, Backtraces, elisp,
279the Emacs Lisp Reference Manual}, for more information about
280backtraces.
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.