comparison lisp/emacs-lisp/edebug.el @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 375f2633d815
children 4c90ffeb71c5
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
1 ;;; edebug.el --- a source-level debugger for Emacs Lisp 1 ;;; edebug.el --- a source-level debugger for Emacs Lisp
2 2
3 ;; Copyright (C) 1988, 89, 90, 91, 92, 93, 94, 95, 97, 1999, 2000, 01, 2003 3 ;; Copyright (C) 1988,89,90,91,92,93,94,95,97,1999,2000,01,03,2004
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 5
6 ;; Author: Daniel LaLiberte <liberte@holonexus.org> 6 ;; Author: Daniel LaLiberte <liberte@holonexus.org>
7 ;; Maintainer: FSF 7 ;; Maintainer: FSF
8 ;; Keywords: lisp, tools, maint 8 ;; Keywords: lisp, tools, maint
2088 (def-edebug-spec with-temp-message t) 2088 (def-edebug-spec with-temp-message t)
2089 (def-edebug-spec with-syntax-table t) 2089 (def-edebug-spec with-syntax-table t)
2090 (def-edebug-spec push (form sexp)) 2090 (def-edebug-spec push (form sexp))
2091 (def-edebug-spec pop (sexp)) 2091 (def-edebug-spec pop (sexp))
2092 2092
2093 (def-edebug-spec 1value (form))
2094 (def-edebug-spec noreturn (form))
2095
2096
2093 ;; Anything else? 2097 ;; Anything else?
2094 2098
2095 2099
2096 ;; Some miscellaneous specs for macros in public packages. 2100 ;; Some miscellaneous specs for macros in public packages.
2097 ;; Send me yours. 2101 ;; Send me yours.
2239 (edebug-outside-overriding-terminal-local-map 2243 (edebug-outside-overriding-terminal-local-map
2240 overriding-terminal-local-map) 2244 overriding-terminal-local-map)
2241 2245
2242 ;; Save the outside value of executing macro. (here??) 2246 ;; Save the outside value of executing macro. (here??)
2243 (edebug-outside-executing-macro executing-kbd-macro) 2247 (edebug-outside-executing-macro executing-kbd-macro)
2244 (edebug-outside-pre-command-hook pre-command-hook) 2248 (edebug-outside-pre-command-hook
2245 (edebug-outside-post-command-hook post-command-hook)) 2249 (edebug-var-status 'pre-command-hook))
2250 (edebug-outside-post-command-hook
2251 (edebug-var-status 'post-command-hook)))
2246 (unwind-protect 2252 (unwind-protect
2247 (let (;; Don't keep reading from an executing kbd macro 2253 (let (;; Don't keep reading from an executing kbd macro
2248 ;; within edebug unless edebug-continue-kbd-macro is 2254 ;; within edebug unless edebug-continue-kbd-macro is
2249 ;; non-nil. Again, local binding may not be best. 2255 ;; non-nil. Again, local binding may not be best.
2250 (executing-kbd-macro 2256 (executing-kbd-macro
2265 edebug-initial-mode 2271 edebug-initial-mode
2266 edebug-execution-mode) 2272 edebug-execution-mode)
2267 edebug-next-execution-mode nil) 2273 edebug-next-execution-mode nil)
2268 (edebug-enter edebug-function edebug-args edebug-body)) 2274 (edebug-enter edebug-function edebug-args edebug-body))
2269 ;; Reset global variables in case outside value was changed. 2275 ;; Reset global variables in case outside value was changed.
2270 (setq executing-kbd-macro edebug-outside-executing-macro 2276 (setq executing-kbd-macro edebug-outside-executing-macro)
2271 pre-command-hook edebug-outside-pre-command-hook 2277 (edebug-restore-status
2272 post-command-hook edebug-outside-post-command-hook 2278 'post-command-hook edebug-outside-post-command-hook)
2273 ))) 2279 (edebug-restore-status
2280 'pre-command-hook edebug-outside-pre-command-hook)))
2274 2281
2275 (let* ((edebug-data (get edebug-function 'edebug)) 2282 (let* ((edebug-data (get edebug-function 'edebug))
2276 (edebug-def-mark (car edebug-data)) ; mark at def start 2283 (edebug-def-mark (car edebug-data)) ; mark at def start
2277 (edebug-freq-count (get edebug-function 'edebug-freq-count)) 2284 (edebug-freq-count (get edebug-function 'edebug-freq-count))
2278 (edebug-coverage (get edebug-function 'edebug-coverage)) 2285 (edebug-coverage (get edebug-function 'edebug-coverage))
2289 (if edebug-trace 2296 (if edebug-trace
2290 (edebug-enter-trace edebug-body) 2297 (edebug-enter-trace edebug-body)
2291 (funcall edebug-body)) 2298 (funcall edebug-body))
2292 ))) 2299 )))
2293 2300
2301 (defun edebug-var-status (var)
2302 "Return a cons cell describing the status of VAR's current binding.
2303 The purpose of this function is so you can properly undo
2304 subsequent changes to the same binding, by passing the status
2305 cons cell to `edebug-restore-status'. The status cons cell
2306 has the form (LOCUS . VALUE), where LOCUS can be a buffer
2307 \(for a buffer-local binding), a frame (for a frame-local binding),
2308 or nil (if the default binding is current)."
2309 (cons (variable-binding-locus var)
2310 (symbol-value var)))
2311
2312 (defun edebug-restore-status (var status)
2313 "Reset VAR based on STATUS.
2314 STATUS should be a list you got from `edebug-var-status'."
2315 (let ((locus (car status))
2316 (value (cdr status)))
2317 (cond ((bufferp locus)
2318 (if (buffer-live-p locus)
2319 (with-current-buffer locus
2320 (set var value))))
2321 ((framep locus)
2322 (modify-frame-parameters locus (list (cons var value))))
2323 (t
2324 (set var value)))))
2294 2325
2295 (defun edebug-enter-trace (edebug-body) 2326 (defun edebug-enter-trace (edebug-body)
2296 (let ((edebug-stack-depth (1+ edebug-stack-depth)) 2327 (let ((edebug-stack-depth (1+ edebug-stack-depth))
2297 edebug-result) 2328 edebug-result)
2298 (edebug-print-trace-before 2329 (edebug-print-trace-before
2476 ;; Emacs 19 adds an arg to mark and mark-marker. 2507 ;; Emacs 19 adds an arg to mark and mark-marker.
2477 (defalias 'edebug-mark-marker 'mark-marker) 2508 (defalias 'edebug-mark-marker 'mark-marker)
2478 2509
2479 2510
2480 (defun edebug-display () 2511 (defun edebug-display ()
2512 (unless (marker-position edebug-def-mark)
2513 ;; The buffer holding the source has been killed.
2514 ;; Let's at least show a backtrace so the user can figure out
2515 ;; which function we're talking about.
2516 (debug))
2481 ;; Setup windows for edebug, determine mode, maybe enter recursive-edit. 2517 ;; Setup windows for edebug, determine mode, maybe enter recursive-edit.
2482 ;; Uses local variables of edebug-enter, edebug-before, edebug-after 2518 ;; Uses local variables of edebug-enter, edebug-before, edebug-after
2483 ;; and edebug-debugger. 2519 ;; and edebug-debugger.
2484 (let ((edebug-active t) ; for minor mode alist 2520 (let ((edebug-active t) ; for minor mode alist
2485 edebug-stop ; should we enter recursive-edit 2521 edebug-stop ; should we enter recursive-edit
3509 (standard-output edebug-outside-standard-output) 3545 (standard-output edebug-outside-standard-output)
3510 (standard-input edebug-outside-standard-input) 3546 (standard-input edebug-outside-standard-input)
3511 3547
3512 (executing-kbd-macro edebug-outside-executing-macro) 3548 (executing-kbd-macro edebug-outside-executing-macro)
3513 (defining-kbd-macro edebug-outside-defining-kbd-macro) 3549 (defining-kbd-macro edebug-outside-defining-kbd-macro)
3514 (pre-command-hook edebug-outside-pre-command-hook) 3550 ;; Get the values out of the saved statuses.
3515 (post-command-hook edebug-outside-post-command-hook) 3551 (pre-command-hook (cdr edebug-outside-pre-command-hook))
3552 (post-command-hook (cdr edebug-outside-post-command-hook))
3516 3553
3517 ;; See edebug-display 3554 ;; See edebug-display
3518 (overlay-arrow-position edebug-outside-o-a-p) 3555 (overlay-arrow-position edebug-outside-o-a-p)
3519 (overlay-arrow-string edebug-outside-o-a-s) 3556 (overlay-arrow-string edebug-outside-o-a-s)
3520 (cursor-in-echo-area edebug-outside-c-i-e-a) 3557 (cursor-in-echo-area edebug-outside-c-i-e-a)
3550 edebug-outside-standard-output standard-output 3587 edebug-outside-standard-output standard-output
3551 edebug-outside-standard-input standard-input 3588 edebug-outside-standard-input standard-input
3552 3589
3553 edebug-outside-executing-macro executing-kbd-macro 3590 edebug-outside-executing-macro executing-kbd-macro
3554 edebug-outside-defining-kbd-macro defining-kbd-macro 3591 edebug-outside-defining-kbd-macro defining-kbd-macro
3555 edebug-outside-pre-command-hook pre-command-hook
3556 edebug-outside-post-command-hook post-command-hook
3557 3592
3558 edebug-outside-o-a-p overlay-arrow-position 3593 edebug-outside-o-a-p overlay-arrow-position
3559 edebug-outside-o-a-s overlay-arrow-string 3594 edebug-outside-o-a-s overlay-arrow-string
3560 edebug-outside-c-i-e-a cursor-in-echo-area 3595 edebug-outside-c-i-e-a cursor-in-echo-area
3561 ))) ; let 3596 )
3597
3598 ;; Restore the outside saved values; don't alter
3599 ;; the outside binding loci.
3600 (setcdr edebug-outside-pre-command-hook pre-command-hook)
3601 (setcdr edebug-outside-post-command-hook post-command-hook)
3602
3603 )) ; let
3562 )) 3604 ))
3563 3605
3564 (defvar cl-debug-env nil) ;; defined in cl; non-nil when lexical env used. 3606 (defvar cl-debug-env nil) ;; defined in cl; non-nil when lexical env used.
3565 3607
3566 (defun edebug-eval (edebug-expr) 3608 (defun edebug-eval (edebug-expr)
3642 (print-circle (or edebug-print-circle print-circle)) 3684 (print-circle (or edebug-print-circle print-circle))
3643 (print-readably nil)) ;; lemacs uses this. 3685 (print-readably nil)) ;; lemacs uses this.
3644 (edebug-prin1-to-string value))) 3686 (edebug-prin1-to-string value)))
3645 3687
3646 (defun edebug-compute-previous-result (edebug-previous-value) 3688 (defun edebug-compute-previous-result (edebug-previous-value)
3689 (if edebug-unwrap-results
3690 (setq edebug-previous-value
3691 (edebug-unwrap* edebug-previous-value)))
3647 (setq edebug-previous-result 3692 (setq edebug-previous-result
3648 (if (and (integerp edebug-previous-value) 3693 (concat "Result: "
3649 (< edebug-previous-value 256) 3694 (edebug-safe-prin1-to-string edebug-previous-value)
3650 (>= edebug-previous-value 0)) 3695 (let ((name (prin1-char edebug-previous-value)))
3651 (format "Result: %s = %s" edebug-previous-value 3696 (if name (concat " = " name))))))
3652 (single-key-description edebug-previous-value))
3653 (if edebug-unwrap-results
3654 (setq edebug-previous-value
3655 (edebug-unwrap* edebug-previous-value)))
3656 (concat "Result: "
3657 (edebug-safe-prin1-to-string edebug-previous-value)))))
3658 3697
3659 (defun edebug-previous-result () 3698 (defun edebug-previous-result ()
3660 "Print the previous result." 3699 "Print the previous result."
3661 (interactive) 3700 (interactive)
3662 (message "%s" edebug-previous-result)) 3701 (message "%s" edebug-previous-result))
3674 (edebug-outside-excursion 3713 (edebug-outside-excursion
3675 (setq values (cons (edebug-eval edebug-expr) values)) 3714 (setq values (cons (edebug-eval edebug-expr) values))
3676 (edebug-safe-prin1-to-string (car values))))) 3715 (edebug-safe-prin1-to-string (car values)))))
3677 3716
3678 (defun edebug-eval-last-sexp () 3717 (defun edebug-eval-last-sexp ()
3679 "Evaluate sexp before point in the outside environment; 3718 "Evaluate sexp before point in the outside environment; value in minibuffer."
3680 print value in minibuffer."
3681 (interactive) 3719 (interactive)
3682 (edebug-eval-expression (edebug-last-sexp))) 3720 (edebug-eval-expression (edebug-last-sexp)))
3683 3721
3684 (defun edebug-eval-print-last-sexp () 3722 (defun edebug-eval-print-last-sexp ()
3685 "Evaluate sexp before point in the outside environment; 3723 "Evaluate sexp before point in the outside environment; insert the value.
3686 print value into current buffer." 3724 This prints the value into current buffer."
3687 (interactive) 3725 (interactive)
3688 (let* ((edebug-form (edebug-last-sexp)) 3726 (let* ((edebug-form (edebug-last-sexp))
3689 (edebug-result-string 3727 (edebug-result-string
3690 (edebug-outside-excursion 3728 (edebug-outside-excursion
3691 (edebug-safe-prin1-to-string (edebug-safe-eval edebug-form)))) 3729 (edebug-safe-prin1-to-string (edebug-safe-eval edebug-form))))
3696 (princ "\n") 3734 (princ "\n")
3697 )) 3735 ))
3698 3736
3699 ;;; Edebug Minor Mode 3737 ;;; Edebug Minor Mode
3700 3738
3739 (defvar gud-inhibit-global-bindings
3740 "*Non-nil means don't do global rebindings of C-x C-a subcommands.")
3741
3701 ;; Global GUD bindings for all emacs-lisp-mode buffers. 3742 ;; Global GUD bindings for all emacs-lisp-mode buffers.
3702 (define-key emacs-lisp-mode-map "\C-x\C-a\C-s" 'edebug-step-mode) 3743 (unless gud-inhibit-global-bindings
3703 (define-key emacs-lisp-mode-map "\C-x\C-a\C-n" 'edebug-next-mode) 3744 (define-key emacs-lisp-mode-map "\C-x\C-a\C-s" 'edebug-step-mode)
3704 (define-key emacs-lisp-mode-map "\C-x\C-a\C-c" 'edebug-go-mode) 3745 (define-key emacs-lisp-mode-map "\C-x\C-a\C-n" 'edebug-next-mode)
3705 (define-key emacs-lisp-mode-map "\C-x\C-a\C-l" 'edebug-where) 3746 (define-key emacs-lisp-mode-map "\C-x\C-a\C-c" 'edebug-go-mode)
3706 3747 (define-key emacs-lisp-mode-map "\C-x\C-a\C-l" 'edebug-where))
3707 3748
3708 (defvar edebug-mode-map 3749 (defvar edebug-mode-map
3709 (let ((map (copy-keymap emacs-lisp-mode-map))) 3750 (let ((map (copy-keymap emacs-lisp-mode-map)))
3710 ;; control 3751 ;; control
3711 (define-key map " " 'edebug-step-mode) 3752 (define-key map " " 'edebug-step-mode)
4108 4149
4109 4150
4110 ;;; Frequency count and coverage 4151 ;;; Frequency count and coverage
4111 4152
4112 (defun edebug-display-freq-count () 4153 (defun edebug-display-freq-count ()
4113 "Display the frequency count data for each line of the current 4154 "Display the frequency count data for each line of the current definition.
4114 definition. The frequency counts are inserted as comment lines after 4155 The frequency counts are inserted as comment lines after
4115 each line, and you can undo all insertions with one `undo' command. 4156 each line, and you can undo all insertions with one `undo' command.
4116 4157
4117 The counts are inserted starting under the `(' before an expression 4158 The counts are inserted starting under the `(' before an expression
4118 or the `)' after an expression, or on the last char of a symbol. 4159 or the `)' after an expression, or on the last char of a symbol.
4119 The counts are only displayed when they differ from previous counts on 4160 The counts are only displayed when they differ from previous counts on
4413 ;; Install edebug read and eval functions. 4454 ;; Install edebug read and eval functions.
4414 (edebug-install-read-eval-functions) 4455 (edebug-install-read-eval-functions)
4415 4456
4416 (provide 'edebug) 4457 (provide 'edebug)
4417 4458
4459 ;;; arch-tag: 19c8d05c-4554-426e-ac72-e0fa1fcb0808
4418 ;;; edebug.el ends here 4460 ;;; edebug.el ends here