aboutsummaryrefslogtreecommitdiffstats
path: root/lispref/debugging.texi
diff options
context:
space:
mode:
authorRichard M. Stallman1998-05-19 03:45:57 +0000
committerRichard M. Stallman1998-05-19 03:45:57 +0000
commita9f0a989a17f47f9d25b7a426b4e82a8ff684ee4 (patch)
treed62b5592064177c684f1509989b223623db3f24c /lispref/debugging.texi
parentc6d6572475603083762cb0155ae966de7710bb9c (diff)
downloademacs-a9f0a989a17f47f9d25b7a426b4e82a8ff684ee4.tar.gz
emacs-a9f0a989a17f47f9d25b7a426b4e82a8ff684ee4.zip
*** empty log message ***
Diffstat (limited to 'lispref/debugging.texi')
-rw-r--r--lispref/debugging.texi108
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
14If the problem occurs when you run the program, you can use a Lisp 14If the problem occurs when you run the program, you can use a Lisp
15debugger (either the default debugger or Edebug) to investigate what is 15debugger to investigate what is happening during execution. In addition
16happening during execution. 16to the ordinary debugger, Emacs comes with a source level debugger,
17Edebug. This chapter describes both of them.
17 18
18@item 19@item
19If the problem is syntactic, so that Lisp cannot even read the program, 20If 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
49a form. While evaluation is suspended (a state that is commonly known 50evaluation of a form. While evaluation is suspended (a state that is
50as a @dfn{break}), you may examine the run time stack, examine the 51commonly known as a @dfn{break}), you may examine the run time stack,
51values of local or global variables, or change those values. Since a 52examine the values of local or global variables, or change those values.
52break is a recursive edit, all the usual editing facilities of Emacs are 53Since a break is a recursive edit, all the usual editing facilities of
53available; you can even run programs that will enter the debugger 54Emacs are available; you can even run programs that will enter the
54recursively. @xref{Recursive Editing}. 55debugger 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
74error. 75error.
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
77error. Many commands frequently get Lisp errors when invoked in 78error. Many commands frequently cause Lisp errors when invoked
78inappropriate contexts (such as @kbd{C-f} at the end of the buffer) and 79inappropriately (such as @kbd{C-f} at the end of the buffer), and during
79during ordinary editing it would be very unpleasant to enter the 80ordinary editing it would be very inconvenient to enter the debugger
80debugger each time this happens. If you want errors to enter the 81each time this happens. So if you want errors to enter the debugger, set
81debugger, set the variable @code{debug-on-error} to non-@code{nil}. 82the 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
84This variable determines whether the debugger is called when an error is 86This variable determines whether the debugger is called when an error is
85signaled and not handled. If @code{debug-on-error} is @code{t}, all 87signaled and not handled. If @code{debug-on-error} is @code{t}, all
86errors call the debugger. If it is @code{nil}, none call the debugger. 88kinds of errors call the debugger (except those listed in
89@code{debug-ignored-errors}). If it is @code{nil}, none call the
90debugger.
87 91
88The value can also be a list of error conditions that should call the 92The value can also be a list of error conditions that should call the
89debugger. For example, if you set it to the list 93debugger. 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
91value invoke the debugger. 95value invoke the debugger.
92 96
93When this variable is non-@code{nil}, Emacs does not catch errors that 97When this variable is non-@code{nil}, Emacs does not create an error
94happen in process filter functions and sentinels. Therefore, these 98handler around process filter functions and sentinels. Therefore,
95errors also can invoke the debugger. @xref{Processes}. 99errors 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
117words, @code{condition-case} gets a chance to handle the error before 121words, @code{condition-case} gets a chance to handle the error before
118the debugger gets a chance. 122the debugger gets a chance.
119 123
120If you set @code{debug-on-signal} non-@code{nil}, then the debugger gets 124If you set @code{debug-on-signal} to a non-@code{nil} value, then the
121first chance at every error; an error will invoke the debugger 125debugger gets the first chance at every error; an error will invoke the
122regardless of any @code{condition-case}, if the fits the criterion 126debugger regardless of any @code{condition-case}, if it fits the
123specified by the values of @code{debug-on-error} and 127criterion 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}
137file, use the option @samp{-debug-init}, which binds 141file, 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
139inhibits use of @code{condition-case} to catch init-file errors. 143bypasses the @code{condition-case} which normally catches errors in the
144init-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
142not last past the end of loading @file{.emacs}. (This is an undesirable 147not last past the end of loading @file{.emacs}. (This is an undesirable
143byproduct of the code that implements the @samp{-debug-init} command 148byproduct of the code that implements the @samp{--debug-init} command
144line option.) The best way to make @file{.emacs} set 149line 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
146this: 151this:
@@ -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
270program by writing the expression @code{(debug)} at that point. To do 275program by writing the expression @code{(debug)} at that point. To do
271this, visit the source file, insert the text @samp{(debug)} at the 276this, visit the source file, insert the text @samp{(debug)} at the
272proper place, and type @kbd{C-M-x}. Be sure to undo this insertion 277proper place, and type @kbd{C-M-x}. @strong{Warning:} if you do this
273before you save the file! 278for temporary debugging purposes, be sure to undo this insertion before
279you 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
276additional form can be evaluated and its value ignored. (If the value 282additional 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
340Exit the debugger and continue execution. When continuing is possible, 346Exit the debugger and continue execution. When continuing is possible,
341it resumes execution of the program as if the debugger had never been 347it resumes execution of the program as if the debugger had never been
342entered (aside from the effect of any variables or data structures you 348entered (aside from any side-effects that you caused by changing
343may have changed while inside the debugger). 349variable values or data structures while inside the debugger).
344 350
345Continuing is possible after entry to the debugger due to function entry 351Continuing is possible after entry to the debugger due to function entry
346or exit, explicit invocation, or quitting. You cannot continue if the 352or exit, explicit invocation, or quitting. You cannot continue if the
@@ -371,10 +377,10 @@ remove the star from the line in the backtrace buffer.
371Read a Lisp expression in the minibuffer, evaluate it, and print the 377Read a Lisp expression in the minibuffer, evaluate it, and print the
372value in the echo area. The debugger alters certain important 378value in the echo area. The debugger alters certain important
373variables, and the current buffer, as part of its operation; @kbd{e} 379variables, and the current buffer, as part of its operation; @kbd{e}
374temporarily restores their outside-the-debugger values so you can 380temporarily restores their values from outside the debugger, so you can
375examine them. This makes the debugger more transparent. By contrast, 381examine and change them. This makes the debugger more transparent. By
376@kbd{M-:} does nothing special in the debugger; it shows you the 382contrast, @kbd{M-:} does nothing special in the debugger; it shows you
377variable values within the debugger. 383the variable values within the debugger.
378 384
379@item R 385@item R
380Like @kbd{e}, but also save the result of evaluation in the 386Like @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
414to invoke the debugger.
408 415
409@defun debug &rest debugger-args 416@defun debug &rest debugger-args
410This function enters the debugger. It switches buffers to a buffer 417This 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
418whatever called @code{debug}. This is the only way the function 425whatever 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
421If the first of the @var{debugger-args} passed to @code{debug} is 428The 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 429rest of its arguments at the top of the @samp{*Backtrace*} buffer, so
423below), then @code{debug} displays the rest of its arguments at the 430that the user can see them. Except as described below, this is the
424top of the @samp{*Backtrace*} buffer. This mechanism is used to display 431@emph{only} way these arguments are used.
425a message to the user.
426
427However, if the first argument passed to @code{debug} is one of the
428following special values, then it has special significance. Normally,
429these values are passed to @code{debug} only by the internals of Emacs
430and the debugger, and not by programmers calling @code{debug}.
431 432
432The special values are: 433However, certain values for first argument to @code{debug} have a
434special significance. (Normally, these values are used only by the
435internals of Emacs, and not by programmers calling @code{debug}.) Here
436is 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
658not, there is a problem in that defun. 664not, 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
661Lisp, and we can give further advice for those cases. 667Lisp, and we can give further advice for those cases. (In addition,
668just moving point through the code with Show Paren mode enabled might
669find 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.
753successfully, then point is located at the end of the form. In this 761successfully, then point is located at the end of the form. In this
754case, this technique can't localize the error precisely, but can still 762case, this technique can't localize the error precisely, but can still
755show you which function to check. 763show you which function to check.
756
757@include edebug.texi