1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-24 06:20:43 -08:00

Fix edebug instrumentation removing from advised functions

* lisp/emacs-lisp/edebug.el (edebug-remove-instrumentation): Handle
advised functions correctly.
This commit is contained in:
Michael Heerdegen 2019-11-14 17:47:51 +01:00
parent be779cf7b4
commit 311ca036f4

View file

@ -4571,6 +4571,21 @@ With prefix argument, make it a temporary breakpoint."
;; Continue standard unloading. ;; Continue standard unloading.
nil) nil)
(defun edebug--unwrap*-symbol-function (symbol)
;; Try to unwrap SYMBOL's `symbol-function'. The result is suitable
;; to be fbound back to SYMBOL with `defalias'. When no unwrapping
;; could be done return nil.
(pcase (symbol-function symbol)
((or (and `(macro . ,f) (let was-macro t))
(and f (let was-macro nil)))
;; `defalias' takes care of advises so we must strip them
(let* ((orig-f (advice--cd*r f))
(unwrapped (edebug-unwrap* orig-f)))
(cond
((equal unwrapped orig-f) nil)
(was-macro `(macro . ,unwrapped))
(t unwrapped))))))
(defun edebug-remove-instrumentation (functions) (defun edebug-remove-instrumentation (functions)
"Remove Edebug instrumentation from FUNCTIONS. "Remove Edebug instrumentation from FUNCTIONS.
Interactively, the user is prompted for the function to remove Interactively, the user is prompted for the function to remove
@ -4582,10 +4597,10 @@ instrumentation for, defaulting to all functions."
(lambda (symbol) (lambda (symbol)
(when (and (get symbol 'edebug) (when (and (get symbol 'edebug)
(or (functionp symbol) (or (functionp symbol)
(macrop symbol))) (macrop symbol))
(let ((unwrapped (edebug-unwrap* (symbol-function symbol)))) (edebug--unwrap*-symbol-function
(unless (equal unwrapped (symbol-function symbol)) symbol))
(push symbol functions))))) (push symbol functions)))
obarray) obarray)
(unless functions (unless functions
(error "Found no functions to remove instrumentation from")) (error "Found no functions to remove instrumentation from"))
@ -4599,8 +4614,9 @@ instrumentation for, defaulting to all functions."
functions))))) functions)))))
;; Remove instrumentation. ;; Remove instrumentation.
(dolist (symbol functions) (dolist (symbol functions)
(setf (symbol-function symbol) (when-let ((unwrapped
(edebug-unwrap* (symbol-function symbol)))) (edebug--unwrap*-symbol-function symbol)))
(defalias symbol unwrapped)))
(message "Removed edebug instrumentation from %s" (message "Removed edebug instrumentation from %s"
(mapconcat #'symbol-name functions ", "))) (mapconcat #'symbol-name functions ", ")))