comparison lispref/edebug.texi @ 7252:2ddb8063f154

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Sun, 01 May 1994 09:17:11 +0000
parents fa8ff07eaafc
children 2d4db32cccd5
comparison
equal deleted inserted replaced
7251:02cc4eee5928 7252:2ddb8063f154
5 @c Manual, edebug.tex, in which case the Edebug node below should be used 5 @c Manual, edebug.tex, in which case the Edebug node below should be used
6 @c with the following links to the Bugs section and to the top level: 6 @c with the following links to the Bugs section and to the top level:
7 7
8 @c , Bugs and Todo List, Top, Top 8 @c , Bugs and Todo List, Top, Top
9 9
10 @node Edebug, Bugs and Todo List, Top, Top 10 @node Edebug,, Compilation Errors, Debugging
11 @section Edebug 11 @section Edebug
12 @cindex Edebug mode 12 @cindex Edebug mode
13 13
14 @cindex Edebug 14 @cindex Edebug
15 Edebug is a source-level debugger for Emacs Lisp programs with which 15 Edebug is a source-level debugger for Emacs Lisp programs with which
150 @node Instrumenting 150 @node Instrumenting
151 @subsection Instrumenting for Edebug 151 @subsection Instrumenting for Edebug
152 152
153 In order to use Edebug to debug Lisp code, you must first 153 In order to use Edebug to debug Lisp code, you must first
154 @dfn{instrument} the code. Instrumenting code inserts additional code 154 @dfn{instrument} the code. Instrumenting code inserts additional code
155 into it, code which invokes Edebug at the proper places. 155 into it, to invoke Edebug at the proper places.
156
157 Once a function is instrumented, any call to the function activates
158 Edebug. This may or may not stop execution, depending on the Edebug
159 execution mode in use. Some Edebug modes only update the display to
160 indicate the progress of the evaluation without stopping execution.
161 156
162 @kindex C-M-x 157 @kindex C-M-x
163 @findex eval-defun (Edebug) 158 @findex eval-defun (Edebug)
164 Once you have loaded Edebug, the command @kbd{C-M-x} 159 Once you have loaded Edebug, the command @kbd{C-M-x}
165 (@code{eval-defun}) is redefined so that when invoked with a prefix 160 (@code{eval-defun}) is redefined so that when invoked with a prefix
215 must tell it; @xref{Instrumenting Macro Calls}, for details. 210 must tell it; @xref{Instrumenting Macro Calls}, for details.
216 211
217 @findex eval-expression (Edebug) 212 @findex eval-expression (Edebug)
218 To remove instrumentation from a definition, simply reevaluate its 213 To remove instrumentation from a definition, simply reevaluate its
219 definition in a way that does not instrument. There are two ways of 214 definition in a way that does not instrument. There are two ways of
220 evaluating forms without instrumenting them: from a file with 215 evaluating forms that never instrument them: from a file with
221 @code{load}, and from the minibuffer with @code{eval-expression} 216 @code{load}, and from the minibuffer with @code{eval-expression}
222 (@kbd{M-ESC}). 217 (@kbd{M-ESC}).
223 218
224 If Edebug detects a syntax error while instrumenting, it leaves point 219 If Edebug detects a syntax error while instrumenting, it leaves point
225 at the erroneous code and signals an @code{invalid-read-syntax} error. 220 at the erroneous code and signals an @code{invalid-read-syntax} error.
231 @subsection Edebug Execution Modes 226 @subsection Edebug Execution Modes
232 227
233 @cindex Edebug execution modes 228 @cindex Edebug execution modes
234 Edebug supports several execution modes for running the program you are 229 Edebug supports several execution modes for running the program you are
235 debugging. We call these alternatives @dfn{Edebug execution modes}; do 230 debugging. We call these alternatives @dfn{Edebug execution modes}; do
236 not confuse them with major or minor modes. The current Edebug mode 231 not confuse them with major or minor modes. The current Edebug execution mode
237 determines how far Edebug continues execution before stopping---whether 232 determines how far Edebug continues execution before stopping---whether
238 it stops at each stop point, or continues to the next breakpoint, for 233 it stops at each stop point, or continues to the next breakpoint, for
239 example---and how much Edebug displays the progress of the evaluation 234 example---and how much Edebug displays the progress of the evaluation
240 before it stops. 235 before it stops.
241 236
279 Go non-stop: ignore breakpoints (@code{edebug-Go-nonstop-mode}). You 274 Go non-stop: ignore breakpoints (@code{edebug-Go-nonstop-mode}). You
280 can still stop the program by typing @kbd{S}, or any editing command. 275 can still stop the program by typing @kbd{S}, or any editing command.
281 @end table 276 @end table
282 277
283 In general, the execution modes earlier in the above list run the 278 In general, the execution modes earlier in the above list run the
284 program more slowly or stop sooner. 279 program more slowly or stop sooner than the modes later in the list.
285 280
286 While executing or tracing, you can interrupt the execution by typing 281 While executing or tracing, you can interrupt the execution by typing
287 any Edebug command. Edebug stops the program at the next stop point and 282 any Edebug command. Edebug stops the program at the next stop point and
288 then executes the command that you typed. For example, typing @kbd{t} 283 then executes the command you typed. For example, typing @kbd{t} during
289 during execution switches to trace mode at the next stop point. You can 284 execution switches to trace mode at the next stop point. You can use
290 use @kbd{S} to stop execution without doing anything else. 285 @kbd{S} to stop execution without doing anything else.
291 286
292 If your function happens to read input, a character you type intending 287 If your function happens to read input, a character you type intending
293 to interrupt execution may be read by the function instead. You can 288 to interrupt execution may be read by the function instead. You can
294 avoid such unintended results by paying attention to when your program 289 avoid such unintended results by paying attention to when your program
295 wants input. 290 wants input.
360 expression @emph{from the current stop point}, type @kbd{w} first, to 355 expression @emph{from the current stop point}, type @kbd{w} first, to
361 move point there, and then type @kbd{f}. 356 move point there, and then type @kbd{f}.
362 357
363 The @kbd{o} command continues ``out of'' an expression. It places a 358 The @kbd{o} command continues ``out of'' an expression. It places a
364 temporary breakpoint at the end of the sexp containing point. If the 359 temporary breakpoint at the end of the sexp containing point. If the
365 containing sexp is a function definition itself, it continues until just 360 containing sexp is a function definition itself, @kbd{o} continues until
366 before the last sexp in the definition. If that is where you are now, 361 just before the last sexp in the definition. If that is where you are
367 it returns from the function and then stops. In other words, this 362 now, it returns from the function and then stops. In other words, this
368 command does not exit the currently executing function unless you are 363 command does not exit the currently executing function unless you are
369 positioned after the last sexp. 364 positioned after the last sexp.
370 365
371 The @kbd{i} command steps into the function or macro called by the list 366 The @kbd{i} command steps into the function or macro called by the list
372 form after point. Note that the form need not be the one about to be 367 form after point, and stops at its first stop point. Note that the form
373 evaluated. But if the form is a function call about to be evaluated, 368 need not be the one about to be evaluated. But if the form is a
374 remember to use this command before any of the arguments are evaluated, 369 function call about to be evaluated, remember to use this command before
375 since otherwise it will be too late. 370 any of the arguments are evaluated, since otherwise it will be too late.
376 371
377 The @kbd{i} command instruments the function or macro it's supposed to 372 The @kbd{i} command instruments the function or macro it's supposed to
378 step into, if it isn't instrumented already. This is convenient, but keep 373 step into, if it isn't instrumented already. This is convenient, but keep
379 in mind that the function or macro remains instrumented unless you explicitly 374 in mind that the function or macro remains instrumented unless you explicitly
380 arrange to deinstrument it. 375 arrange to deinstrument it.
416 411
417 The backtrace buffer is killed automatically when you continue 412 The backtrace buffer is killed automatically when you continue
418 execution. 413 execution.
419 @end table 414 @end table
420 415
421 >From the Edebug recursive edit, you may invoke commands that activate 416 From the Edebug recursive edit, you may invoke commands that activate
422 Edebug again recursively. Any time Edebug is active, you can quit to 417 Edebug again recursively. Any time Edebug is active, you can quit to
423 the top level with @kbd{q} or abort one recursive edit level with 418 the top level with @kbd{q} or abort one recursive edit level with
424 @kbd{C-]}. You can display a backtrace of all the 419 @kbd{C-]}. You can display a backtrace of all the
425 pending evaluations with @kbd{d}. 420 pending evaluations with @kbd{d}.
426 421
483 478
484 Edebug always stops or pauses at a breakpoint except when the Edebug 479 Edebug always stops or pauses at a breakpoint except when the Edebug
485 mode is Go-nonstop. In that mode, it ignores breakpoints entirely. 480 mode is Go-nonstop. In that mode, it ignores breakpoints entirely.
486 481
487 To find out where your breakpoints are, use the @kbd{B} command, which 482 To find out where your breakpoints are, use the @kbd{B} command, which
488 moves point to the next breakpoint in the definition following point, or 483 moves point to the next breakpoint following point, within the same
489 to the first breakpoint if there are no following breakpoints. This 484 function, or to the first breakpoint if there are no following
490 command does not continue execution---it just moves point in the buffer. 485 breakpoints. This command does not continue execution---it just moves
486 point in the buffer.
491 487
492 @menu 488 @menu
493 * Global Break Condition:: Breaking on an event. 489 * Global Break Condition:: Breaking on an event.
494 * Source Breakpoints:: Embedding breakpoints in source code. 490 * Source Breakpoints:: Embedding breakpoints in source code.
495 @end menu 491 @end menu
559 function which was not instrumented, within which the error actually 555 function which was not instrumented, within which the error actually
560 occurred. For an unbound variable error, the last known stop point 556 occurred. For an unbound variable error, the last known stop point
561 might be quite distant from the offending variable reference. In that 557 might be quite distant from the offending variable reference. In that
562 case you might want to display a full backtrace (@pxref{Edebug Misc}). 558 case you might want to display a full backtrace (@pxref{Edebug Misc}).
563 559
560 @c Edebug should be changed for the following: -- dan
564 If you change @code{debug-on-error} or @code{debug-on-quit} while 561 If you change @code{debug-on-error} or @code{debug-on-quit} while
565 Edebug is active, these changes will be forgotten when Edebug becomes 562 Edebug is active, these changes will be forgotten when Edebug becomes
566 inactive. Furthermore, during Edebug's recursive edit, these variables 563 inactive. Furthermore, during Edebug's recursive edit, these variables
567 are bound to the values they had outside of Edebug. 564 are bound to the values they had outside of Edebug.
568 565
569 @ignore @c I don't want to document something that works only partly -- rms.
570 Edebug can also trap signals even if they are handled. If
571 @code{debug-on-error} is a list of signal names, Edebug will stop when
572 any of these errors are signaled. Edebug shows you the last known stop
573 point just as for unhandled errors. After you continue execution, the
574 error is signaled again (but without being caught by Edebug). Edebug
575 can only trap errors that are handled if they are signaled in Lisp code
576 (not subroutines) since it does so by temporarily replacing the
577 @code{signal} function.
578 @end ignore
579
580 @node Edebug Views 566 @node Edebug Views
581 @subsection Edebug Views 567 @subsection Edebug Views
582 568
583 These Edebug commands let you view aspects of the buffer and window 569 These Edebug commands let you view aspects of the buffer and window
584 status that obtained before entry to Edebug. 570 status that obtained before entry to Edebug. The outside window
571 configuration is the collection of windows and contents that were in
572 effect outside of Edebug.
585 573
586 @table @kbd 574 @table @kbd
587 @item v 575 @item v
588 View the outside window configuration (@code{edebug-view-outside}). 576 Temporarily view the outside window configuration
577 (@code{edebug-view-outside}).
589 578
590 @item p 579 @item p
591 Temporarily display the outside current buffer with point at its outside 580 Temporarily display the outside current buffer with point at its outside
592 position (@code{edebug-bounce-point}). With a prefix argument @var{n}, 581 position (@code{edebug-bounce-point}). With a prefix argument @var{n},
593 pause for @var{n} seconds instead. 582 pause for @var{n} seconds instead.
597 source code buffer. Also, if you use this command in a different window 586 source code buffer. Also, if you use this command in a different window
598 displaying the same buffer, that window will be used instead to display 587 displaying the same buffer, that window will be used instead to display
599 the current definition in the future. 588 the current definition in the future.
600 589
601 @item W 590 @item W
602 Forget the saved outside window configuration---so that the current 591 @c Its function is not simply to forget the saved configuration -- dan
603 window configuration will remain unchanged when you next exit Edebug (by 592 Toggle whether Edebug saves and restores the outside window
604 continuing the program). Also toggle the @code{edebug-save-windows} 593 configuration (@code{edebug-toggle-save-windows}).
605 variable. 594
606 @ignore @c This text is implementation-oriented and doesn't emphasize 595 With a prefix argument, @code{W} only toggles saving and restoring of
607 what users really want to know. 596 the selected window. To specify a window that is not displaying the
608 Toggle the @code{edebug-save-windows} variable which indicates whether 597 source code buffer, you must use @kbd{C-x X W} from the global keymap.
609 the outside window configuration is saved and restored
610 (@code{edebug-toggle-save-windows}). Also, each time it is toggled on,
611 make the outside window configuration the same as the current window
612 configuration.
613 @end ignore
614 @end table 598 @end table
615 599
616 You can view the outside window configuration with @kbd{v} or just 600 You can view the outside window configuration with @kbd{v} or just
617 bounce to the point in the current buffer with @kbd{p}, even if 601 bounce to the point in the current buffer with @kbd{p}, even if
618 it is not normally displayed. After moving point, you may wish to jump 602 it is not normally displayed. After moving point, you may wish to jump
619 back to the stop point with @kbd{w} from a source code buffer. 603 back to the stop point with @kbd{w} from a source code buffer.
620 604
621 @ignore I don't understand this -- rms 605 Each time you use @kbd{W} to turn saving @emph{off}, Edebug forgets the
622 If you type @kbd{W} twice, Edebug continues saving and restoring an 606 saved outside window configuration---so that even if you turn saving
623 outside window configuration, but updates it to match the current 607 back @emph{on}, the current window configuration remains unchanged when
624 configuration. You can use this to add another buffer to be displayed 608 you next exit Edebug (by continuing the program). However, the
625 whenever Edebug is active. However, the automatic redisplay of 609 automatic redisplay of @samp{*edebug*} and @samp{*edebug-trace*} may
626 @samp{*edebug*} and @samp{*edebug-trace*} may conflict with the buffers 610 conflict with the buffers you wish to see unless you have enough windows
627 you wish to see unless you have enough windows open. 611 open.
628
629 With a prefix argument, @code{W} only toggles saving and restoring of
630 the selected window. To specify a window that is not displaying the
631 source code buffer, you must use @kbd{C-x X W} from the global keymap.
632 @end ignore
633 612
634 @node Edebug Eval 613 @node Edebug Eval
635 @subsection Evaluation 614 @subsection Evaluation
636 615
637 While within Edebug, you can evaluate expressions ``as if'' Edebug were 616 While within Edebug, you can evaluate expressions ``as if'' Edebug were
688 @item C-x C-e 667 @item C-x C-e
689 Evaluate the expression before point, in the context outside of Edebug 668 Evaluate the expression before point, in the context outside of Edebug
690 (@code{edebug-eval-last-sexp}). 669 (@code{edebug-eval-last-sexp}).
691 670
692 @item C-c C-u 671 @item C-c C-u
693 Build a new evaluation list from contents of the buffer 672 Build a new evaluation list from the contents of the buffer
694 (@code{edebug-update-eval-list}). 673 (@code{edebug-update-eval-list}).
695 674
696 @item C-c C-d 675 @item C-c C-d
697 Delete the evaluation list group that point is in 676 Delete the evaluation list group that point is in
698 (@code{edebug-delete-eval-item}). 677 (@code{edebug-delete-eval-item}).
715 evaluation list buffer. An evaluation list group consists of one or 694 evaluation list buffer. An evaluation list group consists of one or
716 more Lisp expressions. Groups are separated by comment lines. 695 more Lisp expressions. Groups are separated by comment lines.
717 696
718 The command @kbd{C-c C-u} (@code{edebug-update-eval-list}) rebuilds the 697 The command @kbd{C-c C-u} (@code{edebug-update-eval-list}) rebuilds the
719 evaluation list, scanning the buffer and using the first expression of 698 evaluation list, scanning the buffer and using the first expression of
720 each group. 699 each group. (The idea is that the second expression of the group is the
700 value previously computed and displayed.)
721 701
722 Be careful not to add expressions that execute instrumented code since 702 Be careful not to add expressions that execute instrumented code since
723 that would cause an infinite loop. 703 that would cause an infinite loop.
724 @c There ought to be a way to fix this. 704 @c There ought to be a way to fix this.
725 705
726 Redisplaying the evaluation list works by inserting each expression in 706 Each entry to Edebug redisplays the evaluation list by inserting each
727 the buffer, followed by its current value. It also inserts comment 707 expression in the buffer, followed by its current value. It also
728 lines so that each expression becomes its own group. Thus, if you type 708 inserts comment lines so that each expression becomes its own group.
729 @kbd{C-c C-u} again without changing the buffer text, the evaluation 709 Thus, if you type @kbd{C-c C-u} again without changing the buffer text,
730 list is effectively unchanged. 710 the evaluation list is effectively unchanged.
731 711
732 If an error occurs during an evaluation from the evaluation list, the 712 If an error occurs during an evaluation from the evaluation list, the
733 error message is displayed in a string as if it were the result. 713 error message is displayed in a string as if it were the result.
734 Therefore, expressions that use variables not currently valid do not 714 Therefore, expressions that use variables not currently valid do not
735 interrupt your debugging. 715 interrupt your debugging.
815 795
816 @node Trace Buffer 796 @node Trace Buffer
817 @subsection Trace Buffer 797 @subsection Trace Buffer
818 @cindex trace buffer 798 @cindex trace buffer
819 799
820 Edebug can record an execution trace in a buffer named 800 Edebug can record an execution trace, storing it in a buffer named
821 @samp{*edebug-trace*}. This is a log of function calls and returns, 801 @samp{*edebug-trace*}. This is a log of function calls and returns,
822 showing the function names and their arguments and values. To enable 802 showing the function names and their arguments and values. To enable
823 trace recording, set @code{edebug-trace} to a non-@code{nil} value. 803 trace recording, set @code{edebug-trace} to a non-@code{nil} value.
824 804
825 Making a trace buffer is not the same thing as using trace execution 805 Making a trace buffer is not the same thing as using trace execution
849 @end defmac 829 @end defmac
850 830
851 @defun edebug-trace format-string &rest format-args 831 @defun edebug-trace format-string &rest format-args
852 This function inserts text in the trace buffer. It computes the text 832 This function inserts text in the trace buffer. It computes the text
853 with @code{(apply 'format @var{format-string} @var{format-args})}. 833 with @code{(apply 'format @var{format-string} @var{format-args})}.
854 It also inserts a newline to separate entries. 834 It also appends a newline to separate entries.
855 @end defun 835 @end defun
856 836
857 @code{edebug-tracing} and @code{edebug-trace} insert lines in the trace 837 @code{edebug-tracing} and @code{edebug-trace} insert lines in the trace
858 buffer even if Edebug is not active. 838 buffer even if Edebug is not active.
859 839
860 Adding text to the trace buffer also scrolls its window to show the 840 Adding text to the trace buffer also scrolls its window to show the
861 last lines inserted. 841 last lines inserted.
862
863 @ignore @c too vague
864 There may be some display problems if you use
865 tracing along with the evaluation list.
866 @end ignore
867 842
868 @node Coverage Testing 843 @node Coverage Testing
869 @subsection Coverage Testing 844 @subsection Coverage Testing
870 845
871 @cindex coverage testing 846 @cindex coverage testing
881 856
882 @deffn Command edebug-display-freq-count 857 @deffn Command edebug-display-freq-count
883 This command displays the frequency count data for each line of the 858 This command displays the frequency count data for each line of the
884 current definition. 859 current definition.
885 860
886 The frequency counts appear comment lines after each line of code, and 861 The frequency counts appear as comment lines after each line of code, and
887 you can undo all insertions with one @code{undo} command. The counts 862 you can undo all insertions with one @code{undo} command. The counts
888 are appear under the @kbd{(} before an expression or the @kbd{)} after 863 appear under the @kbd{(} before an expression or the @kbd{)} after
889 an expression, or on the last character of a symbol. Values do not appear if 864 an expression, or on the last character of a symbol. Values do not appear if
890 they are equal to the previous count on the same line. 865 they are equal to the previous count on the same line.
891 866
892 The character @samp{=} following the count for an expression says that 867 The character @samp{=} following the count for an expression says that
893 the expression has returned the same value each time it was evaluated 868 the expression has returned the same value each time it was evaluated
911 ;# 5 0 886 ;# 5 0
912 1)) 887 1))
913 ;# 0 888 ;# 0
914 @end example 889 @end example
915 890
916 The comment lines show that @code{fac} has been called 6 times. The 891 The comment lines show that @code{fac} was called 6 times. The
917 first @code{if} statement has returned 5 times with the same result each 892 first @code{if} statement returned 5 times with the same result each
918 time; the same is true of the condition on the second @code{if}. 893 time; the same is true of the condition on the second @code{if}.
919 The recursive call of @code{fac} has not returned at all. 894 The recursive call of @code{fac} did not return at all.
920 895
921 896
922 @node The Outside Context 897 @node The Outside Context
923 @subsection The Outside Context 898 @subsection The Outside Context
924 899
927 you evaluate expressions with @kbd{e} or with the evaluation list 902 you evaluate expressions with @kbd{e} or with the evaluation list
928 buffer, by temporarily restoring the outside context. This section 903 buffer, by temporarily restoring the outside context. This section
929 explains precisely what context Edebug restores, and how Edebug fails to 904 explains precisely what context Edebug restores, and how Edebug fails to
930 be completely transparent. 905 be completely transparent.
931 906
932 @c This can be fixed and should be
933 The same mechanism that avoids masking certain variable's outside values
934 also currently makes it impossible to set these variables within Edebug.
935
936 @menu 907 @menu
937 * Checking Whether to Stop:: When Edebug decides what to do. 908 * Checking Whether to Stop:: When Edebug decides what to do.
938 * Edebug Display Update:: When Edebug updates the display. 909 * Edebug Display Update:: When Edebug updates the display.
939 * Edebug Recursive Edit:: When Edebug stops execution. 910 * Edebug Recursive Edit:: When Edebug stops execution.
940 @end menu 911 @end menu
941 912
942 @node Checking Whether to Stop 913 @node Checking Whether to Stop
943 @subsubsection Checking Whether to Stop 914 @subsubsection Checking Whether to Stop
944 915
945 Whenever Edebug is entered just to think about whether to take some 916 Whenever Edebug is entered, it needs to save and restore certain data
946 action, it needs to save and restore certain data. 917 before even deciding whether to make trace information or stop the
918 program.
947 919
948 @itemize @bullet 920 @itemize @bullet
949 @item 921 @item
950 @code{max-lisp-eval-depth} and @code{max-specpdl-size} are both 922 @code{max-lisp-eval-depth} and @code{max-specpdl-size} are both
951 incremented one time to reduce Edebug's impact on the stack. 923 incremented one time to reduce Edebug's impact on the stack.
960 932
961 933
962 @node Edebug Display Update 934 @node Edebug Display Update
963 @subsubsection Edebug Display Update 935 @subsubsection Edebug Display Update
964 936
937 @c This paragraph is not filled, because LaLiberte's conversion script
938 @c needs an xref to be on just one line.
965 When Edebug needs to display something (e.g., in trace mode), it saves 939 When Edebug needs to display something (e.g., in trace mode), it saves
966 the current window configuration from ``outside'' Edebug (@pxref{Window 940 the current window configuration from ``outside'' Edebug
967 Configurations,,, elisp, GNU Emacs Lisp Reference Manual}). When 941 (@pxref{Window Configurations}). When you exit Edebug (by continuing
968 you exit Edebug (by continuing the program), it restores the previous 942 the program), it restores the previous window configuration.
969 window configuration.
970 943
971 Emacs redisplays only when it pauses. Usually, when you continue 944 Emacs redisplays only when it pauses. Usually, when you continue
972 execution, the program comes back into Edebug at a breakpoint or after 945 execution, the program comes back into Edebug at a breakpoint or after
973 stepping without pausing or reading input in between. In such cases, 946 stepping without pausing or reading input in between. In such cases,
974 Emacs never gets a chance to redisplay the ``outside'' configuration. 947 Emacs never gets a chance to redisplay the ``outside'' configuration.
998 971
999 The window start and horizontal scrolling of the source code buffer are 972 The window start and horizontal scrolling of the source code buffer are
1000 not restored, however, so that the display remains coherent within Edebug. 973 not restored, however, so that the display remains coherent within Edebug.
1001 974
1002 @item 975 @item
1003 @vindex edebug-save-displayed-buffer-points
1004 The value of point in each displayed buffer is saved and restored if 976 The value of point in each displayed buffer is saved and restored if
1005 @code{edebug-save-displayed-buffer-points} is non-@code{nil}. 977 @code{edebug-save-displayed-buffer-points} is non-@code{nil}.
1006 978
1007 @item 979 @item
1008 The variables @code{overlay-arrow-position} and 980 The variables @code{overlay-arrow-position} and
1032 Edebug do not affect these variables outside of Edebug. 1004 Edebug do not affect these variables outside of Edebug.
1033 1005
1034 The key sequence returned by @code{this-command-keys} is changed by 1006 The key sequence returned by @code{this-command-keys} is changed by
1035 executing commands within Edebug and there is no way to reset 1007 executing commands within Edebug and there is no way to reset
1036 the key sequence from Lisp. 1008 the key sequence from Lisp.
1009
1010 Edebug cannot save and restore the value of
1011 @code{unread-command-events}. Entering Edebug while this variable has a
1012 nontrivial value can interfere with execution of the program you are
1013 debugging.
1037 1014
1038 @item 1015 @item
1039 Complex commands executed while in Edebug are added to the variable 1016 Complex commands executed while in Edebug are added to the variable
1040 @code{command-history}. In rare cases this can alter execution. 1017 @code{command-history}. In rare cases this can alter execution.
1041 1018
1062 additional advice to do the job properly. This is because there is no 1039 additional advice to do the job properly. This is because there is no
1063 way to tell which subexpressions of the macro call are forms to be 1040 way to tell which subexpressions of the macro call are forms to be
1064 evaluated. (Evaluation may occur explicitly in the macro body, or when 1041 evaluated. (Evaluation may occur explicitly in the macro body, or when
1065 the resulting expansion is evaluated, or any time later.) You must 1042 the resulting expansion is evaluated, or any time later.) You must
1066 explain the format of calls to each macro to enable Edebug to handle it. 1043 explain the format of calls to each macro to enable Edebug to handle it.
1067 To do this, use @code{def-edebug-form-spec} to define the format of 1044 To do this, use @code{def-edebug-spec} to define the format of
1068 calls to a given macro. 1045 calls to a given macro.
1069 1046
1070 @deffn Macro def-edebug-spec macro specification 1047 @deffn Macro def-edebug-spec macro specification
1071 Specify which expressions of a call to macro @var{macro} are forms to be 1048 Specify which expressions of a call to macro @var{macro} are forms to be
1072 evaluated. For simple macros, the @var{specification} often looks very 1049 evaluated. For simple macros, the @var{specification} often looks very
1112 @end table 1089 @end table
1113 1090
1114 @menu 1091 @menu
1115 * Specification List:: How to specify complex patterns of evaluation. 1092 * Specification List:: How to specify complex patterns of evaluation.
1116 * Backtracking:: What Edebug does when matching fails. 1093 * Backtracking:: What Edebug does when matching fails.
1117 @c * Debugging Backquote:: Debugging Backquote
1118 * Specification Examples:: To help understand specifications. 1094 * Specification Examples:: To help understand specifications.
1119 @end menu 1095 @end menu
1120 1096
1121 1097
1122 @node Specification List 1098 @node Specification List
1148 Here's a table of the possible elements of a specification list, with 1124 Here's a table of the possible elements of a specification list, with
1149 their meanings: 1125 their meanings:
1150 1126
1151 @table @code 1127 @table @code
1152 @item sexp 1128 @item sexp
1153 A single unevaluated Lisp object object. 1129 A single Lisp object, not unevaluated.
1130 @c "unevaluated expression" is not meaningful, because
1131 @c an expression is a Lisp object intended for evaluation.
1154 1132
1155 @item form 1133 @item form
1156 A single evaluated expression, which is instrumented. 1134 A single evaluated expression, which is instrumented.
1157 1135
1158 @item place 1136 @item place
1244 1222
1245 Otherwise, the symbol should be a predicate. The predicate is called 1223 Otherwise, the symbol should be a predicate. The predicate is called
1246 with the argument and the specification fails if the predicate returns 1224 with the argument and the specification fails if the predicate returns
1247 @code{nil}. In either case, that argument is not instrumented. 1225 @code{nil}. In either case, that argument is not instrumented.
1248 1226
1249 @findex keywordp
1250 @findex lambda-list-keywordp
1251 Some suitable predicates include @code{symbolp}, @code{integerp}, 1227 Some suitable predicates include @code{symbolp}, @code{integerp},
1252 @code{stringp}, @code{vectorp}, and @code{atom}. 1228 @code{stringp}, @code{vectorp}, and @code{atom}.
1253 @ignore
1254 , @code{keywordp}, and
1255 @code{lambda-list-keywordp}. The last two, defined in @file{edebug.el},
1256 test whether the argument is a symbol starting with @samp{@code{:}} and
1257 @samp{@code{&}} respectively.
1258 @end ignore
1259 1229
1260 @item [@var{elements}@dots{}] 1230 @item [@var{elements}@dots{}]
1261 @cindex [@dots{}] (Edebug) 1231 @cindex [@dots{}] (Edebug)
1262 A vector of elements groups the elements into a single @dfn{group 1232 A vector of elements groups the elements into a single @dfn{group
1263 specification}. Its meaning has nothing to do with vectors. 1233 specification}. Its meaning has nothing to do with vectors.
1264 1234
1265 @item "@var{string}" 1235 @item "@var{string}"
1266 The argument should be a symbol named @var{string}. This specification 1236 The argument should be a symbol named @var{string}. This specification
1267 is equivalent to the quoted symbol, @code{'@var{symbol}}, where the name 1237 is equivalent to the quoted symbol, @code{'@var{symbol}}, where the name
1268 of @var{symbol} is the @var{string}, but the string form is preferred. 1238 of @var{symbol} is the @var{string}, but the string form is preferred.
1269
1270 @ignore
1271 @item '@var{symbol} @r{or} (quote @var{symbol})
1272 The argument should be the symbol @var{symbol}. But use a string
1273 specification instead.
1274 @end ignore
1275 1239
1276 @item (vector @var{elements}@dots{}) 1240 @item (vector @var{elements}@dots{})
1277 The argument should be a vector whose elements must match the 1241 The argument should be a vector whose elements must match the
1278 @var{elements} in the specification. See the backquote example below. 1242 @var{elements} in the specification. See the backquote example below.
1279 1243
1289 specs@dots{})])}) whose elements match the non-dotted list arguments. 1253 specs@dots{})])}) whose elements match the non-dotted list arguments.
1290 This is useful in recursive specifications such as in the backquote 1254 This is useful in recursive specifications such as in the backquote
1291 example below. Also see the description of a @code{nil} specification 1255 example below. Also see the description of a @code{nil} specification
1292 above for terminating such recursion. 1256 above for terminating such recursion.
1293 1257
1294 Note that a sublist specification of the form @code{(specs . nil)} 1258 Note that a sublist specification written as @code{(specs . nil)}
1295 means the same as @code{(specs)}, and @code{(specs . 1259 is equivalent to @code{(specs)}, and @code{(specs .
1296 (sublist-elements@dots{}))} means the same as @code{(specs 1260 (sublist-elements@dots{}))} is equivalent to @code{(specs
1297 sublist-elements@dots{})}. 1261 sublist-elements@dots{})}.
1298 @end table 1262 @end table
1299 1263
1300 @c Need to document extensions with &symbol and :symbol 1264 @c Need to document extensions with &symbol and :symbol
1301 1265
1317 than once. 1281 than once.
1318 1282
1319 @item arg 1283 @item arg
1320 The argument, a symbol, is the name of an argument of the defining form. 1284 The argument, a symbol, is the name of an argument of the defining form.
1321 However, lambda list keywords (symbols starting with @samp{@code{&}}) 1285 However, lambda list keywords (symbols starting with @samp{@code{&}})
1322 are not allowed. See @code{lambda-list} and the example below. 1286 are not allowed.
1323 1287
1324 @item lambda-list 1288 @item lambda-list
1325 @cindex lambda-list (Edebug) 1289 @cindex lambda-list (Edebug)
1326 This matches a lambda list---the argument list of a lambda expression. 1290 This matches a lambda list---the argument list of a lambda expression.
1327 The argument should be a list of symbols.
1328 1291
1329 @item def-body 1292 @item def-body
1330 The argument is the body of code in a definition. This is like 1293 The argument is the body of code in a definition. This is like
1331 @code{body}, described above, but a definition body must be instrumented 1294 @code{body}, described above, but a definition body must be instrumented
1332 with a different Edebug call that looks up information associated with 1295 with a different Edebug call that looks up information associated with
1378 1341
1379 Third, backtracking may be explicitly disabled by using the 1342 Third, backtracking may be explicitly disabled by using the
1380 @code{gate} specification. This is useful when you know that 1343 @code{gate} specification. This is useful when you know that
1381 no higher alternatives may apply. 1344 no higher alternatives may apply.
1382 1345
1383 @ignore
1384 @node Debugging Backquote
1385 @subsubsection Debugging Backquote
1386
1387 @findex ` (Edebug)
1388 @cindex backquote (Edebug)
1389 Backquote (@kbd{`}) is a macro that results in an expression that may or
1390 may not be evaluated. It is often used to simplify the definition of a
1391 macro to return an expression to be evaluated, but Edebug cannot know
1392 whether the resyult of backquote will be used in any other way.
1393
1394 The forms inside unquotes (@code{,} and @code{,@@}) are evaluated, and
1395 Edebug instruments them.
1396
1397 Edebug supports nested backquotes, but there is a limit on the support
1398 of quotes inside of backquotes. Forms quoted with @code{'} are not
1399 normally evaluated, but if the quoted form appears immediately within
1400 @code{,} and @code{,@@} forms, Edebug treats this as a backquoted form
1401 at the next higher level (even if there is not a next higher level; this
1402 is difficult to fix).
1403
1404 @findex edebug-`
1405 If the backquoted forms are code to be evaluated, you can have Edebug
1406 instrument them by using @code{edebug-`} instead of the regular
1407 @code{`}. Unquoting forms can be used inside @code{edebug-`} anywhere a
1408 form is normally allowed. But @code{(, @var{form})} may be used in two
1409 other places specially recognized by Edebug: wherever a predicate
1410 specification would match, and at the head of a list form where the
1411 function name normally appears. The @var{form} inside a spliced
1412 unquote, @code{(,@@ @var{form})}, will be instrumented, but the unquote
1413 form itself will not be instrumented since this would interfere with the
1414 splicing.
1415
1416 There is one other complication with using @code{edebug-`}. If the
1417 @code{edebug-`} call is in a macro and the macro may be called from code
1418 that is also instrumented, and if unquoted forms contain any macro
1419 arguments bound to instrumented forms, then you should modify the
1420 specification for the macro as follows: the specifications for those
1421 arguments must use @code{def-form} instead of @code{form}. (This is to
1422 reestablish the Edebugging context for those external forms.)
1423
1424 For example, the @code{for} macro (@pxref{Problems with Macros,,, elisp,
1425 Emacs Lisp Reference Manual}) is shown here but with @code{edebug-`}
1426 substituted for regular @code{`}.
1427
1428 @example
1429 (defmacro inc (var)
1430 (list 'setq var (list '1+ var)))
1431
1432 (defmacro for (var from init to final do &rest body)
1433 (let ((tempvar (make-symbol "max")))
1434 (edebug-` (let (((, var) (, init))
1435 ((, tempvar) (, final)))
1436 (while (<= (, var) (, tempvar))
1437 (,@ body)
1438 (inc (, var)))))))
1439 @end example
1440
1441 Here is the corresponding modified Edebug specification and a
1442 call of the macro:
1443
1444 @example
1445 (def-edebug-spec for
1446 (symbolp "from" def-form "to" def-form "do" &rest def-form))
1447
1448 (let ((n 5))
1449 (for i from n to (* n (+ n 1)) do
1450 (message "%s" i)))
1451 @end example
1452
1453 After instrumenting the @code{for} macro and the macro call, Edebug
1454 first steps to the beginning of the macro call, then into the macro
1455 body, then through each of the unquoted expressions in the backquote
1456 showing the expressions that will be embedded. Then when the macro
1457 expansion is evaluated, Edebug will step through the @code{let} form and
1458 each time it gets to an unquoted form, it will jump back to an argument
1459 of the macro call to step through that expression. Finally stepping
1460 will continue after the macro call. Even more convoluted execution
1461 paths may result when using anonymous functions.
1462
1463 @vindex edebug-unwrap-results
1464 When the result of an expression is an instrumented expression, it is
1465 difficult to see the expression inside the instrumentation. So
1466 you may want to set the option @code{edebug-unwrap-results} to a
1467 non-@code{nil} value while debugging such expressions, but it would slow
1468 Edebug down to always do this.
1469
1470 @end ignore
1471 @node Specification Examples 1346 @node Specification Examples
1472 @subsubsection Specification Examples 1347 @subsubsection Specification Examples
1473 1348
1474 It may be easier to understand Edebug specifications by studying 1349 It may be easier to understand Edebug specifications by studying
1475 the examples provided here. 1350 the examples provided here.
1490 @code{defmacro} and the associated argument list and @code{interactive} 1365 @code{defmacro} and the associated argument list and @code{interactive}
1491 specifications. It is necessary to handle interactive forms specially 1366 specifications. It is necessary to handle interactive forms specially
1492 since an expression argument it is actually evaluated outside of the 1367 since an expression argument it is actually evaluated outside of the
1493 function body. 1368 function body.
1494 1369
1495 @example 1370 @smallexample
1496 (def-edebug-spec defmacro defun) ; @r{Indirect ref to @code{defun} spec} 1371 (def-edebug-spec defmacro defun) ; @r{Indirect ref to @code{defun} spec.}
1497 (def-edebug-spec defun 1372 (def-edebug-spec defun
1498 (&define name lambda-list 1373 (&define name lambda-list
1499 [&optional stringp] ; @r{Match the doc string, if present.} 1374 [&optional stringp] ; @r{Match the doc string, if present.}
1500 [&optional ("interactive" interactive)] 1375 [&optional ("interactive" interactive)]
1501 def-body)) 1376 def-body))
1502 1377
1503 (def-edebug-spec lambda-list 1378 (def-edebug-spec lambda-list
1504 (([&rest arg] 1379 (([&rest arg]
1506 &optional ["&rest" arg] 1381 &optional ["&rest" arg]
1507 ))) 1382 )))
1508 1383
1509 (def-edebug-spec interactive 1384 (def-edebug-spec interactive
1510 (&optional &or stringp def-form)) ; @r{Notice: @code{def-form}} 1385 (&optional &or stringp def-form)) ; @r{Notice: @code{def-form}}
1511 @end example 1386 @end smallexample
1512 1387
1513 The specification for backquote below illustrates how to match 1388 The specification for backquote below illustrates how to match
1514 dotted lists and use @code{nil} to terminate recursion. It also 1389 dotted lists and use @code{nil} to terminate recursion. It also
1515 illustrates how components of a vector may be matched. (The actual 1390 illustrates how components of a vector may be matched. (The actual
1516 specification defined by Edebug does not support dotted lists because 1391 specification defined by Edebug does not support dotted lists because
1517 doing so causes very deep recursion that could fail.) 1392 doing so causes very deep recursion that could fail.)
1518 1393
1519 @example 1394 @smallexample
1520 (def-edebug-spec ` (backquote-form)) ;; alias just for clarity 1395 (def-edebug-spec ` (backquote-form)) ; @r{Alias just for clarity.}
1521 1396
1522 (def-edebug-spec backquote-form 1397 (def-edebug-spec backquote-form
1523 (&or ([&or "," ",@@"] &or ("quote" backquote-form) form) 1398 (&or ([&or "," ",@@"] &or ("quote" backquote-form) form)
1524 (backquote-form . [&or nil backquote-form]) 1399 (backquote-form . [&or nil backquote-form])
1525 (vector &rest backquote-form) 1400 (vector &rest backquote-form)
1526 sexp)) 1401 sexp))
1527 @end example 1402 @end smallexample
1528 1403
1529 1404
1530 @node Edebug Options 1405 @node Edebug Options
1531 @subsection Edebug Options 1406 @subsection Edebug Options
1532 1407
1542 @end defopt 1417 @end defopt
1543 1418
1544 @defopt edebug-all-defs 1419 @defopt edebug-all-defs
1545 If this is non-@code{nil}, normal evaluation of defining forms such as 1420 If this is non-@code{nil}, normal evaluation of defining forms such as
1546 @code{defun} and @code{defmacro} instruments them for Edebug. This 1421 @code{defun} and @code{defmacro} instruments them for Edebug. This
1547 applies to @code{eval-defun}, @code{eval-region}, and 1422 applies to @code{eval-defun}, @code{eval-region}, @code{eval-buffer},
1548 @code{eval-current-buffer}. @xref{Instrumenting}. 1423 and @code{eval-current-buffer}.
1424
1425 Use the command @kbd{M-x edebug-all-defs} to toggle the value of this
1426 option. @xref{Instrumenting}.
1549 @end defopt 1427 @end defopt
1550 1428
1551 @defopt edebug-all-forms 1429 @defopt edebug-all-forms
1552 If this is non-@code{nil}, the commands @code{eval-defun}, @code{eval-region}, 1430 If this is non-@code{nil}, the commands @code{eval-defun},
1553 and @code{eval-current-buffer} instrument all forms, even those that 1431 @code{eval-region}, @code{eval-buffer}, and @code{eval-current-buffer}
1554 don't define anything. 1432 instrument all forms, even those that don't define anything.
1433 This doesn't apply to loading or evaluations in the minibuffer.
1555 1434
1556 Use the command @kbd{M-x edebug-all-forms} to toggle the value of this 1435 Use the command @kbd{M-x edebug-all-forms} to toggle the value of this
1557 option. 1436 option. @xref{Instrumenting}.
1558 @xref{Instrumenting}.
1559 @end defopt 1437 @end defopt
1560 1438
1561 @defopt edebug-save-windows 1439 @defopt edebug-save-windows
1562 If this is non-@code{nil}, Edebug saves and restores the window 1440 If this is non-@code{nil}, Edebug saves and restores the window
1563 configuration. That takes some time, so if your program does not care 1441 configuration. That takes some time, so if your program does not care
1570 You can use the @kbd{W} command in Edebug to change this variable 1448 You can use the @kbd{W} command in Edebug to change this variable
1571 interactively. @xref{Edebug Display Update}. 1449 interactively. @xref{Edebug Display Update}.
1572 @end defopt 1450 @end defopt
1573 1451
1574 @defopt edebug-save-displayed-buffer-points 1452 @defopt edebug-save-displayed-buffer-points
1575 If non-@code{nil}, Edebug saves and restores point in all buffers. 1453 If this is non-@code{nil}, Edebug saves and restores point in all
1454 displayed buffers.
1576 1455
1577 Saving and restoring point in other buffers is necessary if you are 1456 Saving and restoring point in other buffers is necessary if you are
1578 debugging code that changes the point of a buffer which is displayed in 1457 debugging code that changes the point of a buffer which is displayed in
1579 a non-selected window. If Edebug or the user then selects the window, 1458 a non-selected window. If Edebug or the user then selects the window,
1580 the buffer's point will change to the window's point. 1459 point in that buffer will move to the window's value of point.
1581 1460
1582 Saving and restoring point in all buffers is expensive, since it 1461 Saving and restoring point in all buffers is expensive, since it
1583 requires selecting each window twice, so enable this only if you need 1462 requires selecting each window twice, so enable this only if you need
1584 it. @xref{Edebug Display Update}. 1463 it. @xref{Edebug Display Update}.
1585 @end defopt 1464 @end defopt
1601 Tracing output is displayed in a buffer named @samp{*edebug-trace*}, one 1480 Tracing output is displayed in a buffer named @samp{*edebug-trace*}, one
1602 function entry or exit per line, indented by the recursion level. 1481 function entry or exit per line, indented by the recursion level.
1603 1482
1604 The default value is @code{nil}. 1483 The default value is @code{nil}.
1605 1484
1606 Also see @code{edebug-tracing}. 1485 Also see @code{edebug-tracing}, in @xref{Trace Buffer}.
1607 @xref{Tracing}.
1608 @end defopt 1486 @end defopt
1609 1487
1610 @defopt edebug-test-coverage 1488 @defopt edebug-test-coverage
1611 If non-@code{nil}, Edebug tests coverage of all expressions debugged. 1489 If non-@code{nil}, Edebug tests coverage of all expressions debugged.
1612 This is done by comparing the result of each expression 1490 This is done by comparing the result of each expression
1655 Errors}. 1533 Errors}.
1656 @end defopt 1534 @end defopt
1657 1535
1658 If you change the values of @code{edebug-on-error} or 1536 If you change the values of @code{edebug-on-error} or
1659 @code{edebug-on-quit} while Edebug is active, their values won't be used 1537 @code{edebug-on-quit} while Edebug is active, their values won't be used
1660 until the @emph{next} time Edebug is invoked at a deeper command level. 1538 until the @emph{next} time Edebug is invoked via a new command.
1661 1539 @c Not necessarily a deeper command level.
1662 @ignore 1540 @c A new command is not precisely true, but that is close enough -- dan
1663 @defopt edebug-unwrap-results
1664 Non-@code{nil} if Edebug should unwrap results of expressions. This is
1665 useful when debugging macros where the results of expressions are
1666 instrumented expressions. But don't do this when results might be
1667 circular, or an infinite loop will result. @xref{Debugging Backquote}.
1668 @end defopt
1669 @end ignore
1670 1541
1671 @defopt edebug-global-break-condition 1542 @defopt edebug-global-break-condition
1672 If non-@code{nil}, an expression to test for at every stop point. 1543 If non-@code{nil}, an expression to test for at every stop point.
1673 If the result is non-nil, then break. Errors are ignored. 1544 If the result is non-nil, then break. Errors are ignored.
1674 @xref{Global Break Condition}. 1545 @xref{Global Break Condition}.
1675 @end defopt 1546 @end defopt
1676