1 ;;; edebug.el --- a source-level debugger for Emacs Lisp
3 ;; Copyright (C) 1988,'89,'90,'91,'92,'93,'94,'95 Free Software Foundation, Inc
5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
6 ;; Keywords: lisp, tools, maint
9 ;; edebug|Daniel LaLiberte|liberte@cs.uiuc.edu
10 ;; |A source level debugger for Emacs Lisp.
11 ;; |$Date: 1996/05/29 17:16:52 $|$Revision: 3.7 $|~/modes/edebug.el|
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
32 ;; This minor mode allows programmers to step through Emacs Lisp
33 ;; source code while executing functions. You can also set
34 ;; breakpoints, trace (stopping at each expression), evaluate
35 ;; expressions as if outside Edebug, reevaluate and display a list of
36 ;; expressions, trap errors normally caught by debug, and display a
37 ;; debug style backtrace.
42 ;; Put edebug.el in some directory in your load-path and
43 ;; byte-compile it. Also read the beginning of edebug-epoch.el,
44 ;; cl-specs.el, and edebug-cl-read.el if they apply to you.
46 ;; Unless you are using Emacs 19 which is already set up to use Edebug,
47 ;; put the following forms in your .emacs file.
48 ;; (define-key emacs-lisp-mode-map "\C-xx" 'edebug-eval-top-level-form)
49 ;; (autoload 'edebug-eval-top-level-form "edebug")
51 ;; If you wish to change the default edebug global command prefix, change:
52 ;; (setq edebug-global-prefix "\C-xX")
54 ;; Other options, are described in the manual.
56 ;; In previous versions of Edebug, users were directed to set
57 ;; `debugger' to `edebug-debug'. This is no longer necessary
58 ;; since Edebug automatically sets it whenever Edebug is active.
60 ;;; Minimal Instructions
61 ;; =====================
63 ;; First evaluate a defun with C-xx, then run the function. Step
64 ;; through the code with SPC, mark breakpoints with b, go until a
65 ;; breakpoint is reached with g, and quit execution with q. Use the
66 ;; "?" command in edebug to describe other commands. See edebug.tex
67 ;; or the Emacs 19 Lisp Reference Manual for more instructions.
69 ;; Send me your enhancements, ideas, bugs, or fixes.
70 ;; For bugs, you can call edebug-submit-bug-report if you have reporter.el.
71 ;; There is an edebug mailing list if you want to keep up
72 ;; with the latest developments. Requests to: edebug-request@cs.uiuc.edu
74 ;; Daniel LaLiberte 217-398-4114
75 ;; University of Illinois, Urbana-Champaign
76 ;; Department of Computer Science
81 ;; liberte@cs.uiuc.edu
83 ;; For the early revision history, see edebug-history.
87 (defconst edebug-version
88 (let ((raw-version "$Revision: 3.7 $"))
89 (substring raw-version
(string-match "[0-9.]*" raw-version
)
94 ;; Emacs 18 doesn't have defalias.
96 (or (fboundp 'defalias
) (fset 'defalias
'fset
)))
101 (defconst edebug-maintainer-address
"liberte@cs.uiuc.edu")
103 (defun edebug-submit-bug-report ()
104 "Submit, via mail, a bug report on edebug."
107 (and (y-or-n-p "Do you really want to submit a report on edebug? ")
108 (reporter-submit-bug-report
109 edebug-maintainer-address
110 (concat "edebug.el " edebug-version
)
111 (list 'edebug-setup-hook
114 'edebug-eval-macro-args
115 'edebug-stop-before-symbols
117 'edebug-save-displayed-buffer-points
120 'edebug-test-coverage
121 'edebug-continue-kbd-macro
129 (defvar edebug-setup-hook nil
130 "*Functions to call before edebug is used.
131 Each time it is set to a new value, Edebug will call those functions
132 once and then `edebug-setup-hook' is reset to nil. You could use this
133 to load up Edebug specifications associated with a package you are
134 using but only when you also use Edebug.")
136 (defvar edebug-all-defs nil
137 "*If non-nil, evaluation of any defining forms will instrument for Edebug.
138 This applies to `eval-defun', `eval-region', `eval-buffer', and
139 `eval-current-buffer'. `eval-region' is also called by
140 `eval-last-sexp', and `eval-print-last-sexp'.
142 You can use the command `edebug-all-defs' to toggle the value of this
143 variable. You may wish to make it local to each buffer with
144 \(make-local-variable 'edebug-all-defs) in your
145 `emacs-lisp-mode-hook'.")
147 (defvar edebug-all-forms nil
148 "*Non-nil evaluation of all forms will instrument for Edebug.
149 This doesn't apply to loading or evaluations in the minibuffer.
150 Use the command `edebug-all-forms' to toggle the value of this option.")
152 (defvar edebug-eval-macro-args nil
153 "*Non-nil means all macro call arguments may be evaluated.
154 If this variable is nil, the default, Edebug will *not* wrap
155 macro call arguments as if they will be evaluated.
156 For each macro, a `edebug-form-spec' overrides this option.
157 So to specify exceptions for macros that have some arguments evaluated
158 and some not, you should specify an `edebug-form-spec'.
160 This option is going away soon.")
162 (defvar edebug-stop-before-symbols nil
163 "*Non-nil causes Edebug to stop before symbols as well as after.
164 In any case, a breakpoint or interrupt may stop before a symbol.
166 This option is going away soon.")
168 (defvar edebug-save-windows t
169 "*If non-nil, Edebug saves and restores the window configuration.
170 That takes some time, so if your program does not care what happens to
171 the window configurations, it is better to set this variable to nil.
173 If the value is a list, only the listed windows are saved and
176 `edebug-toggle-save-windows' may be used to change this variable.")
178 (defvar edebug-save-displayed-buffer-points nil
179 "*If non-nil, save and restore point in all displayed buffers.
181 Saving and restoring point in other buffers is necessary if you are
182 debugging code that changes the point of a buffer which is displayed
183 in a non-selected window. If Edebug or the user then selects the
184 window, the buffer's point will be changed to the window's point.
186 Saving and restoring point in all buffers is expensive, since it
187 requires selecting each window twice, so enable this only if you need
190 (defvar edebug-initial-mode
'step
191 "*Initial execution mode for Edebug, if non-nil. If this variable
192 is non-@code{nil}, it specifies the initial execution mode for Edebug
193 when it is first activated. Possible values are step, next, go,
194 Go-nonstop, trace, Trace-fast, continue, and Continue-fast.")
196 (defvar edebug-trace nil
197 "*Non-nil means display a trace of function entry and exit.
198 Tracing output is displayed in a buffer named `*edebug-trace*', one
199 function entry or exit per line, indented by the recursion level.
201 You can customize by replacing functions `edebug-print-trace-before'
202 and `edebug-print-trace-after'.")
204 (defvar edebug-test-coverage nil
205 "*If non-nil, Edebug tests coverage of all expressions debugged.
206 This is done by comparing the result of each expression
207 with the previous result. Coverage is considered OK if two different
210 Use `edebug-display-freq-count' to display the frequency count and
211 coverage information for a definition.")
213 (defvar edebug-continue-kbd-macro nil
214 "*If non-nil, continue defining or executing any keyboard macro.
215 Use this with caution since it is not debugged.")
218 (defvar edebug-print-length
50
219 "*Default value of `print-length' to use while printing results in Edebug.")
220 (defvar edebug-print-level
50
221 "*Default value of `print-level' to use while printing results in Edebug.")
222 (defvar edebug-print-circle t
223 "*Default value of `print-circle' to use while printing results in Edebug.")
225 (defvar edebug-unwrap-results nil
226 "*Non-nil if Edebug should unwrap results of expressions.
227 This is useful when debugging macros where the results of expressions
228 are instrumented expressions. But don't do this when results might be
229 circular or an infinite loop will result.")
231 (defvar edebug-on-error t
232 "*Value bound to `debug-on-error' while Edebug is active.
234 If `debug-on-error' is non-nil, that value is still used.
236 If the value is a list of signal names, Edebug will stop when any of
237 these errors are signaled from Lisp code whether or not the signal is
238 handled by a `condition-case'. This option is useful for debugging
239 signals that *are* handled since they would otherwise be missed.
240 After execution is resumed, the error is signaled again.")
242 (defvar edebug-on-quit t
243 "*Value bound to `debug-on-quit' while Edebug is active.")
245 (defvar edebug-global-break-condition nil
246 "*If non-nil, an expression to test for at every stop point.
247 If the result is non-nil, then break. Errors are ignored.")
249 ;;; Form spec utilities.
252 (defmacro def-edebug-spec
(symbol spec
)
253 "Set the edebug-form-spec property of SYMBOL according to SPEC.
254 Both SYMBOL and SPEC are unevaluated. The SPEC can be 0, t, a symbol
255 \(naming a function), or a list."
256 (` (put (quote (, symbol
)) 'edebug-form-spec
(quote (, spec
)))))
258 (defmacro def-edebug-form-spec
(symbol spec-form
)
259 "For compatibility with old version. Use `def-edebug-spec' instead."
260 (message "Obsolete: use def-edebug-spec instead.")
261 (def-edebug-spec symbol
(eval spec-form
)))
263 (defun get-edebug-spec (symbol)
264 ;; Get the spec of symbol resolving all indirection.
265 (let ((edebug-form-spec (get symbol
'edebug-form-spec
))
267 (while (and (symbolp edebug-form-spec
)
268 (setq indirect
(get edebug-form-spec
'edebug-form-spec
)))
269 ;; (edebug-trace "indirection: %s" edebug-form-spec)
270 (setq edebug-form-spec indirect
))
276 ;; Define edebug-gensym - from old cl.el
277 (defvar edebug-gensym-index
0
278 "Integer used by `edebug-gensym' to produce new names.")
280 (defun edebug-gensym (&optional prefix
)
281 "Generate a fresh uninterned symbol.
282 There is an optional argument, PREFIX. PREFIX is the
283 string that begins the new name. Most people take just the default,
284 except when debugging needs suggest otherwise."
287 (let ((newsymbol nil
)
289 (while (not newsymbol
)
290 (setq newname
(concat prefix
(int-to-string edebug-gensym-index
)))
291 (setq edebug-gensym-index
(+ edebug-gensym-index
1))
292 (if (not (intern-soft newname
))
293 (setq newsymbol
(make-symbol newname
))))
296 ;; Only used by CL-like code.
297 (defun edebug-keywordp (object)
298 "Return t if OBJECT is a keyword.
299 A keyword is a symbol that starts with `:'."
300 (and (symbolp object
)
301 (= ?
: (aref (symbol-name object
) 0))))
303 (defun edebug-lambda-list-keywordp (object)
304 "Return t if OBJECT is a lambda list keyword.
305 A lambda list keyword is a symbol that starts with `&'."
306 (and (symbolp object
)
307 (= ?
& (aref (symbol-name object
) 0))))
310 (defun edebug-last-sexp ()
311 ;; Return the last sexp before point in current buffer.
312 ;; Assumes Emacs Lisp syntax is active.
321 (defun edebug-window-list ()
322 "Return a list of windows, in order of `next-window'."
323 ;; This doesn't work for epoch.
324 (let* ((first-window (selected-window))
325 (window-list (list first-window
))
326 (next (next-window first-window
)))
327 (while (not (eq next first-window
))
328 (setq window-list
(cons next window-list
))
329 (setq next
(next-window next
)))
330 (nreverse window-list
)))
332 (defun edebug-window-live-p (window)
333 "Return non-nil if WINDOW is visible."
334 (let* ((first-window (selected-window))
335 (next (next-window first-window t
)))
336 (while (not (or (eq next window
)
337 (eq next first-window
)))
338 (setq next
(next-window next t
)))
342 '(defun edebug-two-window-p ()
343 "Return t if there are two windows."
344 (and (not (one-window-p))
345 (eq (selected-window)
346 (next-window (next-window (selected-window))))))
348 (defsubst edebug-lookup-function
(object)
349 (while (and (symbolp object
) (fboundp object
))
350 (setq object
(symbol-function object
)))
353 (defun edebug-macrop (object)
354 "Return the macro named by OBJECT, or nil if it is not a macro."
355 (setq object
(edebug-lookup-function object
))
356 (if (and (listp object
)
357 (eq 'macro
(car object
))
358 (edebug-functionp (cdr object
)))
361 (defun edebug-functionp (object)
362 "Returns the function named by OBJECT, or nil if it is not a function."
363 (setq object
(edebug-lookup-function object
))
364 (if (or (subrp object
)
365 (byte-code-function-p object
)
367 (eq (car object
) 'lambda
)
368 (listp (car (cdr object
)))))
371 (defun edebug-sort-alist (alist function
)
372 ;; Return the ALIST sorted with comparison function FUNCTION.
373 ;; This uses 'sort so the sorting is destructive.
374 (sort alist
(function
376 (funcall function
(car e1
) (car e2
))))))
378 ;;(def-edebug-spec edebug-save-restriction t)
380 ;; Not used. If it is used, def-edebug-spec must be defined before use.
381 '(defmacro edebug-save-restriction
(&rest body
)
382 "Evaluate BODY while saving the current buffers restriction.
383 BODY may change buffer outside of current restriction, unlike
384 save-restriction. BODY may change the current buffer,
385 and the restriction will be restored to the original buffer,
386 and the current buffer remains current.
387 Return the result of the last expression in BODY."
388 (` (let ((edebug:s-r-beg
(point-min-marker))
389 (edebug:s-r-end
(point-max-marker)))
393 (set-buffer (marker-buffer edebug
:s-r-beg
))
394 (narrow-to-region edebug
:s-r-beg edebug
:s-r-end
))))))
398 (defconst edebug-trace-buffer
"*edebug-trace*"
399 "Name of the buffer to put trace info in.")
401 (defun edebug-pop-to-buffer (buffer &optional window
)
402 ;; Like pop-to-buffer, but select window where BUFFER was last shown.
403 ;; Select WINDOW if it provided and it still exists. Otherwise,
404 ;; if buffer is currently shown in several windows, choose one.
405 ;; Otherwise, find a new window, possibly splitting one.
406 (setq window
(if (and (windowp window
) (edebug-window-live-p window
)
407 (eq (window-buffer window
) buffer
))
409 (if (eq (window-buffer (selected-window)) buffer
)
411 (edebug-get-buffer-window buffer
))))
413 (select-window window
)
416 ;; (message "next window: %s" (next-window)) (sit-for 1)
417 (if (eq (get-buffer-window edebug-trace-buffer
) (next-window))
418 ;; Don't select trace window
420 (select-window (next-window))))
421 (set-window-buffer (selected-window) buffer
)
422 (set-window-hscroll (selected-window) 0);; should this be??
423 ;; Selecting the window does not set the buffer until command loop.
424 ;;(set-buffer buffer)
428 (defun edebug-get-displayed-buffer-points ()
429 ;; Return a list of buffer point pairs, for all displayed buffers.
431 (let* ((first-window (selected-window))
432 (next (next-window first-window
))
433 (buffer-point-list nil
)
435 (while (not (eq next first-window
))
436 (set-buffer (setq buffer
(window-buffer next
)))
437 (setq buffer-point-list
438 (cons (cons buffer
(point)) buffer-point-list
))
439 (setq next
(next-window next
)))
443 (defun edebug-set-buffer-points (buffer-points)
444 ;; Restore the buffer-points created by edebug-get-displayed-buffer-points.
445 (let ((current-buffer (current-buffer)))
446 (mapcar (function (lambda (buf-point)
447 (if (buffer-name (car buf-point
)) ; still exists
449 (set-buffer (car buf-point
))
450 (goto-char (cdr buf-point
))))))
452 (set-buffer current-buffer
)))
454 (defun edebug-current-windows (which-windows)
455 ;; Get either a full window configuration or some window information.
456 (if (listp which-windows
)
457 (mapcar (function (lambda (window)
458 (if (edebug-window-live-p window
)
460 (window-buffer window
)
461 (window-point window
)
462 (window-start window
)
463 (window-hscroll window
)))))
465 (current-window-configuration)))
467 (defun edebug-set-windows (window-info)
468 ;; Set either a full window configuration or some window information.
469 (if (listp window-info
)
471 (lambda (one-window-info)
474 (lambda (window buffer point start hscroll
)
475 (if (edebug-window-live-p window
)
477 (set-window-buffer window buffer
)
478 (set-window-point window point
)
479 (set-window-start window start
)
480 (set-window-hscroll window hscroll
)))))
483 (set-window-configuration window-info
)))
485 (defalias 'edebug-get-buffer-window
'get-buffer-window
)
486 (defalias 'edebug-sit-for
'sit-for
)
487 (defalias 'edebug-input-pending-p
'input-pending-p
)
490 ;;; Redefine read and eval functions
491 ;; read is redefined to maybe instrument forms.
492 ;; eval-defun is redefined to check edebug-all-forms and edebug-all-defs.
494 ;; Use the Lisp version of eval-region.
495 (require 'eval-reg
"eval-reg")
497 ;; Save the original read function
498 (or (fboundp 'edebug-original-read
)
499 (defalias 'edebug-original-read
(symbol-function 'read
)))
501 (defun edebug-read (&optional stream
)
502 "Read one Lisp expression as text from STREAM, return as Lisp object.
503 If STREAM is nil, use the value of `standard-input' (which see).
504 STREAM or the value of `standard-input' may be:
505 a buffer (read from point and advance it)
506 a marker (read from where it points and advance it)
507 a function (call it with no arguments for each character,
508 call it with a char as argument to push a char back)
509 a string (takes text from string, starting at the beginning)
510 t (read text line using minibuffer and use it).
512 This version, from Edebug, maybe instruments the expression. But the
513 STREAM must be the current buffer to do so. Whether it instruments is
514 also dependent on the values of `edebug-all-defs' and
516 (or stream
(setq stream standard-input
))
517 (if (eq stream
(current-buffer))
518 (edebug-read-and-maybe-wrap-form)
519 (edebug-original-read stream
)))
521 (or (fboundp 'edebug-original-eval-defun
)
522 (defalias 'edebug-original-eval-defun
(symbol-function 'eval-defun
)))
524 ;; We should somehow arrange to be able to do this
525 ;; without actually replacing the eval-defun command.
526 (defun edebug-eval-defun (edebug-it)
527 "Evaluate the top-level form containing point, or after point.
529 This version, from Edebug, has the following differences: With a
530 prefix argument instrument the code for Edebug. If `edebug-all-defs' is
531 non-nil, then the code is instrumented *unless* there is a prefix
532 argument. If instrumenting, it prints: `Edebug: FUNCTIONNAME'.
533 Otherwise, it prints in the minibuffer."
535 (let* ((edebugging (not (eq (not edebug-it
) (not edebug-all-defs
))))
538 (let ((edebug-all-forms edebugging
)
539 (edebug-all-defs (eq edebug-all-defs
(not edebug-it
))))
540 (edebug-read-top-level-form))))
541 (if (and (eq (car form
) 'defvar
)
542 (cdr-safe (cdr-safe form
)))
543 (setq form
(cons 'defconst
(cdr form
))))
544 (setq edebug-result
(eval form
))
546 (princ edebug-result
)
551 (defalias 'edebug-defun
'edebug-eval-top-level-form
)
554 (defun edebug-eval-top-level-form ()
555 "Evaluate a top level form, such as a defun or defmacro.
556 This is like `eval-defun', but the code is always instrumented for Edebug.
557 Print its name in the minibuffer and leave point where it is,
558 or if an error occurs, leave point after it with mark at the original point."
561 ;; Bind edebug-all-forms only while reading, not while evalling
562 ;; but this causes problems while edebugging edebug.
563 (let ((edebug-all-forms t
)
565 (edebug-read-top-level-form))))
568 (defun edebug-read-top-level-form ()
569 (let ((starting-point (point)))
573 (edebug-read-and-maybe-wrap-form)
574 ;; Recover point, but only if no error occurred.
575 (goto-char starting-point
))))
578 ;; Compatibility with old versions.
579 (defalias 'edebug-all-defuns
'edebug-all-defs
)
581 (defun edebug-all-defs ()
582 "Toggle edebugging of all definitions."
584 (setq edebug-all-defs
(not edebug-all-defs
))
585 (message "Edebugging all definitions is %s."
586 (if edebug-all-defs
"on" "off")))
589 (defun edebug-all-forms ()
590 "Toggle edebugging of all forms."
592 (setq edebug-all-forms
(not edebug-all-forms
))
593 (message "Edebugging all forms is %s."
594 (if edebug-all-forms
"on" "off")))
597 (defun edebug-install-read-eval-functions ()
599 ;; Don't install if already installed.
600 (if (eq (symbol-function 'read
) 'edebug-read
) nil
601 (elisp-eval-region-install)
602 (defalias 'read
'edebug-read
)
603 (defalias 'eval-defun
'edebug-eval-defun
)))
605 (defun edebug-uninstall-read-eval-functions ()
607 (elisp-eval-region-uninstall)
608 (defalias 'read
(symbol-function 'edebug-original-read
))
609 (defalias 'eval-defun
(symbol-function 'edebug-original-eval-defun
)))
612 ;;; Edebug internal data
614 ;; The internal data that is needed for edebugging is kept in the
615 ;; buffer-local variable `edebug-form-data'.
617 (make-variable-buffer-local 'edebug-form-data
)
619 (defconst edebug-form-data nil
)
620 ;; A list of entries associating symbols with buffer regions.
621 ;; This is an automatic buffer local variable. Each entry looks like:
622 ;; @code{(@var{symbol} @var{begin-marker} @var{end-marker}). The markers
623 ;; are at the beginning and end of an entry level form and @var{symbol} is
624 ;; a symbol that holds all edebug related information for the form on its
627 ;; In the future, the symbol will be irrelevant and edebug data will
628 ;; be stored in the definitions themselves rather than in the property
631 (defun edebug-make-form-data-entry (symbol begin end
)
632 (list symbol begin end
))
634 (defsubst edebug-form-data-name
(entry)
637 (defsubst edebug-form-data-begin
(entry)
640 (defsubst edebug-form-data-end
(entry)
643 (defsubst edebug-set-form-data-entry
(entry name begin end
)
644 (setcar entry name
);; in case name is changed
645 (set-marker (nth 1 entry
) begin
)
646 (set-marker (nth 2 entry
) end
))
648 (defun edebug-get-form-data-entry (pnt &optional end-point
)
649 ;; Find the edebug form data entry which is closest to PNT.
650 ;; If END-POINT is supplied, match must be exact.
651 ;; Return `nil' if none found.
652 (let ((rest edebug-form-data
)
654 (closest-dist 999999)) ;; need maxint here
655 (while (and rest
(< 0 closest-dist
))
656 (let* ((entry (car rest
))
657 (begin (edebug-form-data-begin entry
))
658 (dist (- pnt begin
)))
659 (setq rest
(cdr rest
))
661 (< dist closest-dist
)
663 (= end-point
(edebug-form-data-end entry
)))
664 (<= pnt
(edebug-form-data-end entry
)))
665 (setq closest-dist dist
666 closest-entry entry
))))
669 ;; Also need to find all contained entries,
670 ;; and find an entry given a symbol, which should be just assq.
672 (defun edebug-form-data-symbol ()
673 ;; Return the edebug data symbol of the form where point is in.
674 ;; If point is not inside a edebuggable form, cause error.
675 (or (edebug-form-data-name (edebug-get-form-data-entry (point)))
676 (error "Not inside instrumented form")))
678 (defun edebug-make-top-form-data-entry (new-entry)
679 ;; Make NEW-ENTRY the first element in the `edebug-form-data' list.
680 (edebug-clear-form-data-entry new-entry
)
681 (setq edebug-form-data
(cons new-entry edebug-form-data
)))
683 (defun edebug-clear-form-data-entry (entry)
684 ;; If non-nil, clear ENTRY out of the form data.
685 ;; Maybe clear the markers and delete the symbol's edebug property?
688 ;; Instead of this, we could just find all contained forms.
689 ;; (put (car entry) 'edebug nil) ;
690 ;; (mapcar 'edebug-clear-form-data-entry ; dangerous
691 ;; (get (car entry) 'edebug-dependents))
692 ;; (set-marker (nth 1 entry) nil)
693 ;; (set-marker (nth 2 entry) nil)
694 (setq edebug-form-data
(delq entry edebug-form-data
)))))
698 (defun edebug-syntax-error (&rest args
)
699 ;; Signal an invalid-read-syntax with ARGS.
700 (signal 'invalid-read-syntax args
))
703 (defconst edebug-read-syntax-table
704 ;; Lookup table for significant characters indicating the class of the
705 ;; token that follows. This is not a \"real\" syntax table.
706 (let ((table (make-vector 256 'symbol
))
709 (aset table i
'space
)
711 (aset table ?\
( 'lparen
)
712 (aset table ?\
) 'rparen
)
713 (aset table ?
\' 'quote
)
714 (aset table ?\
` 'backquote
)
715 (aset table ?\
, 'comma
)
716 (aset table ?
\" 'string
)
717 (aset table ?
\? 'char
)
718 (aset table ?\
[ 'lbracket
)
719 (aset table ?\
] 'rbracket
)
720 (aset table ?\.
'dot
)
721 (aset table ?\
# 'hash
)
722 ;; We treat numbers as symbols, because of confusion with -, -1, and 1-.
723 ;; We don't care about any other chars since they won't be seen.
726 (defun edebug-next-token-class ()
727 ;; Move to the next token and return its class. We only care about
728 ;; lparen, rparen, dot, quote, backquote, comma, string, char, vector,
730 (edebug-skip-whitespace)
731 (aref edebug-read-syntax-table
(following-char)))
734 (defun edebug-skip-whitespace ()
735 ;; Leave point before the next token, skipping white space and comments.
736 (skip-chars-forward " \t\r\n\f")
737 (while (= (following-char) ?\
;)
738 ;; \r is counted as a comment terminator to support selective display.
739 (skip-chars-forward "^\n\r") ; skip the comment
740 (skip-chars-forward " \t\r\n\f")))
743 ;; Mostly obsolete reader; still used in one case.
745 (defun edebug-read-sexp ()
746 ;; Read one sexp from the current buffer starting at point.
747 ;; Leave point immediately after it. A sexp can be a list or atom.
748 ;; An atom is a symbol (or number), character, string, or vector.
749 ;; This works for reading anything legitimate, but it
750 ;; is gummed up by parser inconsistencies (bugs?)
751 (let ((class (edebug-next-token-class)))
753 ;; read goes one too far if a (possibly quoted) string or symbol
754 ;; is immediately followed by non-whitespace.
755 ((eq class
'symbol
) (prog1
756 (edebug-original-read (current-buffer))
757 (if (not (eq (aref edebug-read-syntax-table
758 (preceding-char)) 'symbol
))
760 ((eq class
'string
) (prog1
761 (edebug-original-read (current-buffer))
762 (if (/= (preceding-char) ?
\")
764 ((eq class
'quote
) (forward-char 1)
765 (list 'quote
(edebug-read-sexp)))
766 ((eq class
'backquote
)
767 (list '\
` (edebug-read-sexp)))
769 (list '\
, (edebug-read-sexp)))
770 (t ; anything else, just read it.
771 (edebug-original-read (current-buffer))))))
773 ;;; Offsets for reader
775 ;; Define a structure to represent offset positions of expressions.
776 ;; Each offset structure looks like: (before . after) for constituents,
777 ;; or for structures that have elements: (before <subexpressions> . after)
778 ;; where the <subexpressions> are the offset structures for subexpressions
779 ;; including the head of a list.
780 (defconst edebug-offsets nil
)
782 ;; Stack of offset structures in reverse order of the nesting.
783 ;; This is used to get back to previous levels.
784 (defconst edebug-offsets-stack nil
)
785 (defconst edebug-current-offset nil
) ; Top of the stack, for convenience.
787 ;; We must store whether we just read a list with a dotted form that
788 ;; is itself a list. This structure will be condensed, so the offsets
789 ;; must also be condensed.
790 (defconst edebug-read-dotted-list nil
)
792 (defsubst edebug-initialize-offsets
()
793 ;; Reinitialize offset recording.
794 (setq edebug-current-offset nil
))
796 (defun edebug-store-before-offset (point)
797 ;; Add a new offset pair with POINT as the before offset.
798 (let ((new-offset (list point
)))
799 (if edebug-current-offset
800 (setcdr edebug-current-offset
801 (cons new-offset
(cdr edebug-current-offset
)))
802 ;; Otherwise, we are at the top level, so initialize.
803 (setq edebug-offsets new-offset
804 edebug-offsets-stack nil
805 edebug-read-dotted-list nil
))
806 ;; Cons the new offset to the front of the stack.
807 (setq edebug-offsets-stack
(cons new-offset edebug-offsets-stack
)
808 edebug-current-offset new-offset
)
811 (defun edebug-store-after-offset (point)
812 ;; Finalize the current offset struct by reversing it and
813 ;; store POINT as the after offset.
814 (if (not edebug-read-dotted-list
)
815 ;; Just reverse the offsets of all subexpressions.
816 (setcdr edebug-current-offset
(nreverse (cdr edebug-current-offset
)))
818 ;; We just read a list after a dot, which will be abbreviated out.
819 (setq edebug-read-dotted-list nil
)
820 ;; Drop the corresponding offset pair.
821 ;; That is, nconc the reverse of the rest of the offsets
822 ;; with the cdr of last offset.
823 (setcdr edebug-current-offset
824 (nconc (nreverse (cdr (cdr edebug-current-offset
)))
825 (cdr (car (cdr edebug-current-offset
))))))
827 ;; Now append the point using nconc.
828 (setq edebug-current-offset
(nconc edebug-current-offset point
))
830 (setq edebug-offsets-stack
(cdr edebug-offsets-stack
)
831 edebug-current-offset
(car edebug-offsets-stack
)))
833 (defun edebug-ignore-offset ()
834 ;; Ignore the last created offset pair.
835 (setcdr edebug-current-offset
(cdr (cdr edebug-current-offset
))))
837 (def-edebug-spec edebug-storing-offsets
(form body
))
838 (put 'edebug-storing-offsets
'lisp-indent-hook
1)
840 (defmacro edebug-storing-offsets
(point &rest body
)
843 (edebug-store-before-offset (, point
))
845 (edebug-store-after-offset (point)))))
848 ;;; Reader for Emacs Lisp.
850 ;; Uses edebug-next-token-class (and edebug-skip-whitespace) above.
852 (defconst edebug-read-alist
853 '((symbol . edebug-read-symbol
)
854 (lparen . edebug-read-list
)
855 (string . edebug-read-string
)
856 (quote . edebug-read-quote
)
857 (backquote . edebug-read-backquote
)
858 (comma . edebug-read-comma
)
859 (lbracket . edebug-read-vector
)
860 (hash . edebug-read-function
)
863 (defun edebug-read-storing-offsets (stream)
864 (let ((class (edebug-next-token-class))
866 edebug-read-dotted-list
) ; see edebug-store-after-offset
867 (edebug-storing-offsets (point)
868 (if (setq func
(assq class edebug-read-alist
))
869 (funcall (cdr func
) stream
)
870 ;; anything else, just read it.
871 (edebug-original-read stream
))
874 (defun edebug-read-symbol (stream)
876 (edebug-original-read stream
)
877 ;; loses for escaped chars
878 (if (not (eq (aref edebug-read-syntax-table
879 (preceding-char)) 'symbol
))
882 (defun edebug-read-string (stream)
884 (edebug-original-read stream
)
885 (if (/= (preceding-char) ?
\")
888 (defun edebug-read-quote (stream)
889 ;; Turn 'thing into (quote thing)
892 (edebug-storing-offsets (point) 'quote
)
893 (edebug-read-storing-offsets stream
)))
895 (defun edebug-read-backquote (stream)
896 ;; Turn `thing into (\` thing)
897 (let ((opoint (point)))
899 ;; Generate the same structure of offsets we would have
900 ;; if the resulting list appeared verbatim in the input text.
901 (edebug-storing-offsets opoint
903 (edebug-storing-offsets opoint
'\
`)
904 (edebug-read-storing-offsets stream
)))))
906 (defvar edebug-read-backquote-new nil
907 "Non-nil if reading the inside of a new-style backquote with no parens around it.
908 Value of nil means reading the inside of an old-style backquote construct
909 which is surrounded by an extra set of parentheses.
910 This controls how we read comma constructs.")
912 (defun edebug-read-comma (stream)
913 ;; Turn ,thing into (\, thing). Handle ,@ and ,. also.
914 (let ((opoint (point)))
917 (cond ((eq (following-char) ?\.
)
920 ((eq (following-char) ?\
@)
923 ;; Generate the same structure of offsets we would have
924 ;; if the resulting list appeared verbatim in the input text.
925 (if edebug-read-backquote-new
927 (edebug-storing-offsets opoint symbol
)
928 (edebug-read-storing-offsets stream
))
929 (edebug-storing-offsets opoint symbol
)))))
931 (defun edebug-read-function (stream)
932 ;; Turn #'thing into (function thing)
934 (if (/= ?
\' (following-char)) (edebug-syntax-error "Bad char"))
937 (edebug-storing-offsets (point)
938 (if (featurep 'cl
) 'function
* 'function
))
939 (edebug-read-storing-offsets stream
)))
941 (defun edebug-read-list (stream)
942 (forward-char 1) ; skip \(
945 (while (not (memq (edebug-next-token-class) '(rparen dot
)))
946 (if (eq (edebug-next-token-class) 'backquote
)
947 (let ((edebug-read-backquote-new (not (null elements
)))
949 (if edebug-read-backquote-new
950 (setq elements
(cons (edebug-read-backquote stream
) elements
))
951 (forward-char 1) ; Skip backquote.
952 ;; Call edebug-storing-offsets here so that we
953 ;; produce the same offsets we would have had
954 ;; if the backquote were an ordinary symbol.
955 (setq elements
(cons (edebug-storing-offsets opoint
'\
`)
957 (setq elements
(cons (edebug-read-storing-offsets stream
) elements
))))
958 (setq elements
(nreverse elements
))
959 (if (eq 'dot
(edebug-next-token-class))
961 (forward-char 1) ; skip \.
962 (setq dotted-form
(edebug-read-storing-offsets stream
))
963 elements
(nconc elements dotted-form
)
964 (if (not (eq (edebug-next-token-class) 'rparen
))
965 (edebug-syntax-error "Expected `)'"))
966 (setq edebug-read-dotted-list
(listp dotted-form
))
969 (forward-char 1) ; skip \)
972 (defun edebug-read-vector (stream)
973 (forward-char 1) ; skip \[
976 (while (not (eq 'rbracket
(edebug-next-token-class)))
977 (setq elements
(cons (edebug-read-storing-offsets stream
) elements
)))
978 (apply 'vector
(nreverse elements
)))
979 (forward-char 1) ; skip \]
982 ;;; Cursors for traversal of list and vector elements with offsets.
984 (defvar edebug-dotted-spec nil
)
986 (defun edebug-new-cursor (expressions offsets
)
987 ;; Return a new cursor for EXPRESSIONS with OFFSETS.
988 (if (vectorp expressions
)
989 (setq expressions
(append expressions nil
)))
990 (cons expressions offsets
))
992 (defsubst edebug-set-cursor
(cursor expressions offsets
)
993 ;; Set the CURSOR's EXPRESSIONS and OFFSETS to the given.
994 ;; Return the cursor.
995 (setcar cursor expressions
)
996 (setcdr cursor offsets
)
999 '(defun edebug-copy-cursor (cursor)
1000 ;; Copy the cursor using the same object and offsets.
1001 (cons (car cursor
) (cdr cursor
)))
1003 (defsubst edebug-cursor-expressions
(cursor)
1005 (defsubst edebug-cursor-offsets
(cursor)
1008 (defsubst edebug-empty-cursor
(cursor)
1009 ;; Return non-nil if CURSOR is empty - meaning no more elements.
1010 (null (car cursor
)))
1012 (defsubst edebug-top-element
(cursor)
1013 ;; Return the top element at the cursor.
1014 ;; Assumes not empty.
1017 (defun edebug-top-element-required (cursor &rest error
)
1018 ;; Check if a dotted form is required.
1019 (if edebug-dotted-spec
(edebug-no-match cursor
"Dot expected."))
1020 ;; Check if there is at least one more argument.
1021 (if (edebug-empty-cursor cursor
) (apply 'edebug-no-match cursor error
))
1022 ;; Return that top element.
1023 (edebug-top-element cursor
))
1025 (defsubst edebug-top-offset
(cursor)
1026 ;; Return the top offset pair corresponding to the top element.
1029 (defun edebug-move-cursor (cursor)
1030 ;; Advance and return the cursor to the next element and offset.
1031 ;; throw no-match if empty before moving.
1032 ;; This is a violation of the cursor encapsulation, but
1033 ;; there is plenty of that going on while matching.
1034 ;; The following test should always fail.
1035 (if (edebug-empty-cursor cursor
)
1036 (edebug-no-match cursor
"Not enough arguments."))
1037 (setcar cursor
(cdr (car cursor
)))
1038 (setcdr cursor
(cdr (cdr cursor
)))
1042 (defun edebug-before-offset (cursor)
1043 ;; Return the before offset of the cursor.
1044 ;; If there is nothing left in the offsets,
1045 ;; return one less than the offset itself,
1046 ;; which is the after offset for a list.
1047 (let ((offset (edebug-cursor-offsets cursor
)))
1052 (defun edebug-after-offset (cursor)
1053 ;; Return the after offset of the cursor object.
1054 (let ((offset (edebug-top-offset cursor
)))
1055 (while (consp offset
)
1056 (setq offset
(cdr offset
)))
1061 ;; The top level function for parsing forms is
1062 ;; edebug-read-and-maybe-wrap-form; it calls all the rest. It checks the
1063 ;; syntax a bit and leaves point at any error it finds, but otherwise
1064 ;; should appear to work like eval-defun.
1066 ;; The basic plan is to surround each expression with a call to
1067 ;; the edebug debugger together with indexes into a table of positions of
1068 ;; all expressions. Thus an expression "exp" becomes:
1070 ;; (edebug-after (edebug-before 1) 2 exp)
1072 ;; When this is evaluated, first point is moved to the beginning of
1073 ;; exp at offset 1 of the current function. The expression is
1074 ;; evaluated, which may cause more edebug calls, and then point is
1075 ;; moved to offset 2 after the end of exp.
1077 ;; The highest level expressions of the function are wrapped in a call to
1078 ;; edebug-enter, which supplies the function name and the actual
1079 ;; arguments to the function. See functions edebug-enter, edebug-before,
1080 ;; and edebug-after for more details.
1082 ;; Dynamically bound vars, left unbound, but globally declared.
1083 ;; This is to quiet the byte compiler.
1085 ;; Window data of the highest definition being wrapped.
1086 ;; This data is shared by all embedded definitions.
1087 (defvar edebug-top-window-data
)
1089 (defvar edebug-
&optional
)
1090 (defvar edebug-
&rest
)
1091 (defvar edebug-gate nil
) ;; whether no-match forces an error.
1093 (defconst edebug-def-name nil
) ; name of definition, used by interactive-form
1094 (defconst edebug-old-def-name nil
) ; previous name of containing definition.
1096 (defconst edebug-error-point nil
)
1097 (defconst edebug-best-error nil
)
1100 (defun edebug-read-and-maybe-wrap-form ()
1101 ;; Read a form and wrap it with edebug calls, if the conditions are right.
1102 ;; Here we just catch any no-match not caught below and signal an error.
1104 ;; Run the setup hook.
1105 (run-hooks 'edebug-setup-hook
)
1106 (setq edebug-setup-hook nil
)
1109 edebug-top-window-data
1110 edebug-def-name
;; make sure it is locally nil
1111 ;; I don't like these here!!
1118 ;; Do this once here instead of several times.
1119 (max-lisp-eval-depth (+ 800 max-lisp-eval-depth
))
1120 (max-specpdl-size (+ 2000 max-specpdl-size
)))
1123 (setq result
(edebug-read-and-maybe-wrap-form1))
1126 (apply 'edebug-syntax-error no-match
))
1130 (defun edebug-read-and-maybe-wrap-form1 ()
1135 ;; These offset things don't belong here, but to support recursive
1136 ;; calls to edebug-read, they need to be here.
1138 edebug-offsets-stack
1139 edebug-current-offset
; reset to nil
1142 (if (and (eq 'lparen
(edebug-next-token-class))
1143 (eq 'symbol
(progn (forward-char 1) (edebug-next-token-class))))
1144 ;; Find out if this is a defining form from first symbol
1145 (setq def-kind
(edebug-original-read (current-buffer))
1146 spec
(and (symbolp def-kind
) (get-edebug-spec def-kind
))
1147 defining-form-p
(and (listp spec
)
1148 (eq '&define
(car spec
)))
1149 ;; This is incorrect in general!! But OK most of the time.
1150 def-name
(if (and defining-form-p
1151 (eq 'name
(car (cdr spec
)))
1152 (eq 'symbol
(edebug-next-token-class)))
1153 (edebug-original-read (current-buffer))))))
1154 ;;;(message "all defs: %s all forms: %s" edebug-all-defs edebug-all-forms)
1157 (if (or edebug-all-defs edebug-all-forms
)
1158 ;; If it is a defining form and we are edebugging defs,
1159 ;; then let edebug-list-form start it.
1160 (let ((cursor (edebug-new-cursor
1161 (list (edebug-read-storing-offsets (current-buffer)))
1162 (list edebug-offsets
))))
1164 (edebug-make-form-wrapper
1166 (edebug-before-offset cursor
)
1167 (1- (edebug-after-offset cursor
))
1168 (list (cons (symbol-name def-kind
) (cdr spec
))))))
1170 ;; Not edebugging this form, so reset the symbol's edebug
1171 ;; property to be just a marker at the definition's source code.
1172 ;; This only works for defs with simple names.
1173 (put def-name
'edebug
(point-marker))
1174 ;; Also nil out dependent defs.
1177 (put def-name
'edebug nil
)))
1178 (get def-name
'edebug-dependents
))
1179 (edebug-read-sexp)))
1181 ;; If all forms are being edebugged, explicitly wrap it.
1183 (let ((cursor (edebug-new-cursor
1184 (list (edebug-read-storing-offsets (current-buffer)))
1185 (list edebug-offsets
))))
1186 (edebug-make-form-wrapper
1188 (edebug-before-offset cursor
)
1189 (edebug-after-offset cursor
)
1192 ;; Not a defining form, and not edebugging.
1193 (t (edebug-read-sexp)))
1197 (defvar edebug-def-args
) ; args of defining form.
1198 (defvar edebug-def-interactive
) ; is it an emacs interactive function?
1199 (defvar edebug-inside-func
) ;; whether code is inside function context.
1200 ;; Currently def-form sets this to nil; def-body sets it to t.
1202 (defun edebug-interactive-p-name ()
1203 ;; Return a unique symbol for the variable used to store the
1204 ;; status of interactive-p for this function.
1205 (intern (format "edebug-%s-interactive-p" edebug-def-name
)))
1208 (defun edebug-wrap-def-body (forms)
1209 "Wrap the FORMS of a definition body."
1210 (if edebug-def-interactive
1211 (` (let (((, (edebug-interactive-p-name))
1213 (, (edebug-make-enter-wrapper forms
))))
1214 (edebug-make-enter-wrapper forms
)))
1217 (defun edebug-make-enter-wrapper (forms)
1218 ;; Generate the enter wrapper for some forms of a definition.
1219 ;; This is not to be used for the body of other forms, e.g. `while',
1220 ;; since it wraps the list of forms with a call to `edebug-enter'.
1221 ;; Uses the dynamically bound vars edebug-def-name and edebug-def-args.
1222 ;; Do this after parsing since that may find a name.
1223 (setq edebug-def-name
1224 (or edebug-def-name edebug-old-def-name
(edebug-gensym "edebug-anon")))
1226 (quote (, edebug-def-name
))
1227 (, (if edebug-inside-func
1229 ;; Doesn't work with more than one def-body!!
1230 ;; But the list will just be reversed.
1231 (nreverse edebug-def-args
))))
1233 (function (lambda () (,@ forms
)))
1237 (defvar edebug-form-begin-marker
) ; the mark for def being instrumented
1239 (defvar edebug-offset-index
) ; the next available offset index.
1240 (defvar edebug-offset-list
) ; the list of offset positions.
1242 (defun edebug-inc-offset (offset)
1243 ;; modifies edebug-offset-index and edebug-offset-list
1244 ;; accesses edebug-func-marc and buffer point
1247 (setq edebug-offset-list
(cons (- offset edebug-form-begin-marker
)
1249 edebug-offset-index
(1+ edebug-offset-index
))))
1252 (defun edebug-make-before-and-after-form (before-index form after-index
)
1253 ;; Return the edebug form for the current function at offset BEFORE-INDEX
1254 ;; given FORM. Looks like:
1255 ;; (edebug-after (edebug-before BEFORE-INDEX) AFTER-INDEX FORM)
1256 ;; Also increment the offset index for subsequent use.
1257 ;; if (not edebug-stop-before-symbols) and form is a symbol,
1258 ;; then don't call edebug-before.
1260 (list 'edebug-before before-index
)
1263 (defun edebug-make-after-form (form after-index
)
1264 ;; Like edebug-make-before-and-after-form, but only after.
1265 (list 'edebug-after
0 after-index form
))
1268 (defun edebug-unwrap (sexp)
1269 "Return the unwrapped SEXP or return it as is if it is not wrapped.
1270 The SEXP might be the result of wrapping a body, which is a list of
1271 expressions; a `progn' form will be returned enclosing these forms."
1274 ((eq 'edebug-after
(car sexp
))
1276 ((eq 'edebug-enter
(car sexp
))
1277 (let ((forms (nthcdr 2 (nth 1 (nth 3 sexp
)))))
1278 (if (> (length forms
) 1)
1279 (cons 'progn forms
) ;; could return (values forms) instead.
1281 (t sexp
);; otherwise it is not wrapped, so just return it.
1285 (defun edebug-unwrap* (sexp)
1286 "Return the sexp recursively unwrapped."
1287 (let ((new-sexp (edebug-unwrap sexp
)))
1288 (while (not (eq sexp new-sexp
))
1290 new-sexp
(edebug-unwrap sexp
)))
1291 (if (consp new-sexp
)
1292 (mapcar 'edebug-unwrap
* new-sexp
)
1296 (defun edebug-defining-form (cursor form-begin form-end speclist
)
1297 ;; Process the defining form, starting outside the form.
1298 ;; The speclist is a generated list spec that looks like:
1299 ;; (("def-symbol" defining-form-spec-sans-&define))
1300 ;; Skip the first offset.
1301 (edebug-set-cursor cursor
(edebug-cursor-expressions cursor
)
1302 (cdr (edebug-cursor-offsets cursor
)))
1303 (edebug-make-form-wrapper
1305 form-begin
(1- form-end
)
1308 (defun edebug-make-form-wrapper (cursor form-begin form-end
1310 ;; Wrap a form, usually a defining form, but any evaluated one.
1311 ;; If speclist is non-nil, this is being called by edebug-defining-form.
1312 ;; Otherwise it is being called from edebug-read-and-maybe-wrap-form1.
1313 ;; This is a hack, but I havent figured out a simpler way yet.
1314 (let* ((form-data-entry (edebug-get-form-data-entry form-begin form-end
))
1315 ;; Set this marker before parsing.
1316 (edebug-form-begin-marker
1318 (edebug-form-data-begin form-data-entry
)
1319 ;; Buffer must be current-buffer for this to work:
1320 (set-marker (make-marker) form-begin
))))
1322 (let (edebug-offset-list
1323 (edebug-offset-index 0)
1326 ;; (edebug-containing-def-name edebug-def-name)
1327 ;; Get name from form-data, if any.
1328 (edebug-old-def-name (edebug-form-data-name form-data-entry
))
1331 edebug-def-interactive
1332 edebug-inside-func
;; whether wrapped code executes inside a function.
1337 (edebug-match cursor speclist
)
1339 ;; else wrap as an enter-form.
1340 (edebug-make-enter-wrapper (list (edebug-form cursor
)))))
1342 ;; Set the name here if it was not set by edebug-make-enter-wrapper.
1343 (setq edebug-def-name
1344 (or edebug-def-name edebug-old-def-name
(edebug-gensym "edebug-anon")))
1346 ;; Add this def as a dependent of containing def. Buggy.
1347 '(if (and edebug-containing-def-name
1348 (not (get edebug-containing-def-name
'edebug-dependents
)))
1349 (put edebug-containing-def-name
'edebug-dependents
1350 (cons edebug-def-name
1351 (get edebug-containing-def-name
1352 'edebug-dependents
))))
1354 ;; Create a form-data-entry or modify existing entry's markers.
1355 ;; In the latter case, pointers to the entry remain eq.
1356 (if (not form-data-entry
)
1357 (setq form-data-entry
1358 (edebug-make-form-data-entry
1360 edebug-form-begin-marker
1361 ;; Buffer must be current-buffer.
1362 (set-marker (make-marker) form-end
)
1364 (edebug-set-form-data-entry
1365 form-data-entry edebug-def-name
;; in case name is changed
1366 form-begin form-end
))
1368 ;; (message "defining: %s" edebug-def-name) (sit-for 2)
1369 (edebug-make-top-form-data-entry form-data-entry
)
1370 (message "Edebug: %s" edebug-def-name
)
1371 ;;(debug edebug-def-name)
1373 ;; Destructively reverse edebug-offset-list and make vector from it.
1374 (setq edebug-offset-list
(vconcat (nreverse edebug-offset-list
)))
1376 ;; Side effects on the property list of edebug-def-name.
1377 (edebug-clear-frequency-count edebug-def-name
)
1378 (edebug-clear-coverage edebug-def-name
)
1380 ;; Set up the initial window data.
1381 (if (not edebug-top-window-data
) ;; if not already set, do it now.
1382 (let ((window ;; Find the best window for this buffer.
1383 (or (get-buffer-window (current-buffer))
1384 (selected-window))))
1385 (setq edebug-top-window-data
1386 (cons window
(window-start window
)))))
1388 ;; Store the edebug data in symbol's property list.
1389 (put edebug-def-name
'edebug
1390 ;; A struct or vector would be better here!!
1391 (list edebug-form-begin-marker
1392 nil
; clear breakpoints
1394 edebug-top-window-data
1400 (defun edebug-clear-frequency-count (name)
1401 ;; Create initial frequency count vector.
1402 ;; For each stop point, the counter is incremented each time it is visited.
1403 (put name
'edebug-freq-count
1404 (make-vector (length edebug-offset-list
) 0)))
1407 (defun edebug-clear-coverage (name)
1408 ;; Create initial coverage vector.
1409 ;; Only need one per expression, but it is simpler to use stop points.
1410 (put name
'edebug-coverage
1411 (make-vector (length edebug-offset-list
) 'unknown
)))
1414 (defun edebug-form (cursor)
1415 ;; Return the instrumented form for the following form.
1416 ;; Add the point offsets to the edebug-offset-list for the form.
1417 (let* ((form (edebug-top-element-required cursor
"Expected form"))
1418 (offset (edebug-top-offset cursor
)))
1422 ;; The first offset for a list form is for the list form itself.
1423 (if (eq 'quote
(car form
))
1425 (let* ((head (car form
))
1426 (spec (and (symbolp head
) (get-edebug-spec head
)))
1427 (new-cursor (edebug-new-cursor form offset
)))
1428 ;; Find out if this is a defining form from first symbol.
1429 ;; An indirect spec would not work here, yet.
1430 (if (and (consp spec
) (eq '&define
(car spec
)))
1431 (edebug-defining-form
1433 (car offset
);; before the form
1434 (edebug-after-offset cursor
)
1435 (cons (symbol-name head
) (cdr spec
)))
1436 ;; Wrap a regular form.
1437 (edebug-make-before-and-after-form
1438 (edebug-inc-offset (car offset
))
1439 (edebug-list-form new-cursor
)
1440 ;; After processing the list form, the new-cursor is left
1441 ;; with the offset after the form.
1442 (edebug-inc-offset (edebug-cursor-offsets new-cursor
))))
1447 ;; Check for constant symbols that don't get wrapped.
1448 ((or (memq form
'(t nil
))
1449 (and (fboundp 'edebug-keywordp
) (edebug-keywordp form
)))
1452 ;; This option may go away.
1453 (edebug-stop-before-symbols
1454 (edebug-make-before-and-after-form
1455 (edebug-inc-offset (car offset
))
1457 (edebug-inc-offset (cdr offset
))
1460 (t ;; just a variable
1461 (edebug-make-after-form form
(edebug-inc-offset (cdr offset
))))))
1463 ;; Anything else is self-evaluating.
1465 (edebug-move-cursor cursor
))))
1468 (defsubst edebug-forms
(cursor) (edebug-match cursor
'(&rest form
)))
1469 (defsubst edebug-sexps
(cursor) (edebug-match cursor
'(&rest sexp
)))
1471 (defsubst edebug-list-form-args
(head cursor
)
1472 ;; Process the arguments of a list form given that head of form is a symbol.
1473 ;; Helper for edebug-list-form
1474 (let ((spec (get-edebug-spec head
)))
1479 ;; It is a speclist.
1480 (let (edebug-best-error
1481 edebug-error-point
);; This may not be needed.
1482 (edebug-match-sublist cursor spec
)))
1483 ((eq t spec
) (edebug-forms cursor
))
1484 ((eq 0 spec
) (edebug-sexps cursor
))
1485 ((symbolp spec
) (funcall spec cursor
));; Not used by edebug,
1486 ; but leave it in for compatibility.
1488 ;; No edebug-form-spec provided.
1489 ((edebug-macrop head
)
1490 (if edebug-eval-macro-args
1491 (edebug-forms cursor
)
1492 (edebug-sexps cursor
)))
1493 (t ;; Otherwise it is a function call.
1494 (edebug-forms cursor
)))))
1497 (defun edebug-list-form (cursor)
1498 ;; Return an instrumented form built from the list form.
1499 ;; The after offset will be left in the cursor after processing the form.
1500 (let ((head (edebug-top-element-required cursor
"Expected elements"))
1501 ;; Prevent backtracking whenever instrumenting.
1503 ;; A list form is never optional because it matches anything.
1504 (edebug-&optional nil
)
1506 ;; Skip the first offset.
1507 (edebug-set-cursor cursor
(edebug-cursor-expressions cursor
)
1508 (cdr (edebug-cursor-offsets cursor
)))
1510 ((null head
) nil
) ; () is legal.
1515 (edebug-syntax-error "nil head"))
1516 ((eq head
'interactive-p
)
1517 ;; Special case: replace (interactive-p) with variable
1518 (setq edebug-def-interactive
'check-it
)
1519 (edebug-move-cursor cursor
)
1520 (edebug-interactive-p-name))
1522 (cons head
(edebug-list-form-args
1523 head
(edebug-move-cursor cursor
))))))
1526 (if (and (listp head
) (eq (car head
) ',))
1527 (edebug-match cursor
'(("," def-form
) body
))
1528 ;; Process anonymous function and args.
1529 ;; This assumes no anonymous macros.
1530 (edebug-match-specs cursor
'(lambda-expr body
) 'edebug-match-specs
)))
1532 (t (edebug-syntax-error
1533 "Head of list form must be a symbol or lambda expression.")))
1536 ;;; Matching of specs.
1538 (defvar edebug-after-dotted-spec nil
)
1540 (defvar edebug-matching-depth
0) ;; initial value
1541 (defconst edebug-max-depth
150) ;; maximum number of matching recursions.
1544 ;;; Failure to match
1546 ;; This throws to no-match, if there are higher alternatives.
1547 ;; Otherwise it signals an error. The place of the error is found
1548 ;; with the two before- and after-offset functions.
1550 (defun edebug-no-match (cursor &rest edebug-args
)
1551 ;; Throw a no-match, or signal an error immediately if gate is active.
1552 ;; Remember this point in case we need to report this error.
1553 (setq edebug-error-point
(or edebug-error-point
1554 (edebug-before-offset cursor
))
1555 edebug-best-error
(or edebug-best-error edebug-args
))
1556 (if (and edebug-gate
(not edebug-
&optional
))
1558 (if edebug-error-point
1559 (goto-char edebug-error-point
))
1560 (apply 'edebug-syntax-error edebug-args
))
1561 (funcall 'throw
'no-match edebug-args
)))
1564 (defun edebug-match (cursor specs
)
1565 ;; Top level spec matching function.
1566 ;; Used also at each lower level of specs.
1567 (let (edebug-&optional
1571 (edebug-gate edebug-gate
) ;; locally bound to limit effect
1573 (edebug-match-specs cursor specs
'edebug-match-specs
)))
1576 (defun edebug-match-one-spec (cursor spec
)
1577 ;; Match one spec, which is not a keyword &-spec.
1579 ((symbolp spec
) (edebug-match-symbol cursor spec
))
1580 ((vectorp spec
) (edebug-match cursor
(append spec nil
)))
1581 ((stringp spec
) (edebug-match-string cursor spec
))
1582 ((listp spec
) (edebug-match-list cursor spec
))
1586 (defun edebug-match-specs (cursor specs remainder-handler
)
1587 ;; Append results of matching the list of specs.
1588 ;; The first spec is handled and the remainder-handler handles the rest.
1589 (let ((edebug-matching-depth
1590 (if (> edebug-matching-depth edebug-max-depth
)
1591 (error "too deep - perhaps infinite loop in spec?")
1592 (1+ edebug-matching-depth
))))
1596 ;; Is the spec dotted?
1598 (let ((edebug-dotted-spec t
));; Containing spec list was dotted.
1599 (edebug-match-specs cursor
(list specs
) remainder-handler
)))
1601 ;; Is the form dotted?
1602 ((not (listp (edebug-cursor-expressions cursor
)));; allow nil
1603 (if (not edebug-dotted-spec
)
1604 (edebug-no-match cursor
"Dotted spec required."))
1605 ;; Cancel dotted spec and dotted form.
1606 (let ((edebug-dotted-spec)
1607 (this-form (edebug-cursor-expressions cursor
))
1608 (this-offset (edebug-cursor-offsets cursor
)))
1609 ;; Wrap the form in a list, (by changing the cursor??)...
1610 (edebug-set-cursor cursor
(list this-form
) this-offset
)
1611 ;; and process normally, then unwrap the result.
1612 (car (edebug-match-specs cursor specs remainder-handler
))))
1614 (t;; Process normally.
1615 (let* ((spec (car specs
))
1617 (first-char (and (symbolp spec
) (aref (symbol-name spec
) 0))))
1618 ;;(message "spec = %s first char = %s" spec first-char) (sit-for 1)
1621 ((eq ?
& first-char
);; "&" symbols take all following specs.
1622 (funcall (get-edebug-spec spec
) cursor
(cdr specs
)))
1623 ((eq ?
: first-char
);; ":" symbols take one following spec.
1624 (setq rest
(cdr (cdr specs
)))
1625 (funcall (get-edebug-spec spec
) cursor
(car (cdr specs
))))
1626 (t;; Any other normal spec.
1627 (setq rest
(cdr specs
))
1628 (edebug-match-one-spec cursor spec
)))
1629 (funcall remainder-handler cursor rest remainder-handler
)))))))
1632 ;; Define specs for all the symbol specs with functions used to process them.
1633 ;; Perhaps we shouldn't be doing this with edebug-form-specs since the
1634 ;; user may want to define macros or functions with the same names.
1635 ;; We could use an internal obarray for these primitive specs.
1638 (function (lambda (pair)
1639 (put (car pair
) 'edebug-form-spec
(cdr pair
))))
1640 '((&optional . edebug-match-
&optional
)
1641 (&rest . edebug-match-
&rest
)
1642 (&or . edebug-match-
&or
)
1643 (form . edebug-match-form
)
1644 (sexp . edebug-match-sexp
)
1645 (body . edebug-match-body
)
1646 (&define . edebug-match-
&define
)
1647 (name . edebug-match-name
)
1648 (:name . edebug-match-colon-name
)
1649 (arg . edebug-match-arg
)
1650 (def-body . edebug-match-def-body
)
1651 (def-form . edebug-match-def-form
)
1652 ;; Less frequently used:
1653 ;; (function . edebug-match-function)
1654 (lambda-expr . edebug-match-lambda-expr
)
1655 (¬ . edebug-match-
¬
)
1656 (&key . edebug-match-
&key
)
1657 (place . edebug-match-place
)
1658 (gate . edebug-match-gate
)
1659 ;; (nil . edebug-match-nil) not this one - special case it.
1662 (defun edebug-match-symbol (cursor symbol
)
1663 ;; Match a symbol spec.
1664 (let* ((spec (get-edebug-spec symbol
)))
1668 ;; It is an indirect spec.
1669 (edebug-match cursor spec
)
1670 ;; Otherwise it should be the symbol name of a function.
1671 ;; There could be a bug here - maybe need to do edebug-match bindings.
1672 (funcall spec cursor
)))
1674 ((null symbol
) ;; special case this.
1675 (edebug-match-nil cursor
))
1677 ((fboundp symbol
) ; is it a predicate?
1678 (let ((sexp (edebug-top-element-required cursor
"Expected" symbol
)))
1679 ;; Special case for edebug-`.
1680 (if (and (listp sexp
) (eq (car sexp
) ',))
1681 (edebug-match cursor
'(("," def-form
)))
1682 (if (not (funcall symbol sexp
))
1683 (edebug-no-match cursor symbol
"failed"))
1684 (edebug-move-cursor cursor
)
1686 (t (error "%s is not a form-spec or function" symbol
))
1690 (defun edebug-match-sexp (cursor)
1691 (list (prog1 (edebug-top-element-required cursor
"Expected sexp")
1692 (edebug-move-cursor cursor
))))
1694 (defun edebug-match-form (cursor)
1695 (list (edebug-form cursor
)))
1697 (defalias 'edebug-match-place
'edebug-match-form
)
1698 ;; Currently identical to edebug-match-form.
1699 ;; This is for common lisp setf-style place arguments.
1701 (defsubst edebug-match-body
(cursor) (edebug-forms cursor
))
1703 (defun edebug-match-&optional
(cursor specs
)
1704 ;; Keep matching until one spec fails.
1705 (edebug-&optional-wrapper cursor specs
'edebug-
&optional-wrapper
))
1707 (defun edebug-&optional-wrapper
(cursor specs remainder-handler
)
1709 (edebug-&optional specs
)
1711 (this-form (edebug-cursor-expressions cursor
))
1712 (this-offset (edebug-cursor-offsets cursor
)))
1713 (if (null (catch 'no-match
1715 (edebug-match-specs cursor specs remainder-handler
))
1716 ;; Returning nil means no no-match was thrown.
1719 ;; no-match, but don't fail; just reset cursor and return nil.
1720 (edebug-set-cursor cursor this-form this-offset
)
1724 (defun edebug-&rest-wrapper
(cursor specs remainder-handler
)
1725 (if (null specs
) (setq specs edebug-
&rest
))
1726 ;; Reuse the &optional handler with this as the remainder handler.
1727 (edebug-&optional-wrapper cursor specs remainder-handler
))
1729 (defun edebug-match-&rest
(cursor specs
)
1730 ;; Repeatedly use specs until failure.
1731 (let ((edebug-&rest specs
) ;; remember these
1734 (edebug-&rest-wrapper cursor specs
'edebug-
&rest-wrapper
)))
1737 (defun edebug-match-&or
(cursor specs
)
1738 ;; Keep matching until one spec succeeds, and return its results.
1739 ;; If none match, fail.
1740 ;; This needs to be optimized since most specs spend time here.
1741 (let ((original-specs specs
)
1742 (this-form (edebug-cursor-expressions cursor
))
1743 (this-offset (edebug-cursor-offsets cursor
)))
1748 (let (edebug-gate ;; only while matching each spec
1751 ;; Doesn't support e.g. &or symbolp &rest form
1752 (edebug-match-one-spec cursor
(car specs
)))))
1753 ;; Match failed, so reset and try again.
1754 (setq specs
(cdr specs
))
1755 ;; Reset the cursor for the next match.
1756 (edebug-set-cursor cursor this-form this-offset
))
1758 (apply 'edebug-no-match cursor
"Expected one of" original-specs
))
1762 (defun edebug-match-¬
(cursor specs
)
1763 ;; If any specs match, then fail
1764 (if (null (catch 'no-match
1765 (let ((edebug-gate nil
))
1767 (edebug-match-&or cursor specs
)))
1769 ;; This means something matched, so it is a no match.
1770 (edebug-no-match cursor
"Unexpected"))
1771 ;; This means nothing matched, so it is OK.
1772 nil
) ;; So, return nothing
1775 (def-edebug-spec &key edebug-match-
&key
)
1777 (defun edebug-match-&key
(cursor specs
)
1778 ;; Following specs must look like (<name> <spec>) ...
1779 ;; where <name> is the name of a keyword, and spec is its spec.
1780 ;; This really doesn't save much over the expanded form and takes time.
1784 (mapcar (function (lambda (pair)
1785 (vector (format ":%s" (car pair
))
1790 (defun edebug-match-gate (cursor)
1791 ;; Simply set the gate to prevent backtracking at this level.
1792 (setq edebug-gate t
)
1796 (defun edebug-match-list (cursor specs
)
1797 ;; The spec is a list, but what kind of list, and what context?
1798 (if edebug-dotted-spec
1799 ;; After dotted spec but form did not contain dot,
1800 ;; so match list spec elements as if spliced in.
1802 (let ((edebug-dotted-spec))
1803 (edebug-match-specs cursor specs
'edebug-match-specs
))
1804 ;; If it matched, really clear the dotted-spec flag.
1805 (setq edebug-dotted-spec nil
))
1806 (let ((spec (car specs
))
1807 (form (edebug-top-element-required cursor
"Expected" specs
)))
1810 (let ((spec (car (cdr specs
))))
1813 ;; Special case: spec quotes a symbol to match.
1814 ;; Change in future. Use "..." instead.
1815 (if (not (eq spec form
))
1816 (edebug-no-match cursor
"Expected" spec
))
1817 (edebug-move-cursor cursor
)
1818 (setq edebug-gate t
)
1821 (error "Bad spec: %s" specs
)))))
1825 (list (edebug-match-sublist
1826 ;; First offset is for the list form itself.
1827 ;; Treat nil as empty list.
1828 (edebug-new-cursor form
(cdr (edebug-top-offset cursor
)))
1830 (edebug-move-cursor cursor
)))
1832 ((and (eq 'vector spec
) (vectorp form
))
1833 ;; Special case: match a vector with the specs.
1834 (let ((result (edebug-match-sublist
1836 form
(cdr (edebug-top-offset cursor
)))
1838 (edebug-move-cursor cursor
)
1839 (list (apply 'vector result
))))
1841 (t (edebug-no-match cursor
"Expected" specs
)))
1845 (defun edebug-match-sublist (cursor specs
)
1846 ;; Match a sublist of specs.
1847 (let (edebug-&optional
1849 ;;edebug-error-point
1852 ;; match with edebug-match-specs so edebug-best-error is not bound.
1853 (edebug-match-specs cursor specs
'edebug-match-specs
)
1854 (if (not (edebug-empty-cursor cursor
))
1855 (if edebug-best-error
1856 (apply 'edebug-no-match cursor edebug-best-error
)
1857 ;; A failed &rest or &optional spec may leave some args.
1858 (edebug-no-match cursor
"Failed matching" specs
)
1862 (defun edebug-match-string (cursor spec
)
1863 (let ((sexp (edebug-top-element-required cursor
"Expected" spec
)))
1864 (if (not (eq (intern spec
) sexp
))
1865 (edebug-no-match cursor
"Expected" spec
)
1866 ;; Since it matched, failure means immediate error, unless &optional.
1867 (setq edebug-gate t
)
1868 (edebug-move-cursor cursor
)
1872 (defun edebug-match-nil (cursor)
1873 ;; There must be nothing left to match a nil.
1874 (if (not (edebug-empty-cursor cursor
))
1875 (edebug-no-match cursor
"Unmatched argument(s)")
1879 (defun edebug-match-function (cursor)
1880 (error "Use function-form instead of function in edebug spec"))
1882 (defun edebug-match-&define
(cursor specs
)
1883 ;; Match a defining form.
1884 ;; Normally, &define is interpreted specially other places.
1885 ;; This should only be called inside of a spec list to match the remainder
1886 ;; of the current list. e.g. ("lambda" &define args def-body)
1887 (edebug-make-form-wrapper
1889 (edebug-before-offset cursor
)
1890 ;; Find the last offset in the list.
1891 (let ((offsets (edebug-cursor-offsets cursor
)))
1892 (while (consp offsets
) (setq offsets
(cdr offsets
)))
1896 (defun edebug-match-lambda-expr (cursor)
1897 ;; The expression must be a function.
1898 ;; This will match any list form that begins with a symbol
1899 ;; that has an edebug-form-spec beginning with &define. In
1900 ;; practice, only lambda expressions should be used.
1901 ;; I could add a &lambda specification to avoid confusion.
1902 (let* ((sexp (edebug-top-element-required
1903 cursor
"Expected lambda expression"))
1904 (offset (edebug-top-offset cursor
))
1905 (head (and (consp sexp
) (car sexp
)))
1906 (spec (and (symbolp head
) (get-edebug-spec head
)))
1907 (edebug-inside-func nil
))
1908 ;; Find out if this is a defining form from first symbol.
1909 (if (and (consp spec
) (eq '&define
(car spec
)))
1912 (edebug-defining-form
1913 (edebug-new-cursor sexp offset
)
1914 (car offset
);; before the sexp
1915 (edebug-after-offset cursor
)
1916 (cons (symbol-name head
) (cdr spec
))))
1917 (edebug-move-cursor cursor
))
1918 (edebug-no-match cursor
"Expected lambda expression")
1922 (defun edebug-match-name (cursor)
1923 ;; Set the edebug-def-name bound in edebug-defining-form.
1924 (let ((name (edebug-top-element-required cursor
"Expected name")))
1925 ;; Maybe strings and numbers could be used.
1926 (if (not (symbolp name
))
1927 (edebug-no-match cursor
"Symbol expected for name of definition"))
1928 (setq edebug-def-name
1930 ;; Construct a new name by appending to previous name.
1931 (intern (format "%s@%s" edebug-def-name name
))
1933 (edebug-move-cursor cursor
)
1936 (defun edebug-match-colon-name (cursor spec
)
1937 ;; Set the edebug-def-name to the spec.
1938 (setq edebug-def-name
1940 ;; Construct a new name by appending to previous name.
1941 (intern (format "%s@%s" edebug-def-name spec
))
1945 (defun edebug-match-arg (cursor)
1946 ;; set the def-args bound in edebug-defining-form
1947 (let ((edebug-arg (edebug-top-element-required cursor
"Expected arg")))
1948 (if (or (not (symbolp edebug-arg
))
1949 (edebug-lambda-list-keywordp edebug-arg
))
1950 (edebug-no-match cursor
"Bad argument:" edebug-arg
))
1951 (edebug-move-cursor cursor
)
1952 (setq edebug-def-args
(cons edebug-arg edebug-def-args
))
1955 (defun edebug-match-def-form (cursor)
1956 ;; Like form but the form is wrapped in edebug-enter form.
1957 ;; The form is assumed to be executing outside of the function context.
1958 ;; This is a hack for now, since a def-form might execute inside as well.
1959 ;; Not to be used otherwise.
1960 (let ((edebug-inside-func nil
))
1961 (list (edebug-make-enter-wrapper (list (edebug-form cursor
))))))
1963 (defun edebug-match-def-body (cursor)
1964 ;; Like body but body is wrapped in edebug-enter form.
1965 ;; The body is assumed to be executing inside of the function context.
1966 ;; Not to be used otherwise.
1967 (let ((edebug-inside-func t
))
1968 (list (edebug-wrap-def-body (edebug-forms cursor
)))))
1971 ;;;; Edebug Form Specs
1972 ;;; ==========================================================
1973 ;;; See cl-specs.el for common lisp specs.
1975 ;;;;* Spec for def-edebug-spec
1978 (defun edebug-spec-p (object)
1979 "Return non-nil if OBJECT is a symbol with an edebug-form-spec property."
1980 (and (symbolp object
)
1981 (get object
'edebug-form-spec
)))
1983 (def-edebug-spec def-edebug-spec
1984 ;; Top level is different from lower levels.
1985 (&define
:name edebug-spec name
1986 &or
"nil" edebug-spec-p
"t" "0" (&rest edebug-spec
)))
1988 (def-edebug-spec edebug-spec-list
1989 ;; A list must have something in it, or it is nil, a symbolp
1990 ((edebug-spec .
[&or nil edebug-spec
])))
1992 (def-edebug-spec edebug-spec
1994 (vector &rest edebug-spec
) ; matches a vector
1995 ("vector" &rest edebug-spec
) ; matches a vector spec
1999 [edebug-lambda-list-keywordp
&rest edebug-spec
]
2000 ;; [edebug-keywordp gate edebug-spec] ;; need edebug-keywordp for this.
2001 edebug-spec-p
;; Including all the special ones e.g. form.
2002 symbolp
;; a predicate
2006 ;;;* Emacs special forms and some functions.
2008 ;; quote expects only one argument, although it allows any number.
2009 (def-edebug-spec quote sexp
)
2011 ;; The standard defining forms.
2012 (def-edebug-spec defconst defvar
)
2013 (def-edebug-spec defvar
(symbolp &optional form stringp
))
2015 (def-edebug-spec defun
2016 (&define name lambda-list
2018 [&optional
("interactive" interactive
)]
2020 (def-edebug-spec defmacro
2021 (&define name lambda-list def-body
))
2023 (def-edebug-spec arglist lambda-list
) ;; deprecated - use lambda-list.
2025 (def-edebug-spec lambda-list
2027 [&optional
["&optional" arg
&rest arg
]]
2028 &optional
["&rest" arg
]
2031 (def-edebug-spec interactive
2032 (&optional
&or stringp def-form
))
2034 ;; A function-form is for an argument that may be a function or a form.
2035 ;; This specially recognizes anonymous functions quoted with quote.
2036 (def-edebug-spec function-form
2037 ;; form at the end could also handle "function",
2038 ;; but recognize it specially to avoid wrapping function forms.
2039 (&or
([&or
"quote" "function"] &or symbolp lambda-expr
) form
))
2041 ;; function expects a symbol or a lambda or macro expression
2042 ;; A macro is allowed by Emacs.
2043 (def-edebug-spec function
(&or symbolp lambda-expr
))
2045 ;; lambda is a macro in emacs 19.
2046 (def-edebug-spec lambda
(&define lambda-list
2048 [&optional
("interactive" interactive
)]
2051 ;; A macro expression is a lambda expression with "macro" prepended.
2052 (def-edebug-spec macro
(&define
"lambda" lambda-list def-body
))
2054 ;; (def-edebug-spec anonymous-form ((&or ["lambda" lambda] ["macro" macro])))
2056 ;; Standard functions that take function-forms arguments.
2057 (def-edebug-spec mapcar
(function-form form
))
2058 (def-edebug-spec mapconcat
(function-form form form
))
2059 (def-edebug-spec mapatoms
(function-form &optional form
))
2060 (def-edebug-spec apply
(function-form &rest form
))
2061 (def-edebug-spec funcall
(function-form &rest form
))
2063 (def-edebug-spec let
2064 ((&rest
&or
(symbolp &optional form
) symbolp
)
2067 (def-edebug-spec let
* let
)
2069 (def-edebug-spec setq
(&rest symbolp form
))
2070 (def-edebug-spec setq-default setq
)
2072 (def-edebug-spec cond
(&rest
(&rest form
)))
2074 (def-edebug-spec condition-case
2077 &rest
(symbolp body
)))
2080 (def-edebug-spec \
` (backquote-form))
2082 ;; Supports quotes inside backquotes,
2083 ;; but only at the top level inside unquotes.
2084 (def-edebug-spec backquote-form
2086 ([&or
"," ",@"] &or
("quote" backquote-form
) form
)
2087 (backquote-form &rest backquote-form
)
2088 ;; If you use dotted forms in backquotes, replace the previous line
2089 ;; with the following. This takes quite a bit more stack space, however.
2090 ;; (backquote-form . [&or nil backquote-form])
2091 (vector &rest backquote-form
)
2094 ;; Special version of backquote that instruments backquoted forms
2095 ;; destined to be evaluated, usually as the result of a
2096 ;; macroexpansion. Backquoted code can only have unquotes (, and ,@)
2097 ;; in places where list forms are allowed, and predicates. If the
2098 ;; backquote is used in a macro, unquoted code that come from
2099 ;; arguments must be instrumented, if at all, with def-form not def-body.
2101 ;; We could assume that all forms (not nested in other forms)
2102 ;; in arguments of macros should be def-forms, whether or not the macros
2103 ;; are defined with edebug-` but this would be expensive.
2105 ;; ,@ might have some problems.
2107 (defalias 'edebug-\
` '\
`) ;; same macro as regular backquote.
2108 (def-edebug-spec edebug-\
` (def-form))
2110 ;; Assume immediate quote in unquotes mean backquote at next higher level.
2111 (def-edebug-spec , (&or
("quote" edebug-
`) def-form
))
2112 (def-edebug-spec ,@ (&define
;; so (,@ form) is never wrapped.
2113 &or
("quote" edebug-
`) def-form
))
2115 ;; New byte compiler.
2116 (def-edebug-spec defsubst defun
)
2117 (def-edebug-spec dont-compile t
)
2118 (def-edebug-spec eval-when-compile t
)
2119 (def-edebug-spec eval-and-compile t
)
2124 ;; Some miscellaneous specs for macros in public packages.
2127 ;; advice.el by Hans Chalupsky (hans@cs.buffalo.edu)
2129 (def-edebug-spec ad-dolist
((symbolp form
&optional form
) body
))
2130 (def-edebug-spec defadvice
2131 (&define name
;; thing being advised.
2132 (name ;; class is [&or "before" "around" "after"
2133 ;; "activation" "deactivation"]
2134 name
;; name of advice
2135 &rest sexp
;; optional position and flags
2138 [&optional
("interactive" interactive
)]
2141 ;;; The debugger itself
2143 (defvar edebug-active nil
) ;; Non-nil when edebug is active
2145 ;;; add minor-mode-alist entry
2146 (or (assq 'edebug-active minor-mode-alist
)
2147 (setq minor-mode-alist
(cons (list 'edebug-active
" *Debugging*")
2150 (defvar edebug-stack nil
)
2151 ;; Stack of active functions evaluated via edebug.
2152 ;; Should be nil at the top level.
2154 (defvar edebug-stack-depth -
1)
2155 ;; Index of last edebug-stack item.
2157 (defvar edebug-offset-indices nil
)
2158 ;; Stack of offset indices of visited edebug sexps.
2159 ;; Should be nil at the top level.
2160 ;; Each function adds one cons. Top is modified with setcar.
2163 (defvar edebug-entered nil
2164 ;; Non-nil if edebug has already been entered at this recursive edit level.
2165 ;; This should stay nil at the top level.
2168 ;; Should these be options?
2169 (defconst edebug-debugger
'edebug
2170 ;; Name of function to use for debugging when error or quit occurs.
2171 ;; Set this to 'debug if you want to debug edebug.
2175 ;; Dynamically bound variables, declared globally but left unbound.
2176 (defvar edebug-function
) ; the function being executed. change name!!
2177 (defvar edebug-args
) ; the arguments of the function
2178 (defvar edebug-data
) ; the edebug data for the function
2179 (defvar edebug-value
) ; the result of the expression
2180 (defvar edebug-after-index
)
2181 (defvar edebug-def-mark
) ; the mark for the definition
2182 (defvar edebug-freq-count
) ; the count of expression visits.
2183 (defvar edebug-coverage
) ; the coverage results of each expression of function.
2185 (defvar edebug-buffer
) ; which buffer the function is in.
2186 (defvar edebug-result
) ; the result of the function call returned by body
2187 (defvar edebug-outside-executing-macro
)
2188 (defvar edebug-outside-defining-kbd-macro
)
2190 (defvar edebug-execution-mode
'step
) ; Current edebug mode set by user.
2191 (defvar edebug-next-execution-mode nil
) ; Use once instead of initial mode.
2193 (defvar edebug-outside-debug-on-error
) ; the value of debug-on-error outside
2194 (defvar edebug-outside-debug-on-quit
) ; the value of debug-on-quit outside
2196 (defvar edebug-outside-pre-command-hook
)
2197 (defvar edebug-outside-post-command-hook
)
2198 (defvar edebug-outside-post-command-idle-hook
)
2201 (defvar pre-command-hook nil
)
2202 (defvar post-command-hook nil
)
2203 (defvar post-command-idle-hook nil
)
2205 (defvar cl-lexical-debug
) ;; Defined in cl.el
2207 ;;; Handling signals
2209 (if (not (fboundp 'edebug-original-signal
))
2210 (defalias 'edebug-original-signal
(symbol-function 'signal
)))
2211 ;; We should use advise for this!!
2213 (defun edebug-signal (edebug-signal-name edebug-signal-data
)
2214 "Signal an error. Args are SIGNAL-NAME, and associated DATA.
2215 A signal name is a symbol with an `error-conditions' property
2216 that is a list of condition names.
2217 A handler for any of those names will get to handle this signal.
2218 The symbol `error' should always be one of them.
2220 DATA should be a list. Its elements are printed as part of the error message.
2221 If the signal is handled, DATA is made available to the handler.
2222 See `condition-case'.
2224 This is the Edebug replacement for the standard `signal'. It should
2225 only be active while Edebug is. It checks `debug-on-error' to see
2226 whether it should call the debugger. When execution is resumed, the
2227 error is signaled again."
2228 (if (and (listp debug-on-error
) (memq edebug-signal-name debug-on-error
))
2229 (edebug 'error
(cons edebug-signal-name edebug-signal-data
)))
2230 ;; If we reach here without another non-local exit, then send signal again.
2231 ;; i.e. the signal is not continuable, yet.
2232 (edebug-original-signal edebug-signal-name edebug-signal-data
))
2237 (defun edebug-enter (edebug-function edebug-args edebug-body
)
2238 ;; Entering FUNC. The arguments are ARGS, and the body is BODY.
2239 ;; Setup edebug variables and evaluate BODY. This function is called
2240 ;; when a function evaluated with edebug-eval-top-level-form is entered.
2241 ;; Return the result of BODY.
2243 ;; Is this the first time we are entering edebug since
2244 ;; lower-level recursive-edit command?
2245 ;; More precisely, this tests whether Edebug is currently active.
2246 (if (not edebug-entered
)
2247 (let ((edebug-entered t
)
2248 ;; Binding max-lisp-eval-depth here is OK,
2249 ;; but not inside an unwind-protect.
2250 ;; Doing it here also keeps it from growing too large.
2251 (max-lisp-eval-depth (+ 100 max-lisp-eval-depth
)) ; too much??
2252 (max-specpdl-size (+ 200 max-specpdl-size
))
2254 (debugger edebug-debugger
) ; only while edebug is active.
2255 (edebug-outside-debug-on-error debug-on-error
)
2256 (edebug-outside-debug-on-quit debug-on-quit
)
2257 ;; Binding these may not be the right thing to do.
2258 ;; We want to allow the global values to be changed.
2259 (debug-on-error (or debug-on-error edebug-on-error
))
2260 (debug-on-quit edebug-on-quit
)
2262 ;; Lexical bindings must be uncompiled for this to work.
2263 (cl-lexical-debug t
)
2265 ;; Save the outside value of executing macro. (here??)
2266 (edebug-outside-executing-macro executing-kbd-macro
)
2267 (edebug-outside-pre-command-hook pre-command-hook
)
2268 (edebug-outside-post-command-hook post-command-hook
)
2269 (edebug-outside-post-command-idle-hook post-command-idle-hook
))
2271 (let (;; Don't keep reading from an executing kbd macro
2272 ;; within edebug unless edebug-continue-kbd-macro is
2273 ;; non-nil. Again, local binding may not be best.
2274 (executing-kbd-macro
2275 (if edebug-continue-kbd-macro executing-kbd-macro
))
2277 ;; Disable command hooks. This is essential when
2278 ;; a hook function is instrumented - to avoid infinite loop.
2279 ;; This may be more than we need, however.
2280 (pre-command-hook nil
)
2281 (post-command-hook nil
)
2282 (post-command-idle-hook nil
))
2283 (setq edebug-execution-mode
(or edebug-next-execution-mode
2285 edebug-execution-mode
)
2286 edebug-next-execution-mode nil
)
2287 ;; Bind signal to edebug-signal only while Edebug is active.
2288 (fset 'signal
'edebug-signal
)
2290 (edebug-enter edebug-function edebug-args edebug-body
)
2291 (fset 'signal
(symbol-function 'edebug-original-signal
))))
2292 ;; Reset global variables in case outside value was changed.
2293 (setq executing-kbd-macro edebug-outside-executing-macro
2294 pre-command-hook edebug-outside-pre-command-hook
2295 post-command-hook edebug-outside-post-command-hook
2296 post-command-idle-hook edebug-outside-post-command-idle-hook
2299 (let* ((edebug-data (get edebug-function
'edebug
))
2300 (edebug-def-mark (car edebug-data
)) ; mark at def start
2301 (edebug-freq-count (get edebug-function
'edebug-freq-count
))
2302 (edebug-coverage (get edebug-function
'edebug-coverage
))
2303 (edebug-buffer (marker-buffer edebug-def-mark
))
2305 (edebug-stack (cons edebug-function edebug-stack
))
2306 (edebug-offset-indices (cons 0 edebug-offset-indices
))
2308 (if (get edebug-function
'edebug-on-entry
)
2310 (setq edebug-execution-mode
'step
)
2311 (if (eq (get edebug-function
'edebug-on-entry
) 'temp
)
2312 (put edebug-function
'edebug-on-entry nil
))))
2314 (edebug-enter-trace edebug-body
)
2315 (funcall edebug-body
))
2319 (defun edebug-enter-trace (edebug-body)
2320 (let ((edebug-stack-depth (1+ edebug-stack-depth
))
2322 (edebug-print-trace-before
2323 (format "%s args: %s" edebug-function edebug-args
))
2324 (prog1 (setq edebug-result
(funcall edebug-body
))
2325 (edebug-print-trace-after
2326 (format "%s result: %s" edebug-function edebug-result
)))))
2328 (def-edebug-spec edebug-tracing
(form body
))
2330 (defmacro edebug-tracing
(msg &rest body
)
2331 "Print MSG in *edebug-trace* before and after evaluating BODY.
2332 The result of BODY is also printed."
2333 (` (let ((edebug-stack-depth (1+ edebug-stack-depth
))
2335 (edebug-print-trace-before (, msg
))
2336 (prog1 (setq edebug-result
(progn (,@ body
)))
2337 (edebug-print-trace-after
2338 (format "%s result: %s" (, msg
) edebug-result
))))))
2340 (defun edebug-print-trace-before (msg)
2341 "Function called to print trace info before expression evaluation.
2342 MSG is printed after `::::{ '."
2343 (edebug-trace-display
2344 edebug-trace-buffer
"%s{ %s" (make-string edebug-stack-depth ?\
:) msg
))
2346 (defun edebug-print-trace-after (msg)
2347 "Function called to print trace info after expression evaluation.
2348 MSG is printed after `::::} '."
2349 (edebug-trace-display
2350 edebug-trace-buffer
"%s} %s" (make-string edebug-stack-depth ?\
:) msg
))
2354 (defun edebug-slow-before (edebug-before-index)
2355 ;; Debug current function given BEFORE position.
2356 ;; Called from functions compiled with edebug-eval-top-level-form.
2357 ;; Return the before index.
2358 (setcar edebug-offset-indices edebug-before-index
)
2360 ;; Increment frequency count
2361 (aset edebug-freq-count edebug-before-index
2362 (1+ (aref edebug-freq-count edebug-before-index
)))
2364 (if (or (not (memq edebug-execution-mode
'(Go-nonstop next
)))
2365 (edebug-input-pending-p))
2366 (edebug-debugger edebug-before-index
'before nil
))
2367 edebug-before-index
)
2369 (defun edebug-fast-before (edebug-before-index)
2373 (defun edebug-slow-after (edebug-before-index edebug-after-index edebug-value
)
2374 ;; Debug current function given AFTER position and VALUE.
2375 ;; Called from functions compiled with edebug-eval-top-level-form.
2377 (setcar edebug-offset-indices edebug-after-index
)
2379 ;; Increment frequency count
2380 (aset edebug-freq-count edebug-after-index
2381 (1+ (aref edebug-freq-count edebug-after-index
)))
2382 (if edebug-test-coverage
(edebug-update-coverage))
2384 (if (and (eq edebug-execution-mode
'Go-nonstop
)
2385 (not (edebug-input-pending-p)))
2386 ;; Just return result.
2388 (edebug-debugger edebug-after-index
'after edebug-value
)
2391 (defun edebug-fast-after (edebug-before-index edebug-after-index edebug-value
)
2392 ;; Do nothing but return the value.
2395 (defun edebug-run-slow ()
2396 (defalias 'edebug-before
'edebug-slow-before
)
2397 (defalias 'edebug-after
'edebug-slow-after
))
2399 ;; This is not used, yet.
2400 (defun edebug-run-fast ()
2401 (defalias 'edebug-before
'edebug-fast-before
)
2402 (defalias 'edebug-after
'edebug-fast-after
))
2407 (defun edebug-update-coverage ()
2408 (let ((old-result (aref edebug-coverage edebug-after-index
)))
2410 ((eq 'ok-coverage old-result
))
2411 ((eq 'unknown old-result
)
2412 (aset edebug-coverage edebug-after-index edebug-value
))
2413 ;; Test if a different result.
2414 ((not (eq edebug-value old-result
))
2415 (aset edebug-coverage edebug-after-index
'ok-coverage
)))))
2418 ;; Dynamically declared unbound variables.
2419 (defvar edebug-arg-mode
) ; the mode, either before, after, or error
2420 (defvar edebug-breakpoints
)
2421 (defvar edebug-break-data
) ; break data for current function.
2422 (defvar edebug-break
) ; whether a break occurred.
2423 (defvar edebug-global-break
) ; whether a global break occurred.
2424 (defvar edebug-break-condition
) ; whether the breakpoint is conditional.
2426 (defvar edebug-break-result nil
)
2427 (defvar edebug-global-break-result nil
)
2430 (defun edebug-debugger (edebug-offset-index edebug-arg-mode edebug-value
)
2431 ;; Check breakpoints and pending input.
2432 ;; If edebug display should be updated, call edebug-display.
2433 ;; Return edebug-value.
2434 (let* (;; This needs to be here since breakpoints may be changed.
2435 (edebug-breakpoints (car (cdr edebug-data
))) ; list of breakpoints
2436 (edebug-break-data (assq edebug-offset-index edebug-breakpoints
))
2437 (edebug-break-condition (car (cdr edebug-break-data
)))
2438 (edebug-global-break
2439 (if edebug-global-break-condition
2441 (setq edebug-global-break-result
2442 (eval edebug-global-break-condition
))
2446 ;;; (edebug-trace "exp: %s" edebug-value)
2447 ;; Test whether we should break.
2449 (or edebug-global-break
2450 (and edebug-break-data
2451 (or (not edebug-break-condition
)
2452 (setq edebug-break-result
2453 (eval edebug-break-condition
))))))
2454 (if (and edebug-break
2455 (nth 2 edebug-break-data
)) ; is it temporary?
2456 ;; Delete the breakpoint.
2458 (cons (delq edebug-break-data edebug-breakpoints
)
2459 (cdr (cdr edebug-data
)))))
2461 ;; Display if mode is not go, continue, or Continue-fast
2462 ;; or break, or input is pending,
2463 (if (or (not (memq edebug-execution-mode
'(go continue Continue-fast
)))
2465 (edebug-input-pending-p))
2466 (edebug-display)) ; <--------------- display
2472 ;; window-start now stored with each function.
2473 ;;(defvar edebug-window-start nil)
2474 ;; Remember where each buffers' window starts between edebug calls.
2475 ;; This is to avoid spurious recentering.
2476 ;; Does this still need to be buffer-local??
2477 ;;(setq-default edebug-window-start nil)
2478 ;;(make-variable-buffer-local 'edebug-window-start)
2481 ;; Dynamically declared unbound vars
2482 (defvar edebug-point
) ; the point in edebug buffer
2483 (defvar edebug-outside-buffer
) ; the current-buffer outside of edebug
2484 (defvar edebug-outside-point
) ; the point outside of edebug
2485 (defvar edebug-outside-mark
) ; the mark outside of edebug
2486 (defvar edebug-window-data
) ; window and window-start for current function
2487 (defvar edebug-outside-windows
) ; outside window configuration
2488 (defvar edebug-eval-buffer
) ; for the evaluation list.
2489 (defvar edebug-outside-o-a-p
) ; outside overlay-arrow-position
2490 (defvar edebug-outside-o-a-s
) ; outside overlay-arrow-string
2491 (defvar edebug-outside-c-i-e-a
) ; outside cursor-in-echo-area
2493 (defvar edebug-eval-list nil
) ;; List of expressions to evaluate.
2495 (defvar edebug-previous-result nil
) ;; Last result returned.
2497 ;; Emacs 19 adds an arg to mark and mark-marker.
2498 (defalias 'edebug-mark
'mark
)
2499 (defalias 'edebug-mark-marker
'mark-marker
)
2502 (defun edebug-display ()
2503 ;; Setup windows for edebug, determine mode, maybe enter recursive-edit.
2504 ;; Uses local variables of edebug-enter, edebug-before, edebug-after
2505 ;; and edebug-debugger.
2506 (let ((edebug-active t
) ; for minor mode alist
2507 edebug-stop
; should we enter recursive-edit
2508 (edebug-point (+ edebug-def-mark
2509 (aref (nth 2 edebug-data
) edebug-offset-index
)))
2510 edebug-buffer-outside-point
; current point in edebug-buffer
2511 ;; window displaying edebug-buffer
2512 (edebug-window-data (nth 3 edebug-data
))
2513 (edebug-outside-window (selected-window))
2514 (edebug-outside-buffer (current-buffer))
2515 (edebug-outside-point (point))
2516 (edebug-outside-mark (edebug-mark))
2517 edebug-outside-windows
; window or screen configuration
2518 edebug-buffer-points
2520 edebug-eval-buffer
; declared here so we can kill it below
2521 (edebug-eval-result-list (and edebug-eval-list
2522 (edebug-eval-result-list)))
2524 edebug-trace-window-start
2526 (edebug-outside-o-a-p overlay-arrow-position
)
2527 (edebug-outside-o-a-s overlay-arrow-string
)
2528 (edebug-outside-c-i-e-a cursor-in-echo-area
))
2530 (let ((overlay-arrow-position overlay-arrow-position
)
2531 (overlay-arrow-string overlay-arrow-string
)
2532 (cursor-in-echo-area nil
)
2535 (if (not (buffer-name edebug-buffer
))
2536 (let ((debug-on-error nil
))
2537 (error "Buffer defining %s not found" edebug-function
)))
2539 (if (eq 'after edebug-arg-mode
)
2540 ;; Compute result string now before windows are modified.
2541 (edebug-compute-previous-result edebug-value
))
2543 (if edebug-save-windows
2544 ;; Save windows now before we modify them.
2545 (setq edebug-outside-windows
2546 (edebug-current-windows edebug-save-windows
)))
2548 (if edebug-save-displayed-buffer-points
2549 (setq edebug-buffer-points
(edebug-get-displayed-buffer-points)))
2551 ;; First move the edebug buffer point to edebug-point
2552 ;; so that window start doesn't get changed when we display it.
2553 ;; I don't know if this is going to help.
2554 ;;(set-buffer edebug-buffer)
2555 ;;(goto-char edebug-point)
2557 ;; If edebug-buffer is not currently displayed,
2558 ;; first find a window for it.
2559 (edebug-pop-to-buffer edebug-buffer
(car edebug-window-data
))
2560 (setcar edebug-window-data
(selected-window))
2562 ;; Now display eval list, if any.
2563 ;; This is done after the pop to edebug-buffer
2564 ;; so that buffer-window correspondence is correct after quitting.
2565 (edebug-eval-display edebug-eval-result-list
)
2566 ;; The evaluation list better not have deleted edebug-window-data.
2567 (select-window (car edebug-window-data
))
2568 (set-buffer edebug-buffer
)
2570 (setq edebug-buffer-outside-point
(point))
2571 (goto-char edebug-point
)
2573 (if (eq 'before edebug-arg-mode
)
2574 ;; Check whether positions are up-to-date.
2575 ;; This assumes point is never before symbol.
2576 (if (not (memq (following-char) '(?\
( ?\
# ?\
` )))
2577 (let ((debug-on-error nil
))
2578 (error "Source has changed - reevaluate definition of %s"
2582 (setcdr edebug-window-data
2583 (edebug-adjust-window (cdr edebug-window-data
)))
2585 ;; Test if there is input, not including keyboard macros.
2586 (if (edebug-input-pending-p)
2588 (setq edebug-execution-mode
'step
2591 ;; (discard-input) ; is this unfriendly??
2593 ;; Now display arrow based on mode.
2594 (edebug-overlay-arrow)
2597 ((eq 'error edebug-arg-mode
)
2598 ;; Display error message
2599 (setq edebug-execution-mode
'step
)
2600 (edebug-overlay-arrow)
2602 (if (eq 'quit
(car edebug-value
))
2604 (edebug-report-error edebug-value
)))
2607 (edebug-global-break
2608 (message "Global Break: %s => %s"
2609 edebug-global-break-condition
2610 edebug-global-break-result
))
2611 (edebug-break-condition
2612 (message "Break: %s => %s"
2613 edebug-break-condition
2614 edebug-break-result
))
2615 ((not (eq edebug-execution-mode
'Continue-fast
))
2621 (if (eq 'after edebug-arg-mode
)
2623 ;; Display result of previous evaluation.
2624 (if (and edebug-break
2625 (not (eq edebug-execution-mode
'Continue-fast
)))
2626 (sit-for 1)) ; Show break message.
2627 (edebug-previous-result)))
2632 ((eq edebug-execution-mode
'continue
) (edebug-sit-for 1))
2633 ((eq edebug-execution-mode
'Continue-fast
) (edebug-sit-for 0))
2634 (t (setq edebug-stop t
))))
2636 ((eq edebug-execution-mode
'trace
)
2637 (edebug-sit-for 1)) ; Force update and pause.
2638 ((eq edebug-execution-mode
'Trace-fast
)
2639 (edebug-sit-for 0)) ; Force update and continue.
2644 (memq edebug-execution-mode
'(step next
))
2645 (eq edebug-arg-mode
'error
))
2647 ;; (setq edebug-execution-mode 'step)
2648 ;; (edebug-overlay-arrow) ; This doesn't always show up.
2649 (edebug-recursive-edit))) ; <---------- Recursive edit
2651 ;; Reset the edebug-window-data to whatever it is now.
2652 (let ((window (if (eq (window-buffer) edebug-buffer
)
2654 (edebug-get-buffer-window edebug-buffer
))))
2655 ;; Remember window-start for edebug-buffer, if still displayed.
2658 (setcar edebug-window-data window
)
2659 (setcdr edebug-window-data
(window-start window
)))))
2661 ;; Save trace window point before restoring outside windows.
2662 ;; Could generalize this for other buffers.
2663 (setq edebug-trace-window
(get-buffer-window edebug-trace-buffer
))
2664 (if edebug-trace-window
2665 (setq edebug-trace-window-start
2666 (and edebug-trace-window
2667 (window-start edebug-trace-window
))))
2669 ;; Restore windows before continuing.
2670 (if edebug-save-windows
2672 (edebug-set-windows edebug-outside-windows
)
2674 ;; Restore displayed buffer points.
2675 ;; Needed even if restoring windows because
2676 ;; window-points are not restored. (should they be??)
2677 (if edebug-save-displayed-buffer-points
2678 (edebug-set-buffer-points edebug-buffer-points
))
2680 ;; Unrestore trace window's window-point.
2681 (if edebug-trace-window
2682 (set-window-start edebug-trace-window
2683 edebug-trace-window-start
))
2685 ;; Unrestore edebug-buffer's window-start, if displayed.
2686 (let ((window (car edebug-window-data
)))
2687 (if (and window
(edebug-window-live-p window
)
2688 (eq (window-buffer) edebug-buffer
))
2690 (set-window-start window
(cdr edebug-window-data
)
2692 ;; Unrestore edebug-buffer's window-point.
2693 ;; Needed in addition to setting the buffer point
2694 ;; - otherwise quitting doesn't leave point as is.
2695 ;; But this causes point to not be restored at times.
2696 ;; Also, it may not be a visible window.
2697 ;; (set-window-point window edebug-point)
2700 ;; Unrestore edebug-buffer's point. Rerestored below.
2701 ;; (goto-char edebug-point) ;; in edebug-buffer
2703 ;; Since we may be in a save-excursion, in case of quit,
2704 ;; reselect the outside window only.
2705 ;; Only needed if we are not recovering windows??
2706 (if (edebug-window-live-p edebug-outside-window
)
2707 (select-window edebug-outside-window
))
2708 ) ; if edebug-save-windows
2710 ;; Restore current buffer always, in case application needs it.
2711 (set-buffer edebug-outside-buffer
)
2712 ;; Restore point, and mark.
2713 ;; Needed even if restoring windows because
2714 ;; that doesn't restore point and mark in the current buffer.
2715 ;; But don't restore point if edebug-buffer is current buffer.
2716 (if (not (eq edebug-buffer edebug-outside-buffer
))
2717 (goto-char edebug-outside-point
))
2718 (if (marker-buffer (edebug-mark-marker))
2719 ;; Does zmacs-regions need to be nil while doing set-marker?
2720 (set-marker (edebug-mark-marker) edebug-outside-mark
))
2722 ;; None of the following is done if quit or signal occurs.
2724 ;; Restore edebug-buffer's outside point.
2725 ;; (edebug-trace "restore edebug-buffer point: %s"
2726 ;; edebug-buffer-outside-point)
2727 (let ((current-buffer (current-buffer)))
2728 (set-buffer edebug-buffer
)
2729 (goto-char edebug-buffer-outside-point
)
2730 (set-buffer current-buffer
))
2731 ;; ... nothing more.
2733 ;; Reset global variables to outside values in case they were changed.
2735 overlay-arrow-position edebug-outside-o-a-p
2736 overlay-arrow-string edebug-outside-o-a-s
2737 cursor-in-echo-area edebug-outside-c-i-e-a
)
2741 (defvar edebug-number-of-recursions
0)
2742 ;; Number of recursive edits started by edebug.
2743 ;; Should be 0 at the top level.
2745 (defvar edebug-recursion-depth
0)
2746 ;; Value of recursion-depth when edebug was called.
2748 ;; Dynamically declared unbound vars
2749 (defvar edebug-outside-match-data
) ; match data outside of edebug
2750 (defvar edebug-backtrace-buffer
) ; each recursive edit gets its own
2751 (defvar edebug-inside-windows
)
2752 (defvar edebug-interactive-p
)
2754 (defvar edebug-outside-map
)
2755 (defvar edebug-outside-standard-output
)
2756 (defvar edebug-outside-standard-input
)
2757 (defvar edebug-outside-last-command-char
)
2758 (defvar edebug-outside-last-command
)
2759 (defvar edebug-outside-this-command
)
2760 (defvar edebug-outside-last-input-char
)
2762 ;; Note: here we have defvars for variables that are
2763 ;; built-in in certain versions.
2764 ;; Each defvar makes a difference
2765 ;; in versions where the variable is *not* built-in.
2768 (defvar edebug-outside-unread-command-char
)
2771 (defvar edebug-outside-unread-command-event
) ;; like unread-command-events
2772 (defvar unread-command-event nil
)
2775 (defvar edebug-outside-last-command-event
)
2776 (defvar edebug-outside-unread-command-events
)
2777 (defvar edebug-outside-last-input-event
)
2778 (defvar edebug-outside-last-event-frame
)
2779 (defvar edebug-outside-last-nonmenu-event
)
2780 (defvar edebug-outside-track-mouse
)
2782 ;; Disable byte compiler warnings about unread-command-char and -event
2783 ;; (maybe works with byte-compile-version 2.22 at least)
2784 (defvar edebug-unread-command-char-warning
)
2785 (defvar edebug-unread-command-event-warning
)
2787 (setq edebug-unread-command-char-warning
2788 (get 'unread-command-char
'byte-obsolete-variable
))
2789 (put 'unread-command-char
'byte-obsolete-variable nil
)
2790 (setq edebug-unread-command-event-warning
2791 (get 'unread-command-event
'byte-obsolete-variable
))
2792 (put 'unread-command-event
'byte-obsolete-variable nil
))
2794 (defun edebug-recursive-edit ()
2795 ;; Start up a recursive edit inside of edebug.
2796 ;; The current buffer is the edebug-buffer, which is put into edebug-mode.
2797 ;; Assume that none of the variables below are buffer-local.
2798 (let ((edebug-buffer-read-only buffer-read-only
)
2799 ;; match-data must be done in the outside buffer
2800 (edebug-outside-match-data
2801 (save-excursion ; might be unnecessary now??
2802 (set-buffer edebug-outside-buffer
) ; in case match buffer different
2805 ;;(edebug-number-of-recursions (1+ edebug-number-of-recursions))
2806 (edebug-recursion-depth (recursion-depth))
2807 edebug-entered
; bind locally to nil
2808 (edebug-interactive-p nil
) ; again non-interactive
2809 edebug-backtrace-buffer
; each recursive edit gets its own
2810 ;; The window configuration may be saved and restored
2811 ;; during a recursive-edit
2812 edebug-inside-windows
2814 (edebug-outside-map (current-local-map))
2816 (edebug-outside-standard-output standard-output
)
2817 (edebug-outside-standard-input standard-input
)
2818 (edebug-outside-defining-kbd-macro defining-kbd-macro
)
2820 (edebug-outside-last-command-char last-command-char
)
2821 (edebug-outside-last-command last-command
)
2822 (edebug-outside-this-command this-command
)
2823 (edebug-outside-last-input-char last-input-char
)
2825 (edebug-outside-unread-command-char unread-command-char
)
2827 (edebug-outside-last-input-event last-input-event
)
2828 (edebug-outside-last-command-event last-command-event
)
2829 (edebug-outside-unread-command-event unread-command-event
)
2830 (edebug-outside-unread-command-events unread-command-events
)
2831 (edebug-outside-last-event-frame last-event-frame
)
2832 (edebug-outside-last-nonmenu-event last-nonmenu-event
)
2833 (edebug-outside-track-mouse track-mouse
)
2838 ;; Declare global values local but using the same global value.
2839 ;; We could set these to the values for previous edebug call.
2840 (last-command-char last-command-char
)
2841 (last-command last-command
)
2842 (this-command this-command
)
2843 (last-input-char last-input-char
)
2845 ;; Assume no edebug command sets unread-command-char.
2846 (unread-command-char -
1)
2848 ;; More for Emacs 19
2849 (last-input-event nil
)
2850 (last-command-event nil
)
2851 (unread-command-event nil
);; lemacs
2852 (unread-command-events nil
)
2853 (last-event-frame nil
)
2854 (last-nonmenu-event nil
)
2857 ;; Bind again to outside values.
2858 (debug-on-error edebug-outside-debug-on-error
)
2859 (debug-on-quit edebug-outside-debug-on-quit
)
2861 ;; Don't keep defining a kbd macro.
2863 (if edebug-continue-kbd-macro defining-kbd-macro
))
2868 (if (fboundp 'zmacs-deactivate-region
);; for lemacs
2869 (zmacs-deactivate-region))
2870 (if (and (eq edebug-execution-mode
'go
)
2871 (not (memq edebug-arg-mode
'(after error
))))
2874 (setq buffer-read-only t
)
2875 (fset 'signal
(symbol-function 'edebug-original-signal
))
2879 (recursive-edit) ; <<<<<<<<<< Recursive edit
2881 ;; Do the following, even if quit occurs.
2882 (fset 'signal
'edebug-signal
)
2883 (if edebug-backtrace-buffer
2884 (kill-buffer edebug-backtrace-buffer
))
2885 ;; Could be an option to keep eval display up.
2886 (if edebug-eval-buffer
(kill-buffer edebug-eval-buffer
))
2888 ;; Remember selected-window after recursive-edit.
2889 ;; (setq edebug-inside-window (selected-window))
2891 (store-match-data edebug-outside-match-data
)
2893 ;; Recursive edit may have changed buffers,
2894 ;; so set it back before exiting let.
2895 (if (buffer-name edebug-buffer
) ; if it still exists
2897 (set-buffer edebug-buffer
)
2898 (if (memq edebug-execution-mode
'(go Go-nonstop
))
2899 (edebug-overlay-arrow))
2900 (setq buffer-read-only edebug-buffer-read-only
)
2901 (use-local-map edebug-outside-map
)
2903 ;; gotta have a buffer to let its buffer local variables be set
2904 (get-buffer-create " bogus edebug buffer"))
2907 ;; Reset global vars to outside values, in case they have been changed.
2909 last-command-char edebug-outside-last-command-char
2910 last-command-event edebug-outside-last-command-event
2911 last-command edebug-outside-last-command
2912 this-command edebug-outside-this-command
2913 unread-command-char edebug-outside-unread-command-char
2914 unread-command-event edebug-outside-unread-command-event
2915 unread-command-events edebug-outside-unread-command-events
2916 last-input-char edebug-outside-last-input-char
2917 last-input-event edebug-outside-last-input-event
2918 last-event-frame edebug-outside-last-event-frame
2919 last-nonmenu-event edebug-outside-last-nonmenu-event
2920 track-mouse edebug-outside-track-mouse
2922 standard-output edebug-outside-standard-output
2923 standard-input edebug-outside-standard-input
2924 defining-kbd-macro edebug-outside-defining-kbd-macro
2929 ;;; Display related functions
2931 (defun edebug-adjust-window (old-start)
2932 ;; If pos is not visible, adjust current window to fit following context.
2933 ;;; (message "window: %s old-start: %s window-start: %s pos: %s"
2934 ;;; (selected-window) old-start (window-start) (point)) (sit-for 5)
2935 (if (not (pos-visible-in-window-p))
2937 ;; First try old-start
2939 (set-window-start (selected-window) old-start
))
2940 (if (not (pos-visible-in-window-p))
2942 ;; (message "resetting window start") (sit-for 2)
2947 (if (< (point) (window-start)) -
1 ; one line before if in back
2948 (- (/ (window-height) 2)) ; center the line moving forward
2956 (defconst edebug-arrow-alist
2957 '((Continue-fast .
"=")
2964 (Go-nonstop .
"..") ; not used
2966 "Association list of arrows for each edebug mode.")
2968 (defun edebug-overlay-arrow ()
2969 ;; Set up the overlay arrow at beginning-of-line in current buffer.
2970 ;; The arrow string is derived from edebug-arrow-alist and
2971 ;; edebug-execution-mode.
2972 (let ((pos (save-excursion (beginning-of-line) (point))))
2973 (setq overlay-arrow-string
2974 (cdr (assq edebug-execution-mode edebug-arrow-alist
)))
2975 (setq overlay-arrow-position
(make-marker))
2976 (set-marker overlay-arrow-position pos
(current-buffer))))
2979 (defun edebug-toggle-save-all-windows ()
2980 "Toggle the saving and restoring of all windows.
2981 Also, each time you toggle it on, the inside and outside window
2982 configurations become the same as the current configuration."
2984 (setq edebug-save-windows
(not edebug-save-windows
))
2985 (if edebug-save-windows
2986 (setq edebug-inside-windows
2987 (setq edebug-outside-windows
2988 (edebug-current-windows
2989 edebug-save-windows
))))
2990 (message "Window saving is %s for all windows."
2991 (if edebug-save-windows
"on" "off")))
2993 (defmacro edebug-changing-windows
(&rest body
)
2994 (` (let ((window (selected-window)))
2995 (setq edebug-inside-windows
(edebug-current-windows t
))
2996 (edebug-set-windows edebug-outside-windows
)
2997 (,@ body
) ;; Code to change edebug-save-windows
2998 (setq edebug-outside-windows
(edebug-current-windows
2999 edebug-save-windows
))
3000 ;; Problem: what about outside windows that are deleted inside?
3001 (edebug-set-windows edebug-inside-windows
))))
3003 (defun edebug-toggle-save-selected-window ()
3004 "Toggle the saving and restoring of the selected window.
3005 Also, each time you toggle it on, the inside and outside window
3006 configurations become the same as the current configuration."
3009 ((eq t edebug-save-windows
)
3010 ;; Save all outside windows except the selected one.
3011 ;; Remove (selected-window) from outside-windows.
3012 (edebug-changing-windows
3013 (setq edebug-save-windows
(delq window
(edebug-window-list)))))
3015 ((memq (selected-window) edebug-save-windows
)
3016 (setq edebug-outside-windows
3017 (delq (assq (selected-window) edebug-outside-windows
)
3018 edebug-outside-windows
))
3019 (setq edebug-save-windows
3020 (delq (selected-window) edebug-save-windows
)))
3021 (t ; Save a new window.
3022 (edebug-changing-windows
3023 (setq edebug-save-windows
(cons window edebug-save-windows
)))))
3025 (message "Window saving is %s for %s."
3026 (if (memq (selected-window) edebug-save-windows
)
3030 (defun edebug-toggle-save-windows (arg)
3031 "Toggle the saving and restoring of windows.
3032 With prefix, toggle for just the selected window.
3033 Otherwise, toggle for all windows."
3036 (edebug-toggle-save-selected-window)
3037 (edebug-toggle-save-all-windows)))
3040 (defun edebug-where ()
3041 "Show the debug windows and where we stopped in the program."
3043 (if (not edebug-active
)
3044 (error "Edebug is not active"))
3045 ;; Restore the window configuration to what it last was inside.
3046 ;; But it is not always set. - experiment
3047 ;;(if edebug-inside-windows
3048 ;; (edebug-set-windows edebug-inside-windows))
3049 (edebug-pop-to-buffer edebug-buffer
)
3050 (goto-char edebug-point
))
3052 (defun edebug-view-outside ()
3053 "Change to the outside window configuration."
3055 (if (not edebug-active
)
3056 (error "Edebug is not active"))
3057 (setq edebug-inside-windows
3058 (edebug-current-windows edebug-save-windows
))
3059 (edebug-set-windows edebug-outside-windows
)
3060 (goto-char edebug-outside-point
)
3061 (message "Window configuration outside of Edebug. Return with %s"
3062 (substitute-command-keys "\\<global-map>\\[edebug-where]")))
3065 (defun edebug-bounce-point (arg)
3066 "Bounce the point in the outside current buffer.
3067 If prefix arg is supplied, sit for that many seconds before returning.
3068 The default is one second."
3070 (if (not edebug-active
)
3071 (error "Edebug is not active"))
3073 ;; If the buffer's currently displayed, avoid set-window-configuration.
3074 (save-window-excursion
3075 (edebug-pop-to-buffer edebug-outside-buffer
)
3076 (goto-char edebug-outside-point
)
3077 (message "Current buffer: %s Point: %s Mark: %s"
3078 (current-buffer) (point)
3079 (if (marker-buffer (edebug-mark-marker))
3080 (marker-position (edebug-mark-marker)) "<not set>"))
3081 (edebug-sit-for arg
)
3082 (edebug-pop-to-buffer edebug-buffer
(car edebug-window-data
)))))
3085 ;; Joe Wells, here is a start at your idea of adding a buffer to the internal
3086 ;; display list. Still need to use this list in edebug-display.
3088 '(defvar edebug-display-buffer-list nil
3089 "List of buffers that edebug will display when it is active.")
3091 '(defun edebug-display-buffer (buffer)
3092 "Toggle display of a buffer inside of edebug."
3093 (interactive "bBuffer: ")
3094 (let ((already-displaying (memq buffer edebug-display-buffer-list
)))
3095 (setq edebug-display-buffer-list
3096 (if already-displaying
3097 (delq buffer edebug-display-buffer-list
)
3098 (cons buffer edebug-display-buffer-list
)))
3099 (message "Displaying %s %s" buffer
3100 (if already-displaying
"off" "on"))))
3102 ;;; Breakpoint related functions
3104 (defun edebug-find-stop-point ()
3105 ;; Return (function . index) of the nearest edebug stop point.
3106 (let* ((edebug-def-name (edebug-form-data-symbol))
3108 (let ((data (get edebug-def-name
'edebug
)))
3109 (if (or (null data
) (markerp data
))
3110 (error "%s is not instrumented for Edebug" edebug-def-name
))
3111 data
)) ; we could do it automatically, if data is a marker.
3112 ;; pull out parts of edebug-data.
3113 (edebug-def-mark (car edebug-data
))
3114 ;; (edebug-breakpoints (car (cdr edebug-data)))
3116 (offset-vector (nth 2 edebug-data
))
3117 (offset (- (save-excursion
3118 (if (looking-at "[ \t]")
3119 ;; skip backwards until non-whitespace, or bol
3120 (skip-chars-backward " \t"))
3124 ;; the offsets are in order so we can do a linear search
3125 (setq len
(length offset-vector
))
3127 (while (and (< i len
) (> offset
(aref offset-vector i
)))
3130 (<= offset
(aref offset-vector i
)))
3131 ;; return the relevant info
3132 (cons edebug-def-name i
)
3133 (message "Point is not on an expression in %s."
3138 (defun edebug-next-breakpoint ()
3139 "Move point to the next breakpoint, or first if none past point."
3141 (let ((edebug-stop-point (edebug-find-stop-point)))
3142 (if edebug-stop-point
3143 (let* ((edebug-def-name (car edebug-stop-point
))
3144 (index (cdr edebug-stop-point
))
3145 (edebug-data (get edebug-def-name
'edebug
))
3147 ;; pull out parts of edebug-data
3148 (edebug-def-mark (car edebug-data
))
3149 (edebug-breakpoints (car (cdr edebug-data
)))
3150 (offset-vector (nth 2 edebug-data
))
3152 (if (not edebug-breakpoints
)
3153 (message "No breakpoints in this function.")
3154 (let ((breaks edebug-breakpoints
))
3156 (<= (car (car breaks
)) index
))
3157 (setq breaks
(cdr breaks
)))
3161 ;; goto the first breakpoint
3162 (car edebug-breakpoints
)))
3163 (goto-char (+ edebug-def-mark
3164 (aref offset-vector
(car breakpoint
))))
3167 (concat (if (nth 2 breakpoint
)
3169 (if (car (cdr breakpoint
))
3170 (format "Condition: %s"
3171 (edebug-safe-prin1-to-string
3172 (car (cdr breakpoint
))))
3177 (defun edebug-modify-breakpoint (flag &optional condition temporary
)
3178 "Modify the breakpoint for the form at point or after it according
3179 to FLAG: set if t, clear if nil. Then move to that point.
3180 If CONDITION or TEMPORARY are non-nil, add those attributes to
3182 (let ((edebug-stop-point (edebug-find-stop-point)))
3183 (if edebug-stop-point
3184 (let* ((edebug-def-name (car edebug-stop-point
))
3185 (index (cdr edebug-stop-point
))
3186 (edebug-data (get edebug-def-name
'edebug
))
3188 ;; pull out parts of edebug-data
3189 (edebug-def-mark (car edebug-data
))
3190 (edebug-breakpoints (car (cdr edebug-data
)))
3191 (offset-vector (nth 2 edebug-data
))
3193 ;; delete it either way
3194 (setq present
(assq index edebug-breakpoints
))
3195 (setq edebug-breakpoints
(delq present edebug-breakpoints
))
3198 ;; add it to the list and resort
3199 (setq edebug-breakpoints
3202 (list index condition temporary
)
3203 edebug-breakpoints
) '<))
3205 (message "Breakpoint set in %s with condition: %s"
3206 edebug-def-name condition
)
3207 (message "Breakpoint set in %s" edebug-def-name
)))
3209 (message "Breakpoint unset in %s" edebug-def-name
)
3210 (message "No breakpoint here")))
3212 (setcar (cdr edebug-data
) edebug-breakpoints
)
3213 (goto-char (+ edebug-def-mark
(aref offset-vector index
)))
3216 (defun edebug-set-breakpoint (arg)
3217 "Set the breakpoint of nearest sexp.
3218 With prefix argument, make it a temporary breakpoint."
3220 (edebug-modify-breakpoint t nil arg
))
3222 (defun edebug-unset-breakpoint ()
3223 "Clear the breakpoint of nearest sexp."
3225 (edebug-modify-breakpoint nil
))
3228 ;; For emacs 18, no read-expression-history
3229 (defun edebug-set-conditional-breakpoint (arg condition
)
3230 "Set a conditional breakpoint at nearest sexp.
3231 The condition is evaluated in the outside context.
3232 With prefix argument, make it a temporary breakpoint."
3233 ;; (interactive "P\nxCondition: ")
3237 ;; Edit previous condition as follows, but it is cumbersome:
3238 (let ((edebug-stop-point (edebug-find-stop-point)))
3239 (if edebug-stop-point
3240 (let* ((edebug-def-name (car edebug-stop-point
))
3241 (index (cdr edebug-stop-point
))
3242 (edebug-data (get edebug-def-name
'edebug
))
3243 (edebug-breakpoints (car (cdr edebug-data
)))
3244 (edebug-break-data (assq index edebug-breakpoints
))
3245 (edebug-break-condition (car (cdr edebug-break-data
))))
3247 (format "Condition in %s: " edebug-def-name
)
3248 (if edebug-break-condition
3249 (format "%s" edebug-break-condition
)
3251 (edebug-modify-breakpoint t condition arg
))
3254 (defun edebug-set-global-break-condition (expression)
3255 (interactive (list (read-minibuffer
3256 "Global Condition: "
3257 (format "%s" edebug-global-break-condition
))))
3258 (setq edebug-global-break-condition expression
))
3261 ;;; Mode switching functions
3263 (defun edebug-set-mode (mode shortmsg msg
)
3264 ;; Set the edebug mode to MODE.
3265 ;; Display SHORTMSG, or MSG if not within edebug.
3266 (if (eq (1+ edebug-recursion-depth
) (recursion-depth))
3268 (setq edebug-execution-mode mode
)
3270 ;; Continue execution
3271 (exit-recursive-edit))
3272 ;; This is not terribly useful!!
3273 (setq edebug-next-execution-mode mode
)
3277 (defalias 'edebug-step-through-mode
'edebug-step-mode
)
3279 (defun edebug-step-mode ()
3280 "Proceed to next stop point."
3282 (edebug-set-mode 'step
"" "Edebug will stop at next stop point."))
3284 (defun edebug-next-mode ()
3285 "Proceed to next `after' stop point."
3287 (edebug-set-mode 'next
"" "Edebug will stop after next eval."))
3289 (defun edebug-go-mode (arg)
3290 "Go, evaluating until break.
3291 With prefix ARG, set temporary break at current point and go."
3294 (edebug-set-breakpoint t
))
3295 (edebug-set-mode 'go
"Go..." "Edebug will go until break."))
3297 (defun edebug-Go-nonstop-mode ()
3298 "Go, evaluating without debugging."
3300 (edebug-set-mode 'Go-nonstop
"Go-Nonstop..."
3301 "Edebug will not stop at breaks."))
3304 (defun edebug-trace-mode ()
3307 (edebug-set-mode 'trace
"Tracing..." "Edebug will trace with pause."))
3309 (defun edebug-Trace-fast-mode ()
3310 "Trace with no wait at each step."
3312 (edebug-set-mode 'Trace-fast
3313 "Trace fast..." "Edebug will trace without pause."))
3315 (defun edebug-continue-mode ()
3316 "Begin continue mode."
3318 (edebug-set-mode 'continue
"Continue..."
3319 "Edebug will pause at breakpoints."))
3321 (defun edebug-Continue-fast-mode ()
3322 "Trace with no wait at each step."
3324 (edebug-set-mode 'Continue-fast
"Continue fast..."
3325 "Edebug will stop and go at breakpoints."))
3327 ;; ------------------------------------------------------------
3328 ;; The following use the mode changing commands and breakpoints.
3331 (defun edebug-goto-here ()
3332 "Proceed to this stop point."
3337 (defun edebug-stop ()
3338 "Stop execution and do not continue.
3339 Useful for exiting from trace or continue loop."
3344 '(defun edebug-forward ()
3345 "Proceed to the exit of the next expression to be evaluated."
3349 "Edebug will stop after exiting the next expression."))
3352 (defun edebug-forward-sexp (arg)
3353 "Proceed from the current point to the end of the ARGth sexp ahead.
3354 If there are not ARG sexps ahead, then do edebug-step-out."
3357 (let ((parse-sexp-ignore-comments t
))
3358 ;; Call forward-sexp repeatedly until done or failure.
3365 (defun edebug-step-out ()
3366 "Proceed from the current point to the end of the containing sexp.
3367 If there is no containing sexp that is not the top level defun,
3368 go to the end of the last sexp, or if that is the same point, then step."
3371 (let ((parse-sexp-ignore-comments t
))
3374 ;; Is there still a containing expression?
3378 ;; At top level - 1, so first check if there are more sexps at this level.
3379 (let ((start-point (point)))
3382 (if (= (point) start-point
)
3383 (edebug-step-mode) ; No more at this level, so step.
3387 (defun edebug-instrument-function (func)
3388 ;; Func should be a function symbol.
3389 ;; Return the function symbol, or nil if not instrumented.
3390 (let ((func-marker))
3391 (setq func-marker
(get func
'edebug
))
3393 ((markerp func-marker
)
3394 ;; It is uninstrumented, so instrument it.
3396 (set-buffer (marker-buffer func-marker
))
3397 (goto-char func-marker
)
3398 (edebug-eval-top-level-form)
3400 ((consp func-marker
)
3401 (message "%s is already instrumented." func
)
3404 ;; We could try harder, e.g. do a tags search.
3405 (error "Don't know where %s is defined" func
)
3408 (defun edebug-instrument-callee ()
3409 "Instrument the definition of the function or macro about to be called.
3410 Do this when stopped before the form or it will be too late.
3411 One side effect of using this command is that the next time the
3412 function or macro is called, Edebug will be called there as well."
3414 (if (not (looking-at "\("))
3415 (error "You must be before a list form")
3419 (if (looking-at "\(")
3420 (edebug-form-data-name
3421 (edebug-get-form-data-entry (point)))
3422 (edebug-original-read (current-buffer))))))
3423 (edebug-instrument-function func
))))
3426 (defun edebug-step-in ()
3427 "Step into the definition of the function or macro about to be called.
3428 This first does `edebug-instrument-callee' to ensure that it is
3429 instrumented. Then it does `edebug-on-entry' and switches to `go' mode."
3431 (let ((func (edebug-instrument-callee)))
3434 (edebug-on-entry func
'temp
)
3435 (edebug-go-mode nil
)))))
3437 (defun edebug-on-entry (function &optional flag
)
3438 "Cause Edebug to stop when FUNCTION is called.
3439 With prefix argument, make this temporary so it is automatically
3440 cancelled the first time the function is entered."
3441 (interactive "aEdebug on entry to: \nP")
3442 ;; Could store this in the edebug data instead.
3443 (put function
'edebug-on-entry
(if flag
'temp t
)))
3445 (defun cancel-edebug-on-entry (function)
3446 (interactive "aEdebug on entry to: ")
3447 (put function
'edebug-on-entry nil
))
3450 (if (not (fboundp 'edebug-original-debug-on-entry
))
3451 (fset 'edebug-original-debug-on-entry
(symbol-function 'debug-on-entry
)))
3452 '(fset 'debug-on-entry
'edebug-debug-on-entry
) ;; Should we do this?
3453 ;; Also need edebug-cancel-debug-on-entry
3455 '(defun edebug-debug-on-entry (function)
3456 "Request FUNCTION to invoke debugger each time it is called.
3457 If the user continues, FUNCTION's execution proceeds.
3458 Works by modifying the definition of FUNCTION,
3459 which must be written in Lisp, not predefined.
3460 Use `cancel-debug-on-entry' to cancel the effect of this command.
3461 Redefining FUNCTION also does that.
3463 This version is from Edebug. If the function is instrumented for
3464 Edebug, it calls `edebug-on-entry'"
3465 (interactive "aDebug on entry (to function): ")
3466 (let ((func-data (get function
'edebug
)))
3467 (if (or (null func-data
) (markerp func-data
))
3468 (edebug-original-debug-on-entry function
)
3469 (edebug-on-entry function
))))
3472 (defun edebug-top-level-nonstop ()
3473 "Set mode to Go-nonstop, and exit to top-level.
3474 This is useful for exiting even if unwind-protect code may be executed."
3476 (setq edebug-execution-mode
'Go-nonstop
)
3480 ;;(defun edebug-exit-out ()
3481 ;; "Go until the current function exits."
3483 ;; (edebug-set-mode 'exiting "Exit..."))
3486 ;;; The following initial mode setting definitions are not used yet.
3488 '(defconst edebug-initial-mode-alist
3489 '((edebug-Continue-fast . Continue-fast
)
3490 (edebug-Trace-fast . Trace-fast
)
3491 (edebug-continue . continue
)
3492 (edebug-trace . trace
)
3494 (edebug-step-through . step
)
3495 (edebug-Go-nonstop . Go-nonstop
)
3497 "Association list between commands and the modes they set.")
3500 '(defun edebug-set-initial-mode ()
3501 "Ask for the initial mode of the enclosing function.
3502 The mode is requested via the key that would be used to set the mode in
3505 (let* ((this-function (edebug-which-function))
3506 (keymap (if (eq edebug-mode-map
(current-local-map))
3508 (old-mode (or (get this-function
'edebug-initial-mode
)
3509 edebug-initial-mode
))
3510 (key (read-key-sequence
3512 "Change initial edebug mode for %s from %s (%s) to (enter key): "
3516 (car (rassq old-mode edebug-initial-mode-alist
))
3519 (mode (cdr (assq (key-binding key
) edebug-initial-mode-alist
)))
3522 (or (get this-function
'edebug-initial-mode
)
3523 (not (eq mode edebug-initial-mode
))))
3525 (put this-function
'edebug-initial-mode mode
)
3526 (message "Initial mode for %s is now: %s"
3527 this-function mode
))
3528 (error "Key must map to one of the mode changing commands")
3531 ;;; Evaluation of expressions
3533 (def-edebug-spec edebug-outside-excursion t
)
3535 (defmacro edebug-outside-excursion
(&rest body
)
3536 "Evaluate an expression list in the outside context.
3537 Return the result of the last expression."
3538 (` (save-excursion ; of current-buffer
3539 (if edebug-save-windows
3541 ;; After excursion, we will
3542 ;; restore to current window configuration.
3543 (setq edebug-inside-windows
3544 (edebug-current-windows edebug-save-windows
))
3545 ;; Restore outside windows.
3546 (edebug-set-windows edebug-outside-windows
)))
3548 (set-buffer edebug-buffer
) ; why?
3549 ;; (use-local-map edebug-outside-map)
3550 (store-match-data edebug-outside-match-data
)
3551 ;; Restore outside context.
3552 (let (;; (edebug-inside-map (current-local-map)) ;; restore map??
3553 (last-command-char edebug-outside-last-command-char
)
3554 (last-command-event edebug-outside-last-command-event
)
3555 (last-command edebug-outside-last-command
)
3556 (this-command edebug-outside-this-command
)
3557 (unread-command-char edebug-outside-unread-command-char
)
3558 (unread-command-event edebug-outside-unread-command-event
)
3559 (unread-command-events edebug-outside-unread-command-events
)
3560 (last-input-char edebug-outside-last-input-char
)
3561 (last-input-event edebug-outside-last-input-event
)
3562 (last-event-frame edebug-outside-last-event-frame
)
3563 (last-nonmenu-event edebug-outside-last-nonmenu-event
)
3564 (track-mouse edebug-outside-track-mouse
)
3565 (standard-output edebug-outside-standard-output
)
3566 (standard-input edebug-outside-standard-input
)
3568 (executing-kbd-macro edebug-outside-executing-macro
)
3569 (defining-kbd-macro edebug-outside-defining-kbd-macro
)
3570 (pre-command-hook edebug-outside-pre-command-hook
)
3571 (post-command-hook edebug-outside-post-command-hook
)
3572 (post-command-idle-hook edebug-outside-post-command-idle-hook
)
3574 ;; See edebug-display
3575 (overlay-arrow-position edebug-outside-o-a-p
)
3576 (overlay-arrow-string edebug-outside-o-a-s
)
3577 (cursor-in-echo-area edebug-outside-c-i-e-a
)
3580 (save-excursion ; of edebug-buffer
3581 (set-buffer edebug-outside-buffer
)
3582 (goto-char edebug-outside-point
)
3583 (if (marker-buffer (edebug-mark-marker))
3584 (set-marker (edebug-mark-marker) edebug-outside-mark
))
3587 ;; Back to edebug-buffer. Restore rest of inside context.
3588 ;; (use-local-map edebug-inside-map)
3589 (if edebug-save-windows
3590 ;; Restore inside windows.
3591 (edebug-set-windows edebug-inside-windows
))
3593 ;; Save values that may have been changed.
3595 edebug-outside-last-command-char last-command-char
3596 edebug-outside-last-command-event last-command-event
3597 edebug-outside-last-command last-command
3598 edebug-outside-this-command this-command
3599 edebug-outside-unread-command-char unread-command-char
3600 edebug-outside-unread-command-event unread-command-event
3601 edebug-outside-unread-command-events unread-command-events
3602 edebug-outside-last-input-char last-input-char
3603 edebug-outside-last-input-event last-input-event
3604 edebug-outside-last-event-frame last-event-frame
3605 edebug-outside-last-nonmenu-event last-nonmenu-event
3606 edebug-outside-track-mouse track-mouse
3607 edebug-outside-standard-output standard-output
3608 edebug-outside-standard-input standard-input
3610 edebug-outside-executing-macro executing-kbd-macro
3611 edebug-outside-defining-kbd-macro defining-kbd-macro
3612 edebug-outside-pre-command-hook pre-command-hook
3613 edebug-outside-post-command-hook post-command-hook
3614 edebug-outside-post-command-idle-hook post-command-idle-hook
3616 edebug-outside-o-a-p overlay-arrow-position
3617 edebug-outside-o-a-s overlay-arrow-string
3618 edebug-outside-c-i-e-a cursor-in-echo-area
3622 (defvar cl-debug-env nil
) ;; defined in cl; non-nil when lexical env used.
3624 (defun edebug-eval (edebug-expr)
3625 ;; Are there cl lexical variables active?
3627 (eval (cl-macroexpand-all edebug-expr cl-debug-env
))
3628 (eval edebug-expr
)))
3630 (defun edebug-safe-eval (edebug-expr)
3631 ;; Evaluate EXPR safely.
3632 ;; If there is an error, a string is returned describing the error.
3633 (condition-case edebug-err
3634 (edebug-eval edebug-expr
)
3635 (error (edebug-format "%s: %s" ;; could
3636 (get (car edebug-err
) 'error-message
)
3637 (car (cdr edebug-err
))))))
3641 ;; Replace printing functions.
3644 (defalias 'edebug-install-custom-print-funcs
'edebug-install-custom-print
)
3645 (defalias 'edebug-reset-print-funcs
'edebug-uninstall-custom-print
)
3646 (defalias 'edebug-uninstall-custom-print-funcs
'edebug-uninstall-custom-print
)
3648 (defun edebug-install-custom-print ()
3649 "Replace print functions used by Edebug with custom versions."
3650 ;; Modifying the custom print functions, or changing print-length,
3651 ;; print-level, print-circle, custom-print-list or custom-print-vector
3652 ;; have immediate effect.
3654 (require 'cust-print
)
3655 (defalias 'edebug-prin1
'custom-prin1
)
3656 (defalias 'edebug-print
'custom-print
)
3657 (defalias 'edebug-prin1-to-string
'custom-prin1-to-string
)
3658 (defalias 'edebug-format
'custom-format
)
3659 (defalias 'edebug-message
'custom-message
)
3663 (defun edebug-uninstall-custom-print ()
3664 "Replace edebug custom print functions with internal versions."
3666 (defalias 'edebug-prin1
'prin1
)
3667 (defalias 'edebug-print
'print
)
3668 (defalias 'edebug-prin1-to-string
'prin1-to-string
)
3669 (defalias 'edebug-format
'format
)
3670 (defalias 'edebug-message
'message
)
3673 ;; Default print functions are the same as Emacs'.
3674 (edebug-uninstall-custom-print))
3677 (defun edebug-report-error (edebug-value)
3678 ;; Print an error message like command level does.
3679 ;; This also prints the error name if it has no error-message.
3681 (or (get (car edebug-value
) 'error-message
)
3682 (format "peculiar error (%s)" (car edebug-value
)))
3683 (mapconcat (function (lambda (edebug-arg)
3684 ;; continuing after an error may
3685 ;; complain about edebug-arg. why??
3686 (prin1-to-string edebug-arg
)))
3687 (cdr edebug-value
) ", ")))
3689 ;; Define here in case they are not already defined.
3690 (defvar print-level nil
)
3691 (defvar print-circle nil
)
3692 (defvar print-readably
) ;; defined by lemacs
3693 ;; Alternatively, we could change the definition of
3694 ;; edebug-safe-prin1-to-string to only use these if defined.
3696 (defun edebug-safe-prin1-to-string (value)
3697 (let ((print-escape-newlines t
)
3698 (print-length (or edebug-print-length print-length
))
3699 (print-level (or edebug-print-level print-level
))
3700 (print-circle (or edebug-print-circle print-circle
))
3701 (print-readably nil
)) ;; lemacs uses this.
3702 (edebug-prin1-to-string value
)))
3704 (defun edebug-compute-previous-result (edebug-previous-value)
3705 (setq edebug-previous-result
3706 (if (and (numberp edebug-previous-value
)
3707 (< edebug-previous-value
256)
3708 (>= edebug-previous-value
0))
3709 (format "Result: %s = %s" edebug-previous-value
3710 (single-key-description edebug-previous-value
))
3711 (if edebug-unwrap-results
3712 (setq edebug-previous-value
3713 (edebug-unwrap* edebug-previous-value
)))
3715 (edebug-safe-prin1-to-string edebug-previous-value
)))))
3717 (defun edebug-previous-result ()
3718 "Print the previous result."
3720 (message "%s" edebug-previous-result
))
3722 ;;; Read, Eval and Print
3724 (defun edebug-eval-expression (edebug-expr)
3725 "Evaluate an expression in the outside environment.
3726 If interactive, prompt for the expression.
3727 Print result in minibuffer."
3728 (interactive "xEval: ")
3730 (edebug-outside-excursion
3731 (setq values
(cons (edebug-eval edebug-expr
) values
))
3732 (edebug-safe-prin1-to-string (car values
)))))
3734 (defun edebug-eval-last-sexp ()
3735 "Evaluate sexp before point in the outside environment;
3736 print value in minibuffer."
3738 (edebug-eval-expression (edebug-last-sexp)))
3740 (defun edebug-eval-print-last-sexp ()
3741 "Evaluate sexp before point in the outside environment;
3742 print value into current buffer."
3744 (let* ((edebug-form (edebug-last-sexp))
3745 (edebug-result-string
3746 (edebug-outside-excursion
3747 (edebug-safe-prin1-to-string (edebug-safe-eval edebug-form
))))
3748 (standard-output (current-buffer)))
3750 ;; princ the string to get rid of quotes.
3751 (princ edebug-result-string
)
3755 ;;; Edebug Minor Mode
3757 ;; Global GUD bindings for all emacs-lisp-mode buffers.
3758 (define-key emacs-lisp-mode-map
"\C-x\C-a\C-s" 'edebug-step-mode
)
3759 (define-key emacs-lisp-mode-map
"\C-x\C-a\C-n" 'edebug-next-mode
)
3760 (define-key emacs-lisp-mode-map
"\C-x\C-a\C-c" 'edebug-go-mode
)
3761 (define-key emacs-lisp-mode-map
"\C-x\C-a\C-l" 'edebug-where
)
3764 (defvar edebug-mode-map nil
)
3768 (setq edebug-mode-map
(copy-keymap emacs-lisp-mode-map
))
3770 (define-key edebug-mode-map
" " 'edebug-step-mode
)
3771 (define-key edebug-mode-map
"n" 'edebug-next-mode
)
3772 (define-key edebug-mode-map
"g" 'edebug-go-mode
)
3773 (define-key edebug-mode-map
"G" 'edebug-Go-nonstop-mode
)
3774 (define-key edebug-mode-map
"t" 'edebug-trace-mode
)
3775 (define-key edebug-mode-map
"T" 'edebug-Trace-fast-mode
)
3776 (define-key edebug-mode-map
"c" 'edebug-continue-mode
)
3777 (define-key edebug-mode-map
"C" 'edebug-Continue-fast-mode
)
3779 ;;(define-key edebug-mode-map "f" 'edebug-forward) not implemented
3780 (define-key edebug-mode-map
"f" 'edebug-forward-sexp
)
3781 (define-key edebug-mode-map
"h" 'edebug-goto-here
)
3783 (define-key edebug-mode-map
"I" 'edebug-instrument-callee
)
3784 (define-key edebug-mode-map
"i" 'edebug-step-in
)
3785 (define-key edebug-mode-map
"o" 'edebug-step-out
)
3787 ;; quitting and stopping
3788 (define-key edebug-mode-map
"q" 'top-level
)
3789 (define-key edebug-mode-map
"Q" 'edebug-top-level-nonstop
)
3790 (define-key edebug-mode-map
"a" 'abort-recursive-edit
)
3791 (define-key edebug-mode-map
"S" 'edebug-stop
)
3794 (define-key edebug-mode-map
"b" 'edebug-set-breakpoint
)
3795 (define-key edebug-mode-map
"u" 'edebug-unset-breakpoint
)
3796 (define-key edebug-mode-map
"B" 'edebug-next-breakpoint
)
3797 (define-key edebug-mode-map
"x" 'edebug-set-conditional-breakpoint
)
3798 (define-key edebug-mode-map
"X" 'edebug-set-global-break-condition
)
3801 (define-key edebug-mode-map
"r" 'edebug-previous-result
)
3802 (define-key edebug-mode-map
"e" 'edebug-eval-expression
)
3803 (define-key edebug-mode-map
"\C-x\C-e" 'edebug-eval-last-sexp
)
3804 (define-key edebug-mode-map
"E" 'edebug-visit-eval-list
)
3807 (define-key edebug-mode-map
"w" 'edebug-where
)
3808 (define-key edebug-mode-map
"v" 'edebug-view-outside
) ;; maybe obsolete??
3809 (define-key edebug-mode-map
"p" 'edebug-bounce-point
)
3810 (define-key edebug-mode-map
"P" 'edebug-view-outside
) ;; same as v
3811 (define-key edebug-mode-map
"W" 'edebug-toggle-save-windows
)
3814 (define-key edebug-mode-map
"?" 'edebug-help
)
3815 (define-key edebug-mode-map
"d" 'edebug-backtrace
)
3817 (define-key edebug-mode-map
"-" 'negative-argument
)
3820 (define-key edebug-mode-map
"=" 'edebug-temp-display-freq-count
)
3823 (define-key edebug-mode-map
"\C-c\C-s" 'edebug-step-mode
)
3824 (define-key edebug-mode-map
"\C-c\C-n" 'edebug-next-mode
)
3825 (define-key edebug-mode-map
"\C-c\C-c" 'edebug-go-mode
)
3827 (define-key edebug-mode-map
"\C-x " 'edebug-set-breakpoint
)
3828 (define-key edebug-mode-map
"\C-c\C-d" 'edebug-unset-breakpoint
)
3829 (define-key edebug-mode-map
"\C-c\C-t"
3830 (function (lambda () (edebug-set-breakpoint t
))))
3831 (define-key edebug-mode-map
"\C-c\C-l" 'edebug-where
)
3834 ;; Autoloading these global bindings doesn't make sense because
3835 ;; they cannot be used anyway unless Edebug is already loaded and active.
3837 (defvar global-edebug-prefix
"\^XX"
3838 "Prefix key for global edebug commands, available from any buffer.")
3840 (defvar global-edebug-map nil
3841 "Global map of edebug commands, available from any buffer.")
3843 (if global-edebug-map
3845 (setq global-edebug-map
(make-sparse-keymap))
3847 (global-unset-key global-edebug-prefix
)
3848 (global-set-key global-edebug-prefix global-edebug-map
)
3850 (define-key global-edebug-map
" " 'edebug-step-mode
)
3851 (define-key global-edebug-map
"g" 'edebug-go-mode
)
3852 (define-key global-edebug-map
"G" 'edebug-Go-nonstop-mode
)
3853 (define-key global-edebug-map
"t" 'edebug-trace-mode
)
3854 (define-key global-edebug-map
"T" 'edebug-Trace-fast-mode
)
3855 (define-key global-edebug-map
"c" 'edebug-continue-mode
)
3856 (define-key global-edebug-map
"C" 'edebug-Continue-fast-mode
)
3859 (define-key global-edebug-map
"b" 'edebug-set-breakpoint
)
3860 (define-key global-edebug-map
"u" 'edebug-unset-breakpoint
)
3861 (define-key global-edebug-map
"x" 'edebug-set-conditional-breakpoint
)
3862 (define-key global-edebug-map
"X" 'edebug-set-global-break-condition
)
3865 (define-key global-edebug-map
"w" 'edebug-where
)
3866 (define-key global-edebug-map
"W" 'edebug-toggle-save-windows
)
3869 (define-key global-edebug-map
"q" 'top-level
)
3870 (define-key global-edebug-map
"Q" 'edebug-top-level-nonstop
)
3871 (define-key global-edebug-map
"a" 'abort-recursive-edit
)
3874 (define-key global-edebug-map
"=" 'edebug-display-freq-count
)
3877 (defun edebug-help ()
3879 (describe-function 'edebug-mode
))
3881 (defun edebug-mode ()
3882 "Mode for Emacs Lisp buffers while in Edebug.
3884 In addition to all Emacs Lisp commands (except those that modify the
3885 buffer) there are local and global key bindings to several Edebug
3886 specific commands. E.g. `edebug-step-mode' is bound to \\[edebug-step-mode]
3887 in the Edebug buffer and \\<global-map>\\[edebug-step-mode] in any buffer.
3889 Also see bindings for the eval list buffer, *edebug*.
3891 The edebug buffer commands:
3894 Global commands prefixed by `global-edebug-prefix':
3895 \\{global-edebug-map}
3902 edebug-save-displayed-buffer-points
3905 edebug-test-coverage
3906 edebug-continue-kbd-macro
3913 edebug-unwrap-results
3914 edebug-global-break-condition
3916 (use-local-map edebug-mode-map
))
3918 ;;; edebug eval list mode
3920 ;; A list of expressions and their evaluations is displayed in *edebug*.
3922 (defun edebug-eval-result-list ()
3923 "Return a list of evaluations of edebug-eval-list"
3924 ;; Assumes in outside environment.
3925 ;; Don't do any edebug things now.
3926 (let ((edebug-execution-mode 'Go-nonstop
)
3928 (mapcar 'edebug-safe-eval edebug-eval-list
)))
3930 (defun edebug-eval-display-list (edebug-eval-result-list)
3931 ;; Assumes edebug-eval-buffer exists.
3932 (let ((edebug-eval-list-temp edebug-eval-list
)
3933 (standard-output edebug-eval-buffer
)
3934 (edebug-comment-line
3935 (format ";%s\n" (make-string (- (window-width) 2) ?-
))))
3936 (set-buffer edebug-eval-buffer
)
3938 (while edebug-eval-list-temp
3939 (prin1 (car edebug-eval-list-temp
)) (terpri)
3940 (prin1 (car edebug-eval-result-list
)) (terpri)
3941 (princ edebug-comment-line
)
3942 (setq edebug-eval-list-temp
(cdr edebug-eval-list-temp
))
3943 (setq edebug-eval-result-list
(cdr edebug-eval-result-list
)))
3944 (edebug-pop-to-buffer edebug-eval-buffer
)
3947 (defun edebug-create-eval-buffer ()
3948 (if (not (and edebug-eval-buffer
(buffer-name edebug-eval-buffer
)))
3950 (set-buffer (setq edebug-eval-buffer
(get-buffer-create "*edebug*")))
3951 (edebug-eval-mode))))
3953 ;; Should generalize this to be callable outside of edebug
3954 ;; with calls in user functions, e.g. (edebug-eval-display)
3956 (defun edebug-eval-display (edebug-eval-result-list)
3957 "Display expressions and evaluations in EVAL-LIST.
3958 It modifies the context by popping up the eval display."
3959 (if edebug-eval-result-list
3961 (edebug-create-eval-buffer)
3962 (edebug-eval-display-list edebug-eval-result-list
)
3965 (defun edebug-eval-redisplay ()
3966 "Redisplay eval list in outside environment.
3967 May only be called from within edebug-recursive-edit."
3968 (edebug-create-eval-buffer)
3969 (edebug-outside-excursion
3970 (edebug-eval-display-list (edebug-eval-result-list))
3973 (defun edebug-visit-eval-list ()
3975 (edebug-eval-redisplay)
3976 (edebug-pop-to-buffer edebug-eval-buffer
))
3979 (defun edebug-update-eval-list ()
3980 "Replace the evaluation list with the sexps now in the eval buffer."
3982 (let ((starting-point (point))
3984 (goto-char (point-min))
3985 ;; get the first expression
3986 (edebug-skip-whitespace)
3990 (setq new-list
(cons (edebug-last-sexp) new-list
))))
3992 (while (re-search-forward "^;" nil t
)
3994 (skip-chars-forward " \t\n\r")
3995 (if (and (/= ?\
; (following-char))
3999 (setq new-list
(cons (edebug-last-sexp) new-list
)))))
4001 (setq edebug-eval-list
(nreverse new-list
))
4002 (edebug-eval-redisplay)
4003 (goto-char starting-point
)))
4006 (defun edebug-delete-eval-item ()
4007 "Delete the item under point and redisplay."
4008 ;; could add arg to do repeatedly
4010 (if (re-search-backward "^;" nil
'nofail
)
4013 (point) (progn (re-search-forward "^;" nil
'nofail
)
4016 (edebug-update-eval-list))
4020 (defvar edebug-eval-mode-map nil
4021 "Keymap for edebug-eval-mode. Superset of lisp-interaction-mode.")
4023 (if edebug-eval-mode-map
4025 (setq edebug-eval-mode-map
(copy-keymap lisp-interaction-mode-map
))
4027 (define-key edebug-eval-mode-map
"\C-c\C-w" 'edebug-where
)
4028 (define-key edebug-eval-mode-map
"\C-c\C-d" 'edebug-delete-eval-item
)
4029 (define-key edebug-eval-mode-map
"\C-c\C-u" 'edebug-update-eval-list
)
4030 (define-key edebug-eval-mode-map
"\C-x\C-e" 'edebug-eval-last-sexp
)
4031 (define-key edebug-eval-mode-map
"\C-j" 'edebug-eval-print-last-sexp
)
4035 (defun edebug-eval-mode ()
4036 "Mode for evaluation list buffer while in Edebug.
4038 In addition to all Interactive Emacs Lisp commands there are local and
4039 global key bindings to several Edebug specific commands. E.g.
4040 `edebug-step-mode' is bound to \\[edebug-step-mode] in the Edebug
4041 buffer and \\<global-map>\\[edebug-step-mode] in any buffer.
4043 Eval list buffer commands:
4044 \\{edebug-eval-mode-map}
4046 Global commands prefixed by global-edebug-prefix:
4047 \\{global-edebug-map}
4049 (lisp-interaction-mode)
4050 (setq major-mode
'edebug-eval-mode
)
4051 (setq mode-name
"Edebug-Eval")
4052 (use-local-map edebug-eval-mode-map
))
4054 ;;; Interface with standard debugger.
4056 ;; (setq debugger 'edebug) ; to use the edebug debugger
4057 ;; (setq debugger 'debug) ; use the standard debugger
4059 ;; Note that debug and its utilities must be byte-compiled to work,
4060 ;; since they depend on the backtrace looking a certain way. But
4061 ;; edebug is not dependent on this, yet.
4063 (defun edebug (&optional edebug-arg-mode
&rest debugger-args
)
4064 "Replacement for debug.
4065 If we are running an edebugged function,
4066 show where we last were. Otherwise call debug normally."
4067 ;; (message "entered: %s depth: %s edebug-recursion-depth: %s"
4068 ;; edebug-entered (recursion-depth) edebug-recursion-depth) (sit-for 1)
4069 (if (and edebug-entered
; anything active?
4070 (eq (recursion-depth) edebug-recursion-depth
))
4071 (let (;; Where were we before the error occurred?
4072 (edebug-offset-index (car edebug-offset-indices
))
4073 ;; Bind variables required by edebug-display
4074 (edebug-value (car debugger-args
))
4077 edebug-break-condition
4079 (edebug-break (null edebug-arg-mode
)) ;; if called explicitly
4082 (if (eq edebug-arg-mode
'error
)
4086 ;; Otherwise call debug normally.
4087 ;; Still need to remove extraneous edebug calls from stack.
4088 (apply 'debug edebug-arg-mode debugger-args
)
4092 (defun edebug-backtrace ()
4093 "Display a non-working backtrace. Better than nothing..."
4095 (if (or (not edebug-backtrace-buffer
)
4096 (null (buffer-name edebug-backtrace-buffer
)))
4097 (setq edebug-backtrace-buffer
4098 (generate-new-buffer "*Backtrace*"))
4099 ;; else, could just display edebug-backtrace-buffer
4101 (with-output-to-temp-buffer (buffer-name edebug-backtrace-buffer
)
4102 (setq edebug-backtrace-buffer standard-output
)
4103 (let ((print-escape-newlines t
)
4108 ;; Clean up the backtrace.
4109 ;; Not quite right for current edebug scheme.
4110 (set-buffer edebug-backtrace-buffer
)
4111 (setq truncate-lines t
)
4112 (goto-char (point-min))
4113 (setq last-ok-point
(point))
4116 ;; Delete interspersed edebug internals.
4117 (while (re-search-forward "^ \(?edebug" nil t
)
4120 ((looking-at "^ \(edebug-after")
4121 ;; Previous lines may contain code, so just delete this line
4122 (setq last-ok-point
(point))
4124 (delete-region last-ok-point
(point)))
4126 ((looking-at "^ edebug")
4128 (delete-region last-ok-point
(point))
4135 (defun edebug-trace-display (buf-name fmt
&rest args
)
4136 "In buffer BUF-NAME, display FMT and ARGS at the end and make it visible.
4137 The buffer is created if it does not exist.
4138 You must include newlines in FMT to break lines, but one newline is appended."
4140 ;; (edebug-trace-display "*trace-point*"
4141 ;; "saving: point = %s window-start = %s"
4142 ;; (point) (window-start))
4143 (let* ((oldbuf (current-buffer))
4144 (selected-window (selected-window))
4145 (buffer (get-buffer-create buf-name
))
4147 ;; (message "before pop-to-buffer") (sit-for 1)
4148 (edebug-pop-to-buffer buffer
)
4149 (setq truncate-lines t
)
4150 (setq buf-window
(selected-window))
4151 (goto-char (point-max))
4152 (insert (apply 'edebug-format fmt args
) "\n")
4154 (vertical-motion (- 1 (window-height)))
4155 (set-window-start buf-window
(point))
4156 (goto-char (point-max))
4157 ;; (set-window-point buf-window (point))
4158 ;; (edebug-sit-for 0)
4159 (bury-buffer buffer
)
4160 (select-window selected-window
)
4161 (set-buffer oldbuf
))
4165 (defun edebug-trace (fmt &rest args
)
4166 "Convenience call to edebug-trace-display using edebug-trace-buffer"
4167 (apply 'edebug-trace-display edebug-trace-buffer fmt args
))
4170 ;;; Frequency count and coverage
4172 (defun edebug-display-freq-count ()
4173 "Display the frequency count data for each line of the current
4174 definition. The frequency counts are inserted as comment lines after
4175 each line, and you can undo all insertions with one `undo' command.
4177 The counts are inserted starting under the `(' before an expression
4178 or the `)' after an expression, or on the last char of a symbol.
4179 The counts are only displayed when they differ from previous counts on
4182 If coverage is being tested, whenever all known results of an expression
4183 are `eq', the char `=' will be appended after the count
4184 for that expression. Note that this is always the case for an
4185 expression only evaluated once.
4187 To clear the frequency count and coverage data for a definition,
4190 (let* ((function (edebug-form-data-symbol))
4191 (counts (get function
'edebug-freq-count
))
4192 (coverages (get function
'edebug-coverage
))
4193 (data (get function
'edebug
))
4194 (def-mark (car data
)) ; mark at def start
4195 (edebug-points (nth 2 data
))
4196 (i (1- (length edebug-points
)))
4200 (start-of-count-line)
4204 ;; Traverse in reverse order so offsets are correct.
4206 ;; Start at last expression in line.
4207 (goto-char (+ def-mark
(aref edebug-points i
)))
4209 (setq start-of-line
(- (point) def-mark
)
4212 ;; Find all indexes on same line.
4213 (while (and (<= 0 (setq i
(1- i
)))
4214 (<= start-of-line
(aref edebug-points i
))))
4215 ;; Insert all the indices for this line.
4217 (setq start-of-count-line
(point)
4218 first-index i
; really last index for line above this one.
4219 last-count -
1) ; cause first count to always appear.
4221 ;; i == first-index still
4222 (while (<= (setq i
(1+ i
)) last-index
)
4223 (let ((count (aref counts i
))
4224 (coverage (aref coverages i
))
4225 (col (save-excursion
4226 (goto-char (+ (aref edebug-points i
) def-mark
))
4228 (if (= ?\
( (following-char)) 0 1)))))
4229 (insert (make-string
4230 (max 0 (- col
(- (point) start-of-count-line
))) ?\
)
4231 (if (and (< 0 count
)
4233 '(unknown ok-coverage
))))
4235 (if (= count last-count
) "" (int-to-string count
))
4237 (setq last-count count
)))
4239 (setq i first-index
)))))
4241 (defun edebug-temp-display-freq-count ()
4242 "Temporarily display the frequency count data for the current definition.
4243 It is removed when you hit any char."
4244 ;; This seems not to work with Emacs 18.59. It undoes too far.
4246 (let ((buffer-read-only nil
))
4248 (edebug-display-freq-count)
4249 (setq unread-command-char
(read-char))
4255 (defun edebug-toggle (variable)
4256 (set variable
(not (eval variable
)))
4257 (message "%s: %s" variable
(eval variable
)))
4259 ;; We have to require easymenu (even for Emacs 18) just so
4260 ;; the easy-menu-define macro call is compiled correctly.
4263 (defconst edebug-mode-menus
4266 ["Stop" edebug-stop t
]
4267 ["Step" edebug-step-mode t
]
4268 ["Next" edebug-next-mode t
]
4269 ["Trace" edebug-trace-mode t
]
4270 ["Trace Fast" edebug-Trace-fast-mode t
]
4271 ["Continue" edebug-continue-mode t
]
4272 ["Continue Fast" edebug-Continue-fast-mode t
]
4273 ["Go" edebug-go-mode t
]
4274 ["Go Nonstop" edebug-Go-nonstop-mode t
]
4276 ["Help" edebug-help t
]
4277 ["Abort" abort-recursive-edit t
]
4278 ["Quit to Top Level" top-level t
]
4279 ["Quit Nonstop" edebug-top-level-nonstop t
]
4282 ["Forward Sexp" edebug-forward-sexp t
]
4283 ["Step In" edebug-step-in t
]
4284 ["Step Out" edebug-step-out t
]
4285 ["Goto Here" edebug-goto-here t
])
4288 ["Set Breakpoint" edebug-set-breakpoint t
]
4289 ["Unset Breakpoint" edebug-unset-breakpoint t
]
4290 ["Set Conditional Breakpoint" edebug-set-conditional-breakpoint t
]
4291 ["Set Global Break Condition" edebug-set-global-break-condition t
]
4292 ["Show Next Breakpoint" edebug-next-breakpoint t
])
4295 ["Where am I?" edebug-where t
]
4296 ["Bounce to Current Point" edebug-bounce-point t
]
4297 ["View Outside Windows" edebug-view-outside t
]
4298 ["Previous Result" edebug-previous-result t
]
4299 ["Show Backtrace" edebug-backtrace t
]
4300 ["Display Freq Count" edebug-display-freq-count t
])
4303 ["Expression" edebug-eval-expression t
]
4304 ["Last Sexp" edebug-eval-last-sexp t
]
4305 ["Visit Eval List" edebug-visit-eval-list t
])
4308 ["Edebug All Defs" edebug-all-defs t
]
4309 ["Edebug All Forms" edebug-all-forms t
]
4311 ["Toggle Tracing" (edebug-toggle 'edebug-trace
) t
]
4312 ["Toggle Coverage Testing" (edebug-toggle 'edebug-test-coverage
) t
]
4313 ["Toggle Window Saving" edebug-toggle-save-windows t
]
4314 ["Toggle Point Saving"
4315 (edebug-toggle 'edebug-save-displayed-buffer-points
) t
]
4317 "Lemacs style menus for Edebug.")
4320 ;;; Emacs version specific code
4322 ;;; The default for all above is Emacs 18, because it is easier to compile
4323 ;;; Emacs 18 code in Emacs 19 than vice versa. This default will
4324 ;;; change once most people are using Emacs 19 or derivatives.
4326 ;; Epoch specific code is in a separate file: edebug-epoch.el.
4328 ;; The byte-compiler will complain about changes in number of arguments
4329 ;; to functions like mark and read-from-minibuffer. These warnings
4330 ;; may be ignored because the right call should always be made.
4332 (defun edebug-emacs-19-specific ()
4334 (defalias 'edebug-window-live-p
'window-live-p
)
4336 ;; Mark takes an argument in Emacs 19.
4337 (defun edebug-mark ()
4338 (mark t
));; Does this work for lemacs too?
4340 ;; Use minibuffer-history when reading expressions.
4341 (defvar read-expression-history
) ;; hush bytecomp
4342 (defvar read-expression-map
)
4344 (defun edebug-set-conditional-breakpoint (arg condition
)
4345 "Set a conditional breakpoint at nearest sexp.
4346 The condition is evaluated in the outside context.
4347 With prefix argument, make it a temporary breakpoint."
4348 ;; (interactive "P\nxCondition: ")
4352 ;; Read condition as follows; getting previous condition is cumbersome:
4353 (let ((edebug-stop-point (edebug-find-stop-point)))
4354 (if edebug-stop-point
4355 (let* ((edebug-def-name (car edebug-stop-point
))
4356 (index (cdr edebug-stop-point
))
4357 (edebug-data (get edebug-def-name
'edebug
))
4358 (edebug-breakpoints (car (cdr edebug-data
)))
4359 (edebug-break-data (assq index edebug-breakpoints
))
4360 (edebug-break-condition (car (cdr edebug-break-data
)))
4361 (edebug-expression-history
4362 ;; Prepend the current condition, if any.
4363 (if edebug-break-condition
4364 (cons edebug-break-condition read-expression-history
)
4365 read-expression-history
)))
4367 (read-from-minibuffer
4368 "Condition: " nil read-expression-map t
4369 'edebug-expression-history
)
4370 (setq read-expression-history edebug-expression-history
)
4372 (edebug-modify-breakpoint t condition arg
))
4374 (defun edebug-eval-expression (edebug-expr)
4375 "Evaluate an expression in the outside environment.
4376 If interactive, prompt for the expression.
4377 Print result in minibuffer."
4378 (interactive (list (read-from-minibuffer
4379 "Eval: " nil read-expression-map t
4380 'read-expression-history
)))
4382 (edebug-outside-excursion
4383 (setq values
(cons (edebug-eval edebug-expr
) values
))
4384 (edebug-safe-prin1-to-string (car values
)))))
4386 (easy-menu-define edebug-menu edebug-mode-map
"Edebug menus" edebug-mode-menus
)
4388 (x-popup-menu nil
(lookup-key edebug-mode-map
[menu-bar Edebug
])))
4392 (defun edebug-lemacs-specific ()
4394 ;; We need to bind zmacs-regions to nil around all calls to `mark' and
4395 ;; `mark-marker' but don't bind it to nil before entering a recursive edit,
4396 ;; that is, don't interfere with the binding the user might see while
4397 ;; executing a command.
4399 (defvar zmacs-regions
)
4401 (defun edebug-mark ()
4402 (let ((zmacs-regions nil
))
4405 (defun edebug-mark-marker ()
4406 (let ((zmacs-regions nil
));; for lemacs
4410 (defun edebug-mode-menu (event)
4411 (interactive "@event")
4412 (popup-menu edebug-mode-menus
))
4414 (define-key edebug-mode-map
'button3
'edebug-mode-menu
)
4417 (defun edebug-emacs-version-specific ()
4419 ((string-match "Lucid" emacs-version
);; Lucid Emacs
4420 (edebug-lemacs-specific))
4422 ((and (boundp 'epoch
::version
) epoch
::version
)
4423 (require 'edebug-epoch
))
4425 ((not (string-match "^18" emacs-version
))
4426 (edebug-emacs-19-specific))))
4428 (edebug-emacs-version-specific)
4433 ;; Extension for bytecomp to resolve undefined function references.
4434 ;; Requires new byte compiler.
4436 ;; Reenable byte compiler warnings about unread-command-char and -event.
4437 ;; Disabled before edebug-recursive-edit.
4439 (if edebug-unread-command-char-warning
4440 (put 'unread-command-char
'byte-obsolete-variable
4441 edebug-unread-command-char-warning
))
4442 (if edebug-unread-command-event-warning
4443 (put 'unread-command-event
'byte-obsolete-variable
4444 edebug-unread-command-event-warning
)))
4447 ;; The body of eval-when-compile seems to get evaluated with eval-defun.
4448 ;; We only want to evaluate when actually byte compiling.
4449 ;; But it is OK to evaluate as long as byte-compiler has been loaded.
4450 (if (featurep 'byte-compile
) (progn
4452 (defun byte-compile-resolve-functions (funcs)
4453 "Say it is OK for the named functions to be unresolved."
4457 (setq byte-compile-unresolved-functions
4458 (delq (assq func byte-compile-unresolved-functions
)
4459 byte-compile-unresolved-functions
))))
4463 '(defun byte-compile-resolve-free-references (vars)
4464 "Say it is OK for the named variables to be referenced."
4468 (setq byte-compile-free-references
4469 (delq var byte-compile-free-references
))))
4473 '(defun byte-compile-resolve-free-assignments (vars)
4474 "Say it is OK for the named variables to be assigned."
4478 (setq byte-compile-free-assignments
4479 (delq var byte-compile-free-assignments
))))
4483 (byte-compile-resolve-functions
4484 '(reporter-submit-bug-report
4485 edebug-gensym
;; also in cl.el
4486 ;; Interfaces to standard functions.
4487 edebug-original-eval-defun
4488 edebug-original-read
4489 edebug-get-buffer-window
4492 edebug-input-pending-p
4494 edebug-prin1-to-string
4496 edebug-original-signal
4498 zmacs-deactivate-region
4502 ;; And believe it or not, the byte compiler doesn't know about:
4503 byte-compile-resolve-functions
4506 '(byte-compile-resolve-free-references
4507 '(read-expression-history
4508 read-expression-map
))
4510 '(byte-compile-resolve-free-assignments
4511 '(read-expression-history))
4516 ;;; Autoloading of Edebug accessories
4519 (add-hook 'edebug-setup-hook
4520 (function (lambda () (require 'cl-specs
))))
4521 ;; The following causes cl-specs to be loaded if you load cl.el.
4522 (add-hook 'cl-load-hook
4523 (function (lambda () (require 'cl-specs
)))))
4525 ;;; edebug-cl-read and cl-read are available from liberte@cs.uiuc.edu
4526 (if (featurep 'cl-read
)
4527 (add-hook 'edebug-setup-hook
4528 (function (lambda () (require 'edebug-cl-read
))))
4529 ;; The following causes edebug-cl-read to be loaded when you load cl-read.el.
4530 (add-hook 'cl-read-load-hooks
4531 (function (lambda () (require 'edebug-cl-read
)))))
4534 ;;; Finalize Loading
4536 ;;; Finally, hook edebug into the rest of Emacs.
4537 ;;; There are probably some other things that could go here.
4539 ;; Install edebug read and eval functions.
4540 (edebug-install-read-eval-functions)
4544 ;;; edebug.el ends here