diff options
| author | Richard M. Stallman | 1998-04-20 17:43:57 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-04-20 17:43:57 +0000 |
| commit | 969fe9b5696c9d9d31f2faf1ca2e8af107013dcb (patch) | |
| tree | 5d7d0399caf410b5c4849aa9d43352b18f68d4c9 /lispref/debugging.texi | |
| parent | b933f645ac70a31659f364cabf7da730d27eb244 (diff) | |
| download | emacs-969fe9b5696c9d9d31f2faf1ca2e8af107013dcb.tar.gz emacs-969fe9b5696c9d9d31f2faf1ca2e8af107013dcb.zip | |
*** empty log message ***
Diffstat (limited to 'lispref/debugging.texi')
| -rw-r--r-- | lispref/debugging.texi | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/lispref/debugging.texi b/lispref/debugging.texi index 99e5e034358..9c7a4fd7be7 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, Byte Compilation, Top | 6 | @node Debugging, Read and Print, Advising, 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, |
| @@ -104,14 +104,18 @@ that error does not enter the debugger, regardless of the value of | |||
| 104 | @code{debug-on-error}. | 104 | @code{debug-on-error}. |
| 105 | 105 | ||
| 106 | The normal value of this variable lists several errors that happen often | 106 | The normal value of this variable lists several errors that happen often |
| 107 | during editing but rarely result from bugs in Lisp programs. | 107 | during editing but rarely result from bugs in Lisp programs. However, |
| 108 | ``rarely'' is not ``never''; if your program fails with an error that | ||
| 109 | matches this list, you will need to change this list in order to debug | ||
| 110 | the error. The easiest way is usually to set | ||
| 111 | @code{debug-ignored-errors} to @code{nil}. | ||
| 108 | @end defopt | 112 | @end defopt |
| 109 | 113 | ||
| 110 | @defopt debug-on-signal | 114 | @defopt debug-on-signal |
| 111 | Normally, errors that are caught by @code{condition-case} never run the | 115 | Normally, errors that are caught by @code{condition-case} never run the |
| 112 | debugger, even if @code{debug-on-error} is non-@code{nil}. In other | 116 | debugger, even if @code{debug-on-error} is non-@code{nil}. In other |
| 113 | words, @code{condition-case} gets a chance to catch the error before the | 117 | words, @code{condition-case} gets a chance to handle the error before |
| 114 | debugger gets a chance. | 118 | the debugger gets a chance. |
| 115 | 119 | ||
| 116 | If you set @code{debug-on-signal} non-@code{nil}, then the debugger gets | 120 | If you set @code{debug-on-signal} non-@code{nil}, then the debugger gets |
| 117 | first chance at every error; an error will invoke the debugger | 121 | first chance at every error; an error will invoke the debugger |
| @@ -119,7 +123,7 @@ regardless of any @code{condition-case}, if the fits the criterion | |||
| 119 | specified by the values of @code{debug-on-error} and | 123 | specified by the values of @code{debug-on-error} and |
| 120 | @code{debug-ignored-errors}. | 124 | @code{debug-ignored-errors}. |
| 121 | 125 | ||
| 122 | @strong{Warning:} This variable is strong medecine! Various parts of | 126 | @strong{Warning:} This variable is strong medicine! Various parts of |
| 123 | Emacs handle errors in the normal course of affairs, and you may not | 127 | Emacs handle errors in the normal course of affairs, and you may not |
| 124 | even realize that errors happen there. If you set | 128 | even realize that errors happen there. If you set |
| 125 | @code{debug-on-signal} to a non-@code{nil} value, those errors will | 129 | @code{debug-on-signal} to a non-@code{nil} value, those errors will |
| @@ -132,7 +136,7 @@ enter the debugger. | |||
| 132 | To debug an error that happens during loading of the @file{.emacs} | 136 | To debug an error that happens during loading of the @file{.emacs} |
| 133 | file, use the option @samp{-debug-init}, which binds | 137 | file, use the option @samp{-debug-init}, which binds |
| 134 | @code{debug-on-error} to @code{t} while @file{.emacs} is loaded and | 138 | @code{debug-on-error} to @code{t} while @file{.emacs} is loaded and |
| 135 | inhibits use of @code{condition-case} to catch init file errors. | 139 | inhibits use of @code{condition-case} to catch init-file errors. |
| 136 | 140 | ||
| 137 | If your @file{.emacs} file sets @code{debug-on-error}, the effect may | 141 | If your @file{.emacs} file sets @code{debug-on-error}, the effect may |
| 138 | not last past the end of loading @file{.emacs}. (This is an undesirable | 142 | not last past the end of loading @file{.emacs}. (This is an undesirable |
| @@ -190,26 +194,25 @@ called shortly before the problem, step quickly over the call to that | |||
| 190 | function, and then step through its caller. | 194 | function, and then step through its caller. |
| 191 | 195 | ||
| 192 | @deffn Command debug-on-entry function-name | 196 | @deffn Command debug-on-entry function-name |
| 193 | This function requests @var{function-name} to invoke the debugger each time | 197 | This function requests @var{function-name} to invoke the debugger each time |
| 194 | it is called. It works by inserting the form @code{(debug 'debug)} into | 198 | it is called. It works by inserting the form @code{(debug 'debug)} into |
| 195 | the function definition as the first form. | 199 | the function definition as the first form. |
| 196 | 200 | ||
| 197 | Any function defined as Lisp code may be set to break on entry, | 201 | Any function defined as Lisp code may be set to break on entry, |
| 198 | regardless of whether it is interpreted code or compiled code. If the | 202 | regardless of whether it is interpreted code or compiled code. If the |
| 199 | function is a command, it will enter the debugger when called from Lisp | 203 | function is a command, it will enter the debugger when called from Lisp |
| 200 | and when called interactively (after the reading of the arguments). You | 204 | and when called interactively (after the reading of the arguments). You |
| 201 | can't debug primitive functions (i.e., those written in C) this way. | 205 | can't debug primitive functions (i.e., those written in C) this way. |
| 202 | 206 | ||
| 203 | When @code{debug-on-entry} is called interactively, it prompts | 207 | When @code{debug-on-entry} is called interactively, it prompts for |
| 204 | for @var{function-name} in the minibuffer. | 208 | @var{function-name} in the minibuffer. If the function is already set |
| 209 | up to invoke the debugger on entry, @code{debug-on-entry} does nothing. | ||
| 210 | @code{debug-on-entry} always returns @var{function-name}. | ||
| 205 | 211 | ||
| 206 | If the function is already set up to invoke the debugger on entry, | 212 | @strong{Note:} if you redefine a function after using |
| 207 | @code{debug-on-entry} does nothing. | 213 | @code{debug-on-entry} on it, the code to enter the debugger is discarded |
| 208 | 214 | by the redefinition. In effect, redefining the function cancels | |
| 209 | @strong{Note:} if you redefine a function after using | 215 | the break-on-entry feature for that function. |
| 210 | @code{debug-on-entry} on it, the code to enter the debugger is lost. | ||
| 211 | |||
| 212 | @code{debug-on-entry} returns @var{function-name}. | ||
| 213 | 216 | ||
| 214 | @example | 217 | @example |
| 215 | @group | 218 | @group |
| @@ -252,11 +255,12 @@ Entering: | |||
| 252 | This function undoes the effect of @code{debug-on-entry} on | 255 | This function undoes the effect of @code{debug-on-entry} on |
| 253 | @var{function-name}. When called interactively, it prompts for | 256 | @var{function-name}. When called interactively, it prompts for |
| 254 | @var{function-name} in the minibuffer. If @var{function-name} is | 257 | @var{function-name} in the minibuffer. If @var{function-name} is |
| 255 | @code{nil} or the empty string, it cancels debugging for all functions. | 258 | @code{nil} or the empty string, it cancels break-on-entry for all |
| 259 | functions. | ||
| 256 | 260 | ||
| 257 | If @code{cancel-debug-on-entry} is called more than once on the same | 261 | Calling @code{cancel-debug-on-entry} does nothing to a function which is |
| 258 | function, the second call does nothing. @code{cancel-debug-on-entry} | 262 | not currently set up to break on entry. It always returns |
| 259 | returns @var{function-name}. | 263 | @var{function-name}. |
| 260 | @end deffn | 264 | @end deffn |
| 261 | 265 | ||
| 262 | @node Explicit Debug | 266 | @node Explicit Debug |
| @@ -326,8 +330,8 @@ code, so that you can see how control flows. The debugger can step | |||
| 326 | through the control structures of an interpreted function, but cannot do | 330 | through the control structures of an interpreted function, but cannot do |
| 327 | so in a byte-compiled function. If you would like to step through a | 331 | so in a byte-compiled function. If you would like to step through a |
| 328 | byte-compiled function, replace it with an interpreted definition of the | 332 | byte-compiled function, replace it with an interpreted definition of the |
| 329 | same function. (To do this, visit the source file for the function and | 333 | same function. (To do this, visit the source for the function and type |
| 330 | type @kbd{C-M-x} on its definition.) | 334 | @kbd{C-M-x} on its definition.) |
| 331 | 335 | ||
| 332 | Here is a list of Debugger mode commands: | 336 | Here is a list of Debugger mode commands: |
| 333 | 337 | ||
| @@ -360,7 +364,8 @@ in the backtrace buffer. | |||
| 360 | 364 | ||
| 361 | @item u | 365 | @item u |
| 362 | Don't enter the debugger when the current frame is exited. This | 366 | Don't enter the debugger when the current frame is exited. This |
| 363 | cancels a @kbd{b} command on that frame. | 367 | cancels a @kbd{b} command on that frame. The visible effect is to |
| 368 | remove the star from the line in the backtrace buffer. | ||
| 364 | 369 | ||
| 365 | @item e | 370 | @item e |
| 366 | Read a Lisp expression in the minibuffer, evaluate it, and print the | 371 | Read a Lisp expression in the minibuffer, evaluate it, and print the |
| @@ -371,6 +376,10 @@ examine them. This makes the debugger more transparent. By contrast, | |||
| 371 | @kbd{M-:} does nothing special in the debugger; it shows you the | 376 | @kbd{M-:} does nothing special in the debugger; it shows you the |
| 372 | variable values within the debugger. | 377 | variable values within the debugger. |
| 373 | 378 | ||
| 379 | @item R | ||
| 380 | Like @kbd{e}, but also save the result of evaluation in the | ||
| 381 | buffer @samp{*Debugger-record*}. | ||
| 382 | |||
| 374 | @item q | 383 | @item q |
| 375 | Terminate the program being debugged; return to top-level Emacs | 384 | Terminate the program being debugged; return to top-level Emacs |
| 376 | command execution. | 385 | command execution. |
| @@ -383,11 +392,11 @@ Return a value from the debugger. The value is computed by reading an | |||
| 383 | expression with the minibuffer and evaluating it. | 392 | expression with the minibuffer and evaluating it. |
| 384 | 393 | ||
| 385 | The @kbd{r} command is useful when the debugger was invoked due to exit | 394 | The @kbd{r} command is useful when the debugger was invoked due to exit |
| 386 | from a Lisp call frame (as requested with @kbd{b}); then the value | 395 | from a Lisp call frame (as requested with @kbd{b} or by entering the |
| 387 | specified in the @kbd{r} command is used as the value of that frame. It | 396 | frame with @kbd{d}); then the value specified in the @kbd{r} command is |
| 388 | is also useful if you call @code{debug} and use its return value. | 397 | used as the value of that frame. It is also useful if you call |
| 389 | Otherwise, @kbd{r} has the same effect as @kbd{c}, and the specified | 398 | @code{debug} and use its return value. Otherwise, @kbd{r} has the same |
| 390 | return value does not matter. | 399 | effect as @kbd{c}, and the specified return value does not matter. |
| 391 | 400 | ||
| 392 | You can't use @kbd{r} when the debugger was entered due to an error. | 401 | You can't use @kbd{r} when the debugger was entered due to an error. |
| 393 | @end table | 402 | @end table |
| @@ -448,11 +457,11 @@ Beginning evaluation of function call form: | |||
| 448 | @end smallexample | 457 | @end smallexample |
| 449 | 458 | ||
| 450 | @item exit | 459 | @item exit |
| 451 | When the first argument is @code{exit}, it indicates the exit of a | 460 | When the first argument is @code{exit}, it indicates the exit of a stack |
| 452 | stack frame previously marked to invoke the debugger on exit. The | 461 | frame previously marked to invoke the debugger on exit. The second |
| 453 | second argument given to @code{debug} in this case is the value being | 462 | argument given to @code{debug} in this case is the value being returned |
| 454 | returned from the frame. The debugger displays @samp{Return value:} on | 463 | from the frame. The debugger displays @samp{Return value:} in the top |
| 455 | the top line of the buffer, followed by the value being returned. | 464 | line of the buffer, followed by the value being returned. |
| 456 | 465 | ||
| 457 | @item error | 466 | @item error |
| 458 | @cindex @code{error} in debug | 467 | @cindex @code{error} in debug |
| @@ -605,8 +614,8 @@ bound to @code{nil}. The debugger can set this variable to leave | |||
| 605 | information for future debugger invocations during the same command | 614 | information for future debugger invocations during the same command |
| 606 | invocation. | 615 | invocation. |
| 607 | 616 | ||
| 608 | The advantage, for the debugger, of using this variable rather than | 617 | The advantage, for the debugger, of using this variable rather than an |
| 609 | another global variable is that the data will never carry over to a | 618 | ordinary global variable is that the data will never carry over to a |
| 610 | subsequent command invocation. | 619 | subsequent command invocation. |
| 611 | @end defvar | 620 | @end defvar |
| 612 | 621 | ||
| @@ -671,7 +680,8 @@ close parenthesis, and finally return to the mark.) | |||
| 671 | way to be sure of this except by studying the program, but often the | 680 | way to be sure of this except by studying the program, but often the |
| 672 | existing indentation is a clue to where the parentheses should have | 681 | existing indentation is a clue to where the parentheses should have |
| 673 | been. The easiest way to use this clue is to reindent with @kbd{C-M-q} | 682 | been. The easiest way to use this clue is to reindent with @kbd{C-M-q} |
| 674 | and see what moves. | 683 | and see what moves. @strong{But don't do this yet!} Keep reading, |
| 684 | first. | ||
| 675 | 685 | ||
| 676 | Before you do this, make sure the defun has enough close parentheses. | 686 | Before you do this, make sure the defun has enough close parentheses. |
| 677 | Otherwise, @kbd{C-M-q} will get an error, or will reindent all the rest | 687 | Otherwise, @kbd{C-M-q} will get an error, or will reindent all the rest |
| @@ -702,7 +712,7 @@ parenthesis at the beginning of the file, back up over it, and type | |||
| 702 | insertion of the open parenthesis, and finally return to the mark.) | 712 | insertion of the open parenthesis, and finally return to the mark.) |
| 703 | 713 | ||
| 704 | Then find the actual matching close parenthesis by typing @kbd{C-M-f} | 714 | Then find the actual matching close parenthesis by typing @kbd{C-M-f} |
| 705 | at the beginning of the defun. This will leave you somewhere short of | 715 | at the beginning of that defun. This will leave you somewhere short of |
| 706 | the place where the defun ought to end. It is possible that you will | 716 | the place where the defun ought to end. It is possible that you will |
| 707 | find a spurious close parenthesis in that vicinity. | 717 | find a spurious close parenthesis in that vicinity. |
| 708 | 718 | ||