* lisp/emacs-lisp/edebug.el: Use backtrace-eval to handle lexical variables.

(edebug-eval): Use backtrace-eval.
(edebug--display, edebug--recursive-edit): Don't let-bind the
edebug-outer-* vars that keep track of variables we locally let-bind.
(edebug-outside-excursion): Don't restore outside values of locally
let-bound vars.
(edebug--display): Use user-error.
(cl-lexical-debug, cl-debug-env): Remove.
This commit is contained in:
Stefan Monnier 2013-07-26 11:09:04 -04:00
parent 045f7a53f9
commit 53ff3e77b4
2 changed files with 40 additions and 173 deletions

View file

@ -2088,8 +2088,6 @@ expressions; a `progn' form will be returned enclosing these forms."
(defvar edebug-coverage) ; the coverage results of each expression of function.
(defvar edebug-buffer) ; which buffer the function is in.
(defvar edebug-outside-executing-macro)
(defvar edebug-outside-defining-kbd-macro)
(defvar edebug-execution-mode 'step) ; Current edebug mode set by user.
(defvar edebug-next-execution-mode nil) ; Use once instead of initial mode.
@ -2097,12 +2095,6 @@ expressions; a `progn' form will be returned enclosing these forms."
(defvar edebug-outside-debug-on-error) ; the value of debug-on-error outside
(defvar edebug-outside-debug-on-quit) ; the value of debug-on-quit outside
(defvar edebug-outside-pre-command-hook)
(defvar edebug-outside-post-command-hook)
(defvar cl-lexical-debug) ;; Defined in cl.el
;;; Handling signals
(defun edebug-signal (signal-name signal-data)
@ -2154,10 +2146,7 @@ error is signaled again."
;; Binding these may not be the right thing to do.
;; We want to allow the global values to be changed.
(debug-on-error (or debug-on-error edebug-on-error))
(debug-on-quit edebug-on-quit)
;; Lexical bindings must be uncompiled for this to work.
(cl-lexical-debug t))
(debug-on-quit edebug-on-quit))
(unwind-protect
(let ((signal-hook-function 'edebug-signal))
(setq edebug-execution-mode (or edebug-next-execution-mode
@ -2386,9 +2375,6 @@ MSG is printed after `::::} '."
(defvar edebug-window-data) ; window and window-start for current function
(defvar edebug-outside-windows) ; outside window configuration
(defvar edebug-eval-buffer) ; for the evaluation list.
(defvar edebug-outside-o-a-p) ; outside overlay-arrow-position
(defvar edebug-outside-o-a-s) ; outside overlay-arrow-string
(defvar edebug-outside-c-i-e-a) ; outside cursor-in-echo-area
(defvar edebug-outside-d-c-i-n-s-w) ; outside default-cursor-in-non-selected-windows
(defvar edebug-eval-list nil) ;; List of expressions to evaluate.
@ -2398,8 +2384,6 @@ MSG is printed after `::::} '."
;; Emacs 19 adds an arg to mark and mark-marker.
(defalias 'edebug-mark-marker 'mark-marker)
(defvar edebug-outside-unread-command-events)
(defun edebug--display (value offset-index arg-mode)
(unless (marker-position edebug-def-mark)
;; The buffer holding the source has been killed.
@ -2421,7 +2405,6 @@ MSG is printed after `::::} '."
(edebug-outside-buffer (current-buffer))
(edebug-outside-point (point))
(edebug-outside-mark (edebug-mark))
(edebug-outside-unread-command-events unread-command-events)
edebug-outside-windows ; Window or screen configuration.
edebug-buffer-points
@ -2431,9 +2414,6 @@ MSG is printed after `::::} '."
edebug-trace-window
edebug-trace-window-start
(edebug-outside-o-a-p overlay-arrow-position)
(edebug-outside-o-a-s overlay-arrow-string)
(edebug-outside-c-i-e-a cursor-in-echo-area)
(edebug-outside-d-c-i-n-s-w
(default-value 'cursor-in-non-selected-windows)))
(unwind-protect
@ -2445,8 +2425,7 @@ MSG is printed after `::::} '."
)
(setq-default cursor-in-non-selected-windows t)
(if (not (buffer-name edebug-buffer))
(let ((debug-on-error nil))
(error "Buffer defining %s not found" edebug-function)))
(user-error "Buffer defining %s not found" edebug-function))
(if (eq 'after arg-mode)
;; Compute result string now before windows are modified.
@ -2486,10 +2465,9 @@ MSG is printed after `::::} '."
;; Check whether positions are up-to-date.
;; This assumes point is never before symbol.
(if (not (memq (following-char) '(?\( ?\# ?\` )))
(let ((debug-on-error nil))
(error "Source has changed - reevaluate definition of %s"
edebug-function)
)))
(user-error "Source has changed - reevaluate definition of %s"
edebug-function)
))
(setcdr edebug-window-data
(edebug-adjust-window (cdr edebug-window-data)))
@ -2645,11 +2623,6 @@ MSG is printed after `::::} '."
(if edebug-eval-buffer (kill-buffer edebug-eval-buffer))
(with-timeout-unsuspend edebug-with-timeout-suspend)
;; Reset global variables to outside values in case they were changed.
(setq
unread-command-events edebug-outside-unread-command-events
overlay-arrow-position edebug-outside-o-a-p
overlay-arrow-string edebug-outside-o-a-s
cursor-in-echo-area edebug-outside-c-i-e-a)
(setq-default cursor-in-non-selected-windows edebug-outside-d-c-i-n-s-w)
)))
@ -2667,27 +2640,6 @@ MSG is printed after `::::} '."
(defvar edebug-inside-windows)
(defvar edebug-interactive-p)
(defvar edebug-outside-map)
(defvar edebug-outside-standard-output)
(defvar edebug-outside-standard-input)
(defvar edebug-outside-current-prefix-arg)
(defvar edebug-outside-last-command)
(defvar edebug-outside-this-command)
;; Note: here we have defvars for variables that are
;; built-in in certain versions.
;; Each defvar makes a difference
;; in versions where the variable is *not* built-in.
;; Emacs 18 FIXME
;; Emacs 19.
(defvar edebug-outside-last-command-event)
(defvar edebug-outside-last-input-event)
(defvar edebug-outside-last-event-frame)
(defvar edebug-outside-last-nonmenu-event)
(defvar edebug-outside-track-mouse)
(defun edebug--recursive-edit (arg-mode)
;; Start up a recursive edit inside of edebug.
;; The current buffer is the edebug-buffer, which is put into edebug-mode.
@ -2705,28 +2657,6 @@ MSG is printed after `::::} '."
;; The window configuration may be saved and restored
;; during a recursive-edit
edebug-inside-windows
;; Save the outside value of executing macro. (here??)
(edebug-outside-executing-macro executing-kbd-macro)
(edebug-outside-pre-command-hook
(edebug-var-status 'pre-command-hook))
(edebug-outside-post-command-hook
(edebug-var-status 'post-command-hook))
(edebug-outside-standard-output standard-output)
(edebug-outside-standard-input standard-input)
(edebug-outside-defining-kbd-macro defining-kbd-macro)
(edebug-outside-last-command last-command)
(edebug-outside-this-command this-command)
(edebug-outside-current-prefix-arg current-prefix-arg)
(edebug-outside-last-input-event last-input-event)
(edebug-outside-last-command-event last-command-event)
(edebug-outside-last-event-frame last-event-frame)
(edebug-outside-last-nonmenu-event last-nonmenu-event)
(edebug-outside-track-mouse track-mouse)
)
(unwind-protect
@ -2757,7 +2687,7 @@ MSG is printed after `::::} '."
(overriding-local-map nil)
(overriding-terminal-local-map nil)
;; Bind again to outside values.
;; Bind again to outside values.
(debug-on-error edebug-outside-debug-on-error)
(debug-on-quit edebug-outside-debug-on-quit)
@ -2805,27 +2735,7 @@ MSG is printed after `::::} '."
;; gotta have a buffer to let its buffer local variables be set
(get-buffer-create " bogus edebug buffer"))
));; inner let
;; Reset global vars to outside values, in case they have been changed.
(setq
last-command-event edebug-outside-last-command-event
last-command edebug-outside-last-command
this-command edebug-outside-this-command
current-prefix-arg edebug-outside-current-prefix-arg
last-input-event edebug-outside-last-input-event
last-event-frame edebug-outside-last-event-frame
last-nonmenu-event edebug-outside-last-nonmenu-event
track-mouse edebug-outside-track-mouse
standard-output edebug-outside-standard-output
standard-input edebug-outside-standard-input
defining-kbd-macro edebug-outside-defining-kbd-macro)
(setq executing-kbd-macro edebug-outside-executing-macro)
(edebug-restore-status
'post-command-hook edebug-outside-post-command-hook)
(edebug-restore-status
'pre-command-hook edebug-outside-pre-command-hook))))
)))
;;; Display related functions
@ -3423,6 +3333,9 @@ edebug-mode."
(defmacro edebug-outside-excursion (&rest body)
"Evaluate an expression list in the outside context.
Return the result of the last expression."
;; Only restores the non-variables context since all the variables let-bound
;; by Edebug will be properly reset to the appropriate context's value by
;; backtrace-eval.
(declare (debug t))
`(save-excursion ; of current-buffer
(if edebug-save-windows
@ -3435,89 +3348,32 @@ Return the result of the last expression."
(edebug-set-windows edebug-outside-windows)))
(set-buffer edebug-buffer) ; why?
;; (use-local-map edebug-outside-map)
(set-match-data edebug-outside-match-data)
;; Restore outside context.
(let (;; (edebug-inside-map (current-local-map)) ;; restore map??
(last-command-event edebug-outside-last-command-event)
(last-command edebug-outside-last-command)
(this-command edebug-outside-this-command)
(unread-command-events edebug-outside-unread-command-events)
(current-prefix-arg edebug-outside-current-prefix-arg)
(last-input-event edebug-outside-last-input-event)
(last-event-frame edebug-outside-last-event-frame)
(last-nonmenu-event edebug-outside-last-nonmenu-event)
(track-mouse edebug-outside-track-mouse)
(standard-output edebug-outside-standard-output)
(standard-input edebug-outside-standard-input)
(setq-default cursor-in-non-selected-windows edebug-outside-d-c-i-n-s-w)
(unwind-protect
(with-current-buffer edebug-outside-buffer ; of edebug-buffer
(goto-char edebug-outside-point)
(if (marker-buffer (edebug-mark-marker))
(set-marker (edebug-mark-marker) edebug-outside-mark))
,@body)
(executing-kbd-macro edebug-outside-executing-macro)
(defining-kbd-macro edebug-outside-defining-kbd-macro)
;; Get the values out of the saved statuses.
(pre-command-hook (cdr edebug-outside-pre-command-hook))
(post-command-hook (cdr edebug-outside-post-command-hook))
;; Back to edebug-buffer. Restore rest of inside context.
;; (use-local-map edebug-inside-map)
(if edebug-save-windows
;; Restore inside windows.
(edebug-set-windows edebug-inside-windows))
;; See edebug-display.
(overlay-arrow-position edebug-outside-o-a-p)
(overlay-arrow-string edebug-outside-o-a-s)
(cursor-in-echo-area edebug-outside-c-i-e-a)
)
(setq-default cursor-in-non-selected-windows edebug-outside-d-c-i-n-s-w)
(unwind-protect
(with-current-buffer edebug-outside-buffer ; of edebug-buffer
(goto-char edebug-outside-point)
(if (marker-buffer (edebug-mark-marker))
(set-marker (edebug-mark-marker) edebug-outside-mark))
,@body)
;; Save values that may have been changed.
(setq edebug-outside-d-c-i-n-s-w
(default-value 'cursor-in-non-selected-windows))
;; Back to edebug-buffer. Restore rest of inside context.
;; (use-local-map edebug-inside-map)
(if edebug-save-windows
;; Restore inside windows.
(edebug-set-windows edebug-inside-windows))
;; Save values that may have been changed.
(setq
edebug-outside-last-command-event last-command-event
edebug-outside-last-command last-command
edebug-outside-this-command this-command
edebug-outside-unread-command-events unread-command-events
edebug-outside-current-prefix-arg current-prefix-arg
edebug-outside-last-input-event last-input-event
edebug-outside-last-event-frame last-event-frame
edebug-outside-last-nonmenu-event last-nonmenu-event
edebug-outside-track-mouse track-mouse
edebug-outside-standard-output standard-output
edebug-outside-standard-input standard-input
edebug-outside-executing-macro executing-kbd-macro
edebug-outside-defining-kbd-macro defining-kbd-macro
edebug-outside-o-a-p overlay-arrow-position
edebug-outside-o-a-s overlay-arrow-string
edebug-outside-c-i-e-a cursor-in-echo-area
edebug-outside-d-c-i-n-s-w (default-value
'cursor-in-non-selected-windows)
)
;; Restore the outside saved values; don't alter
;; the outside binding loci.
(setcdr edebug-outside-pre-command-hook pre-command-hook)
(setcdr edebug-outside-post-command-hook post-command-hook)
(setq-default cursor-in-non-selected-windows t)
)) ; let
))
(defvar cl-debug-env) ; defined in cl; non-nil when lexical env used.
;; Restore the outside saved values; don't alter
;; the outside binding loci.
(setq-default cursor-in-non-selected-windows t))))
(defun edebug-eval (expr)
;; Are there cl lexical variables active?
(eval (if (and (bound-and-true-p cl-debug-env)
(fboundp 'cl-macroexpand-all))
(cl-macroexpand-all expr cl-debug-env)
expr)
lexical-binding))
(backtrace-eval expr 0 'edebug-after))
(defun edebug-safe-eval (expr)
;; Evaluate EXPR safely.