aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lispref/debugging.texi
diff options
context:
space:
mode:
authorJoakim Verona2012-02-15 15:12:49 +0100
committerJoakim Verona2012-02-15 15:12:49 +0100
commit02db17e53bf46c91b2cb8ee33b43d8ae252a1681 (patch)
treefcafa961e884648e15524130f1dbca55dc7093d0 /doc/lispref/debugging.texi
parent736ab04e2752e7c3c5b5070a0d62279dcfb12b27 (diff)
parent1deeb569b1247db4c0b2eea4906a9e53e5ee7e99 (diff)
downloademacs-02db17e53bf46c91b2cb8ee33b43d8ae252a1681.tar.gz
emacs-02db17e53bf46c91b2cb8ee33b43d8ae252a1681.zip
upstream
Diffstat (limited to 'doc/lispref/debugging.texi')
-rw-r--r--doc/lispref/debugging.texi216
1 files changed, 96 insertions, 120 deletions
diff --git a/doc/lispref/debugging.texi b/doc/lispref/debugging.texi
index cc92fc225f9..6e7d0078e07 100644
--- a/doc/lispref/debugging.texi
+++ b/doc/lispref/debugging.texi
@@ -6,41 +6,46 @@
6@node Debugging, Read and Print, Advising Functions, 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 several ways to find and investigate problems in an Emacs
10depending on what you are doing with the program when the problem appears. 10Lisp program.
11 11
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 a problem occurs when you run the program, you can use the built-in
15debugger to investigate what is happening during execution. In addition 15Emacs Lisp debugger to suspend the Lisp evaluator, and examine and/or
16to the ordinary debugger, Emacs comes with a source-level debugger, 16alter its internal state.
17Edebug. This chapter describes both of them.
18 17
19@item 18@item
20If the problem is syntactic, so that Lisp cannot even read the program, 19You can use Edebug, a source-level debugger for Emacs Lisp.
21you can use the Emacs facilities for editing Lisp to localize it.
22 20
23@item 21@item
24If the problem occurs when trying to compile the program with the byte 22If a syntactic problem is preventing Lisp from even reading the
25compiler, you need to know how to examine the compiler's input buffer. 23program, you can locate it using Lisp editing commands.
24
25@item
26You can look at the error and warning messages produced by the byte
27compiler when it compiles the program. @xref{Compiler Errors}.
28
29@item
30You can use the Testcover package to perform coverage testing on the
31program.
32
33@item
34You can use the ERT package to write regression tests for the program.
35@xref{Top,the ERT manual,, ERT, ERT: Emacs Lisp Regression Testing}.
26@end itemize 36@end itemize
27 37
38 Other useful tools for debugging input and output problems are the
39dribble file (@pxref{Terminal Input}) and the @code{open-termscript}
40function (@pxref{Terminal Output}).
41
28@menu 42@menu
29* Debugger:: How the Emacs Lisp debugger is implemented. 43* Debugger:: A debugger for the Emacs Lisp evaluator.
30* Edebug:: A source-level Emacs Lisp debugger. 44* Edebug:: A source-level Emacs Lisp debugger.
31* Syntax Errors:: How to find syntax errors. 45* Syntax Errors:: How to find syntax errors.
32* Test Coverage:: Ensuring you have tested all branches in your code. 46* Test Coverage:: Ensuring you have tested all branches in your code.
33* Compilation Errors:: How to find errors that show up in byte compilation.
34@end menu 47@end menu
35 48
36 Another useful debugging tool is the dribble file. When a dribble
37file is open, Emacs copies all keyboard input characters to that file.
38Afterward, you can examine the file to find out what input was used.
39@xref{Terminal Input}.
40
41 For debugging problems in terminal descriptions, the
42@code{open-termscript} function can be useful. @xref{Terminal Output}.
43
44@node Debugger 49@node Debugger
45@section The Lisp Debugger 50@section The Lisp Debugger
46@cindex debugger for Emacs Lisp 51@cindex debugger for Emacs Lisp
@@ -76,25 +81,29 @@ happens. This allows you to investigate the immediate causes of the
76error. 81error.
77 82
78 However, entry to the debugger is not a normal consequence of an 83 However, entry to the debugger is not a normal consequence of an
79error. Many commands frequently cause Lisp errors when invoked 84error. Many commands signal Lisp errors when invoked inappropriately,
80inappropriately, and during ordinary editing it would be very 85and during ordinary editing it would be very inconvenient to enter the
81inconvenient to enter the debugger each time this happens. So if you 86debugger each time this happens. So if you want errors to enter the
82want errors to enter the debugger, set the variable 87debugger, set the variable @code{debug-on-error} to non-@code{nil}.
83@code{debug-on-error} to non-@code{nil}. (The command 88(The command @code{toggle-debug-on-error} provides an easy way to do
84@code{toggle-debug-on-error} provides an easy way to do this.) 89this.)
85 90
86@defopt debug-on-error 91@defopt debug-on-error
87This variable determines whether the debugger is called when an error 92This variable determines whether the debugger is called when an error
88is signaled and not handled. If @code{debug-on-error} is @code{t}, 93is signaled and not handled. If @code{debug-on-error} is @code{t},
89all kinds of errors call the debugger, except those listed in 94all kinds of errors call the debugger, except those listed in
90@code{debug-ignored-errors} (see below). If it is @code{nil}, none 95@code{debug-ignored-errors} (see below). If it is @code{nil}, none
91call the debugger. (Note that @code{eval-expression-debug-on-error} 96call the debugger.
92affects the setting of this variable in some cases; see below.)
93 97
94The value can also be a list of error conditions that should call the 98The value can also be a list of error conditions (@pxref{Signaling
95debugger. For example, if you set it to the list 99Errors}). Then the debugger is called only for error conditions in
96@code{(void-variable)}, then only errors about a variable that has no 100this list (except those also listed in @code{debug-ignored-errors}).
97value invoke the debugger. 101For example, if you set @code{debug-on-error} to the list
102@code{(void-variable)}, the debugger is only called for errors about a
103variable that has no value.
104
105Note that @code{eval-expression-debug-on-error} overrides this
106variable in some cases; see below.
98 107
99When this variable is non-@code{nil}, Emacs does not create an error 108When this variable is non-@code{nil}, Emacs does not create an error
100handler around process filter functions and sentinels. Therefore, 109handler around process filter functions and sentinels. Therefore,
@@ -102,52 +111,50 @@ errors in these functions also invoke the debugger. @xref{Processes}.
102@end defopt 111@end defopt
103 112
104@defopt debug-ignored-errors 113@defopt debug-ignored-errors
105This variable specifies certain kinds of errors that should not enter 114This variable specifies errors which should not enter the debugger,
106the debugger. Its value is a list of error condition symbols and/or 115regardless of the value of @code{debug-on-error}. Its value is a list
107regular expressions. If the error has any of those condition symbols, 116of error condition symbols and/or regular expressions. If the error
108or if the error message matches any of the regular expressions, then 117has any of those condition symbols, or if the error message matches
109that error does not enter the debugger, regardless of the value of 118any of the regular expressions, then that error does not enter the
110@code{debug-on-error}. 119debugger.
111 120
112The normal value of this variable lists several errors that happen often 121The normal value of this variable lists several errors that happen
113during editing but rarely result from bugs in Lisp programs. However, 122often during editing but rarely result from bugs in Lisp programs.
114``rarely'' is not ``never''; if your program fails with an error that 123However, ``rarely'' is not ``never''; if your program fails with an
115matches this list, you will need to change this list in order to debug 124error that matches this list, you may try changing this list to debug
116the error. The easiest way is usually to set 125the error. The easiest way is usually to set
117@code{debug-ignored-errors} to @code{nil}. 126@code{debug-ignored-errors} to @code{nil}.
118@end defopt 127@end defopt
119 128
120@defopt eval-expression-debug-on-error 129@defopt eval-expression-debug-on-error
121If this variable has a non-@code{nil} value, then 130If this variable has a non-@code{nil} value (the default), running the
122@code{debug-on-error} is set to @code{t} when evaluating with the 131command @code{eval-expression} causes @code{debug-on-error} to be
123command @code{eval-expression}. If 132temporarily bound to to @code{t}. @xref{Lisp Eval,, Evaluating
124@code{eval-expression-debug-on-error} is @code{nil}, then the value of
125@code{debug-on-error} is not changed. @xref{Lisp Eval,, Evaluating
126Emacs-Lisp Expressions, emacs, The GNU Emacs Manual}. 133Emacs-Lisp Expressions, emacs, The GNU Emacs Manual}.
127@end defopt
128 134
129@defopt debug-on-signal 135If @code{eval-expression-debug-on-error} is @code{nil}, then the value
130Normally, errors that are caught by @code{condition-case} never run the 136of @code{debug-on-error} is not changed during @code{eval-expression}.
131debugger, even if @code{debug-on-error} is non-@code{nil}. In other
132words, @code{condition-case} gets a chance to handle the error before
133the debugger gets a chance.
134
135If you set @code{debug-on-signal} to a non-@code{nil} value, then the
136debugger gets the first chance at every error; an error will invoke the
137debugger regardless of any @code{condition-case}, if it fits the
138criteria specified by the values of @code{debug-on-error} and
139@code{debug-ignored-errors}.
140
141@strong{Warning:} This variable is strong medicine! Various parts of
142Emacs handle errors in the normal course of affairs, and you may not
143even realize that errors happen there. If you set
144@code{debug-on-signal} to a non-@code{nil} value, those errors will
145enter the debugger.
146
147@strong{Warning:} @code{debug-on-signal} has no effect when
148@code{debug-on-error} is @code{nil}.
149@end defopt 137@end defopt
150 138
139@defvar debug-on-signal
140Normally, errors caught by @code{condition-case} never invoke the
141debugger. The @code{condition-case} gets a chance to handle the error
142before the debugger gets a chance.
143
144If you change @code{debug-on-signal} to a non-@code{nil} value, the
145debugger gets the first chance at every error, regardless of the
146presence of @code{condition-case}. (To invoke the debugger, the error
147must still fulfill the criteria specified by @code{debug-on-error} and
148@code{debug-ignored-errors}.)
149
150@strong{Warning:} Setting this variable to non-@code{nil} may have
151annoying effects. Various parts of Emacs catch errors in the normal
152course of affairs, and you may not even realize that errors happen
153there. If you need to debug code wrapped in @code{condition-case},
154consider using @code{condition-case-unless-debug} (@pxref{Handling
155Errors}).
156@end defvar
157
151@defopt debug-on-event 158@defopt debug-on-event
152If you set @code{debug-on-event} to a special event (@pxref{Special 159If you set @code{debug-on-event} to a special event (@pxref{Special
153Events}), Emacs will try to enter the debugger as soon as it receives 160Events}), Emacs will try to enter the debugger as soon as it receives
@@ -171,27 +178,26 @@ init file.
171@cindex stopping an infinite loop 178@cindex stopping an infinite loop
172 179
173 When a program loops infinitely and fails to return, your first 180 When a program loops infinitely and fails to return, your first
174problem is to stop the loop. On most operating systems, you can do this 181problem is to stop the loop. On most operating systems, you can do
175with @kbd{C-g}, which causes a @dfn{quit}. 182this with @kbd{C-g}, which causes a @dfn{quit}. @xref{Quitting}.
176 183
177 Ordinary quitting gives no information about why the program was 184 Ordinary quitting gives no information about why the program was
178looping. To get more information, you can set the variable 185looping. To get more information, you can set the variable
179@code{debug-on-quit} to non-@code{nil}. Quitting with @kbd{C-g} is not 186@code{debug-on-quit} to non-@code{nil}. Once you have the debugger
180considered an error, and @code{debug-on-error} has no effect on the 187running in the middle of the infinite loop, you can proceed from the
181handling of @kbd{C-g}. Likewise, @code{debug-on-quit} has no effect on 188debugger using the stepping commands. If you step through the entire
182errors. 189loop, you may get enough information to solve the problem.
183 190
184 Once you have the debugger running in the middle of the infinite loop, 191 Quitting with @kbd{C-g} is not considered an error, and
185you can proceed from the debugger using the stepping commands. If you 192@code{debug-on-error} has no effect on the handling of @kbd{C-g}.
186step through the entire loop, you will probably get enough information 193Likewise, @code{debug-on-quit} has no effect on errors.
187to solve the problem.
188 194
189@defopt debug-on-quit 195@defopt debug-on-quit
190This variable determines whether the debugger is called when @code{quit} 196This variable determines whether the debugger is called when
191is signaled and not handled. If @code{debug-on-quit} is non-@code{nil}, 197@code{quit} is signaled and not handled. If @code{debug-on-quit} is
192then the debugger is called whenever you quit (that is, type @kbd{C-g}). 198non-@code{nil}, then the debugger is called whenever you quit (that
193If @code{debug-on-quit} is @code{nil}, then the debugger is not called 199is, type @kbd{C-g}). If @code{debug-on-quit} is @code{nil} (the
194when you quit. @xref{Quitting}. 200default), then the debugger is not called when you quit.
195@end defopt 201@end defopt
196 202
197@node Function Debugging 203@node Function Debugging
@@ -337,8 +343,8 @@ that exiting that frame will call the debugger again. This is useful
337for examining the return value of a function. 343for examining the return value of a function.
338 344
339 If a function name is underlined, that means the debugger knows 345 If a function name is underlined, that means the debugger knows
340where its source code is located. You can click @kbd{Mouse-2} on that 346where its source code is located. You can click with the mouse on
341name, or move to it and type @key{RET}, to visit the source code. 347that name, or move to it and type @key{RET}, to visit the source code.
342 348
343 The debugger itself must be run byte-compiled, since it makes 349 The debugger itself must be run byte-compiled, since it makes
344assumptions about how many stack frames are used for the debugger 350assumptions about how many stack frames are used for the debugger
@@ -364,14 +370,10 @@ to step through a primitive function.
364 370
365@table @kbd 371@table @kbd
366@item c 372@item c
367Exit the debugger and continue execution. When continuing is possible, 373Exit the debugger and continue execution. This resumes execution of
368it resumes execution of the program as if the debugger had never been 374the program as if the debugger had never been entered (aside from any
369entered (aside from any side-effects that you caused by changing 375side-effects that you caused by changing variable values or data
370variable values or data structures while inside the debugger). 376structures while inside the debugger).
371
372Continuing is possible after entry to the debugger due to function entry
373or exit, explicit invocation, or quitting. You cannot continue if the
374debugger was entered because of an error.
375 377
376@item d 378@item d
377Continue execution, but enter the debugger the next time any Lisp 379Continue execution, but enter the debugger the next time any Lisp
@@ -790,29 +792,3 @@ never return. If it ever does return, you get a run-time error.
790 Edebug also has a coverage testing feature (@pxref{Coverage 792 Edebug also has a coverage testing feature (@pxref{Coverage
791Testing}). These features partly duplicate each other, and it would 793Testing}). These features partly duplicate each other, and it would
792be cleaner to combine them. 794be cleaner to combine them.
793
794@node Compilation Errors
795@section Debugging Problems in Compilation
796@cindex debugging byte compilation problems
797
798 When an error happens during byte compilation, it is normally due to
799invalid syntax in the program you are compiling. The compiler prints a
800suitable error message in the @samp{*Compile-Log*} buffer, and then
801stops. The message may state a function name in which the error was
802found, or it may not. Either way, here is how to find out where in the
803file the error occurred.
804
805 What you should do is switch to the buffer @w{@samp{ *Compiler Input*}}.
806(Note that the buffer name starts with a space, so it does not show
807up in @kbd{M-x list-buffers}.) This buffer contains the program being
808compiled, and point shows how far the byte compiler was able to read.
809
810 If the error was due to invalid Lisp syntax, point shows exactly where
811the invalid syntax was @emph{detected}. The cause of the error is not
812necessarily near by! Use the techniques in the previous section to find
813the error.
814
815 If the error was detected while compiling a form that had been read
816successfully, then point is located at the end of the form. In this
817case, this technique can't localize the error precisely, but can still
818show you which function to check.