diff options
| author | Richard M. Stallman | 1998-05-19 03:45:57 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-05-19 03:45:57 +0000 |
| commit | a9f0a989a17f47f9d25b7a426b4e82a8ff684ee4 (patch) | |
| tree | d62b5592064177c684f1509989b223623db3f24c /lispref/debugging.texi | |
| parent | c6d6572475603083762cb0155ae966de7710bb9c (diff) | |
| download | emacs-a9f0a989a17f47f9d25b7a426b4e82a8ff684ee4.tar.gz emacs-a9f0a989a17f47f9d25b7a426b4e82a8ff684ee4.zip | |
*** empty log message ***
Diffstat (limited to 'lispref/debugging.texi')
| -rw-r--r-- | lispref/debugging.texi | 108 |
1 files changed, 57 insertions, 51 deletions
diff --git a/lispref/debugging.texi b/lispref/debugging.texi index 9c7a4fd7be7..8e5ed2834a5 100644 --- a/lispref/debugging.texi +++ b/lispref/debugging.texi | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1998 Free Software Foundation, Inc. | 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1998 Free Software Foundation, Inc. |
| 4 | @c See the file elisp.texi for copying conditions. | 4 | @c See the file elisp.texi for copying conditions. |
| 5 | @setfilename ../info/debugging | 5 | @setfilename ../info/debugging |
| 6 | @node Debugging, Read and Print, Advising, Top | 6 | @node Debugging, Read and Print, Advising Functions, Top |
| 7 | @chapter Debugging Lisp Programs | 7 | @chapter Debugging Lisp Programs |
| 8 | 8 | ||
| 9 | There are three ways to investigate a problem in an Emacs Lisp program, | 9 | There are three ways to investigate a problem in an Emacs Lisp program, |
| @@ -12,8 +12,9 @@ depending on what you are doing with the program when the problem appears. | |||
| 12 | @itemize @bullet | 12 | @itemize @bullet |
| 13 | @item | 13 | @item |
| 14 | If the problem occurs when you run the program, you can use a Lisp | 14 | If the problem occurs when you run the program, you can use a Lisp |
| 15 | debugger (either the default debugger or Edebug) to investigate what is | 15 | debugger to investigate what is happening during execution. In addition |
| 16 | happening during execution. | 16 | to the ordinary debugger, Emacs comes with a source level debugger, |
| 17 | Edebug. This chapter describes both of them. | ||
| 17 | 18 | ||
| 18 | @item | 19 | @item |
| 19 | If the problem is syntactic, so that Lisp cannot even read the program, | 20 | If the problem is syntactic, so that Lisp cannot even read the program, |
| @@ -26,9 +27,9 @@ compiler, you need to know how to examine the compiler's input buffer. | |||
| 26 | 27 | ||
| 27 | @menu | 28 | @menu |
| 28 | * Debugger:: How the Emacs Lisp debugger is implemented. | 29 | * Debugger:: How the Emacs Lisp debugger is implemented. |
| 30 | * Edebug:: A source-level Emacs Lisp debugger. | ||
| 29 | * Syntax Errors:: How to find syntax errors. | 31 | * Syntax Errors:: How to find syntax errors. |
| 30 | * Compilation Errors:: How to find errors that show up in byte compilation. | 32 | * Compilation Errors:: How to find errors that show up in byte compilation. |
| 31 | * Edebug:: A source-level Emacs Lisp debugger. | ||
| 32 | @end menu | 33 | @end menu |
| 33 | 34 | ||
| 34 | Another useful debugging tool is the dribble file. When a dribble | 35 | Another useful debugging tool is the dribble file. When a dribble |
| @@ -45,13 +46,13 @@ Afterward, you can examine the file to find out what input was used. | |||
| 45 | @cindex Lisp debugger | 46 | @cindex Lisp debugger |
| 46 | @cindex break | 47 | @cindex break |
| 47 | 48 | ||
| 48 | The @dfn{Lisp debugger} provides the ability to suspend evaluation of | 49 | The ordinary @dfn{Lisp debugger} provides the ability to suspend |
| 49 | a form. While evaluation is suspended (a state that is commonly known | 50 | evaluation of a form. While evaluation is suspended (a state that is |
| 50 | as a @dfn{break}), you may examine the run time stack, examine the | 51 | commonly known as a @dfn{break}), you may examine the run time stack, |
| 51 | values of local or global variables, or change those values. Since a | 52 | examine the values of local or global variables, or change those values. |
| 52 | break is a recursive edit, all the usual editing facilities of Emacs are | 53 | Since a break is a recursive edit, all the usual editing facilities of |
| 53 | available; you can even run programs that will enter the debugger | 54 | Emacs are available; you can even run programs that will enter the |
| 54 | recursively. @xref{Recursive Editing}. | 55 | debugger recursively. @xref{Recursive Editing}. |
| 55 | 56 | ||
| 56 | @menu | 57 | @menu |
| 57 | * Error Debugging:: Entering the debugger when an error happens. | 58 | * Error Debugging:: Entering the debugger when an error happens. |
| @@ -74,25 +75,28 @@ happens. This allows you to investigate the immediate causes of the | |||
| 74 | error. | 75 | error. |
| 75 | 76 | ||
| 76 | However, entry to the debugger is not a normal consequence of an | 77 | However, entry to the debugger is not a normal consequence of an |
| 77 | error. Many commands frequently get Lisp errors when invoked in | 78 | error. Many commands frequently cause Lisp errors when invoked |
| 78 | inappropriate contexts (such as @kbd{C-f} at the end of the buffer) and | 79 | inappropriately (such as @kbd{C-f} at the end of the buffer), and during |
| 79 | during ordinary editing it would be very unpleasant to enter the | 80 | ordinary editing it would be very inconvenient to enter the debugger |
| 80 | debugger each time this happens. If you want errors to enter the | 81 | each time this happens. So if you want errors to enter the debugger, set |
| 81 | debugger, set the variable @code{debug-on-error} to non-@code{nil}. | 82 | the variable @code{debug-on-error} to non-@code{nil}. (The command |
| 83 | @code{toggle-debug-on-error} provides an easy way to do this.) | ||
| 82 | 84 | ||
| 83 | @defopt debug-on-error | 85 | @defopt debug-on-error |
| 84 | This variable determines whether the debugger is called when an error is | 86 | This variable determines whether the debugger is called when an error is |
| 85 | signaled and not handled. If @code{debug-on-error} is @code{t}, all | 87 | signaled and not handled. If @code{debug-on-error} is @code{t}, all |
| 86 | errors call the debugger. If it is @code{nil}, none call the debugger. | 88 | kinds of errors call the debugger (except those listed in |
| 89 | @code{debug-ignored-errors}). If it is @code{nil}, none call the | ||
| 90 | debugger. | ||
| 87 | 91 | ||
| 88 | The value can also be a list of error conditions that should call the | 92 | The value can also be a list of error conditions that should call the |
| 89 | debugger. For example, if you set it to the list | 93 | debugger. For example, if you set it to the list |
| 90 | @code{(void-variable)}, then only errors about a variable that has no | 94 | @code{(void-variable)}, then only errors about a variable that has no |
| 91 | value invoke the debugger. | 95 | value invoke the debugger. |
| 92 | 96 | ||
| 93 | When this variable is non-@code{nil}, Emacs does not catch errors that | 97 | When this variable is non-@code{nil}, Emacs does not create an error |
| 94 | happen in process filter functions and sentinels. Therefore, these | 98 | handler around process filter functions and sentinels. Therefore, |
| 95 | errors also can invoke the debugger. @xref{Processes}. | 99 | errors in these functions also invoke the debugger. @xref{Processes}. |
| 96 | @end defopt | 100 | @end defopt |
| 97 | 101 | ||
| 98 | @defopt debug-ignored-errors | 102 | @defopt debug-ignored-errors |
| @@ -117,10 +121,10 @@ debugger, even if @code{debug-on-error} is non-@code{nil}. In other | |||
| 117 | words, @code{condition-case} gets a chance to handle the error before | 121 | words, @code{condition-case} gets a chance to handle the error before |
| 118 | the debugger gets a chance. | 122 | the debugger gets a chance. |
| 119 | 123 | ||
| 120 | If you set @code{debug-on-signal} non-@code{nil}, then the debugger gets | 124 | If you set @code{debug-on-signal} to a non-@code{nil} value, then the |
| 121 | first chance at every error; an error will invoke the debugger | 125 | debugger gets the first chance at every error; an error will invoke the |
| 122 | regardless of any @code{condition-case}, if the fits the criterion | 126 | debugger regardless of any @code{condition-case}, if it fits the |
| 123 | specified by the values of @code{debug-on-error} and | 127 | criterion specified by the values of @code{debug-on-error} and |
| 124 | @code{debug-ignored-errors}. | 128 | @code{debug-ignored-errors}. |
| 125 | 129 | ||
| 126 | @strong{Warning:} This variable is strong medicine! Various parts of | 130 | @strong{Warning:} This variable is strong medicine! Various parts of |
| @@ -134,13 +138,14 @@ enter the debugger. | |||
| 134 | @end defopt | 138 | @end defopt |
| 135 | 139 | ||
| 136 | To debug an error that happens during loading of the @file{.emacs} | 140 | To debug an error that happens during loading of the @file{.emacs} |
| 137 | file, use the option @samp{-debug-init}, which binds | 141 | file, use the option @samp{--debug-init}, which binds |
| 138 | @code{debug-on-error} to @code{t} while @file{.emacs} is loaded and | 142 | @code{debug-on-error} to @code{t} while @file{.emacs} is loaded, and |
| 139 | inhibits use of @code{condition-case} to catch init-file errors. | 143 | bypasses the @code{condition-case} which normally catches errors in the |
| 144 | init-file. | ||
| 140 | 145 | ||
| 141 | If your @file{.emacs} file sets @code{debug-on-error}, the effect may | 146 | If your @file{.emacs} file sets @code{debug-on-error}, the effect may |
| 142 | not last past the end of loading @file{.emacs}. (This is an undesirable | 147 | not last past the end of loading @file{.emacs}. (This is an undesirable |
| 143 | byproduct of the code that implements the @samp{-debug-init} command | 148 | byproduct of the code that implements the @samp{--debug-init} command |
| 144 | line option.) The best way to make @file{.emacs} set | 149 | line option.) The best way to make @file{.emacs} set |
| 145 | @code{debug-on-error} permanently is with @code{after-init-hook}, like | 150 | @code{debug-on-error} permanently is with @code{after-init-hook}, like |
| 146 | this: | 151 | this: |
| @@ -269,8 +274,9 @@ not currently set up to break on entry. It always returns | |||
| 269 | You can cause the debugger to be called at a certain point in your | 274 | You can cause the debugger to be called at a certain point in your |
| 270 | program by writing the expression @code{(debug)} at that point. To do | 275 | program by writing the expression @code{(debug)} at that point. To do |
| 271 | this, visit the source file, insert the text @samp{(debug)} at the | 276 | this, visit the source file, insert the text @samp{(debug)} at the |
| 272 | proper place, and type @kbd{C-M-x}. Be sure to undo this insertion | 277 | proper place, and type @kbd{C-M-x}. @strong{Warning:} if you do this |
| 273 | before you save the file! | 278 | for temporary debugging purposes, be sure to undo this insertion before |
| 279 | you save the file! | ||
| 274 | 280 | ||
| 275 | The place where you insert @samp{(debug)} must be a place where an | 281 | The place where you insert @samp{(debug)} must be a place where an |
| 276 | additional form can be evaluated and its value ignored. (If the value | 282 | additional form can be evaluated and its value ignored. (If the value |
| @@ -339,8 +345,8 @@ same function. (To do this, visit the source for the function and type | |||
| 339 | @item c | 345 | @item c |
| 340 | Exit the debugger and continue execution. When continuing is possible, | 346 | Exit the debugger and continue execution. When continuing is possible, |
| 341 | it resumes execution of the program as if the debugger had never been | 347 | it resumes execution of the program as if the debugger had never been |
| 342 | entered (aside from the effect of any variables or data structures you | 348 | entered (aside from any side-effects that you caused by changing |
| 343 | may have changed while inside the debugger). | 349 | variable values or data structures while inside the debugger). |
| 344 | 350 | ||
| 345 | Continuing is possible after entry to the debugger due to function entry | 351 | Continuing is possible after entry to the debugger due to function entry |
| 346 | or exit, explicit invocation, or quitting. You cannot continue if the | 352 | or exit, explicit invocation, or quitting. You cannot continue if the |
| @@ -371,10 +377,10 @@ remove the star from the line in the backtrace buffer. | |||
| 371 | Read a Lisp expression in the minibuffer, evaluate it, and print the | 377 | Read a Lisp expression in the minibuffer, evaluate it, and print the |
| 372 | value in the echo area. The debugger alters certain important | 378 | value in the echo area. The debugger alters certain important |
| 373 | variables, and the current buffer, as part of its operation; @kbd{e} | 379 | variables, and the current buffer, as part of its operation; @kbd{e} |
| 374 | temporarily restores their outside-the-debugger values so you can | 380 | temporarily restores their values from outside the debugger, so you can |
| 375 | examine them. This makes the debugger more transparent. By contrast, | 381 | examine and change them. This makes the debugger more transparent. By |
| 376 | @kbd{M-:} does nothing special in the debugger; it shows you the | 382 | contrast, @kbd{M-:} does nothing special in the debugger; it shows you |
| 377 | variable values within the debugger. | 383 | the variable values within the debugger. |
| 378 | 384 | ||
| 379 | @item R | 385 | @item R |
| 380 | Like @kbd{e}, but also save the result of evaluation in the | 386 | Like @kbd{e}, but also save the result of evaluation in the |
| @@ -404,7 +410,8 @@ You can't use @kbd{r} when the debugger was entered due to an error. | |||
| 404 | @node Invoking the Debugger | 410 | @node Invoking the Debugger |
| 405 | @subsection Invoking the Debugger | 411 | @subsection Invoking the Debugger |
| 406 | 412 | ||
| 407 | Here we describe fully the function used to invoke the debugger. | 413 | Here we describe in full detail the function @code{debug} that is used |
| 414 | to invoke the debugger. | ||
| 408 | 415 | ||
| 409 | @defun debug &rest debugger-args | 416 | @defun debug &rest debugger-args |
| 410 | This function enters the debugger. It switches buffers to a buffer | 417 | This function enters the debugger. It switches buffers to a buffer |
| @@ -418,18 +425,15 @@ then @code{debug} switches back to the previous buffer and returns to | |||
| 418 | whatever called @code{debug}. This is the only way the function | 425 | whatever called @code{debug}. This is the only way the function |
| 419 | @code{debug} can return to its caller. | 426 | @code{debug} can return to its caller. |
| 420 | 427 | ||
| 421 | If the first of the @var{debugger-args} passed to @code{debug} is | 428 | The use of the @var{debugger-args} is that @code{debug} displays the |
| 422 | @code{nil} (or if it is not one of the special values in the table | 429 | rest of its arguments at the top of the @samp{*Backtrace*} buffer, so |
| 423 | below), then @code{debug} displays the rest of its arguments at the | 430 | that the user can see them. Except as described below, this is the |
| 424 | top of the @samp{*Backtrace*} buffer. This mechanism is used to display | 431 | @emph{only} way these arguments are used. |
| 425 | a message to the user. | ||
| 426 | |||
| 427 | However, if the first argument passed to @code{debug} is one of the | ||
| 428 | following special values, then it has special significance. Normally, | ||
| 429 | these values are passed to @code{debug} only by the internals of Emacs | ||
| 430 | and the debugger, and not by programmers calling @code{debug}. | ||
| 431 | 432 | ||
| 432 | The special values are: | 433 | However, certain values for first argument to @code{debug} have a |
| 434 | special significance. (Normally, these values are used only by the | ||
| 435 | internals of Emacs, and not by programmers calling @code{debug}.) Here | ||
| 436 | is a table of these special values: | ||
| 433 | 437 | ||
| 434 | @table @code | 438 | @table @code |
| 435 | @item lambda | 439 | @item lambda |
| @@ -640,6 +644,8 @@ If @var{frame-number} is out of range, @code{backtrace-frame} returns | |||
| 640 | @code{nil}. | 644 | @code{nil}. |
| 641 | @end defun | 645 | @end defun |
| 642 | 646 | ||
| 647 | @include edebug.texi | ||
| 648 | |||
| 643 | @node Syntax Errors | 649 | @node Syntax Errors |
| 644 | @section Debugging Invalid Lisp Syntax | 650 | @section Debugging Invalid Lisp Syntax |
| 645 | 651 | ||
| @@ -658,7 +664,9 @@ if it goes to the place where that defun appears to end. If it does | |||
| 658 | not, there is a problem in that defun. | 664 | not, there is a problem in that defun. |
| 659 | 665 | ||
| 660 | However, unmatched parentheses are the most common syntax errors in | 666 | However, unmatched parentheses are the most common syntax errors in |
| 661 | Lisp, and we can give further advice for those cases. | 667 | Lisp, and we can give further advice for those cases. (In addition, |
| 668 | just moving point through the code with Show Paren mode enabled might | ||
| 669 | find the mismatch.) | ||
| 662 | 670 | ||
| 663 | @menu | 671 | @menu |
| 664 | * Excess Open:: How to find a spurious open paren or missing close. | 672 | * Excess Open:: How to find a spurious open paren or missing close. |
| @@ -753,5 +761,3 @@ the error. | |||
| 753 | successfully, then point is located at the end of the form. In this | 761 | successfully, then point is located at the end of the form. In this |
| 754 | case, this technique can't localize the error precisely, but can still | 762 | case, this technique can't localize the error precisely, but can still |
| 755 | show you which function to check. | 763 | show you which function to check. |
| 756 | |||
| 757 | @include edebug.texi | ||