GNU bug report logs - #38195
27.0.50; `edebug-remove-instrumentation' doesn't work for adviced functions

Previous Next

Package: emacs;

Reported by: Michael Heerdegen <michael_heerdegen <at> web.de>

Date: Wed, 13 Nov 2019 13:56:01 UTC

Severity: normal

Found in version 27.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 38195 <at> debbugs.gnu.org
Subject: bug#38195: 27.0.50; `edebug-remove-instrumentation' doesn't work for adviced functions
Date: Sun, 17 Nov 2019 13:55:16 +0100
[Message part 1 (text/plain, inline)]
Michael Heerdegen <michael_heerdegen <at> web.de> writes:

> Hello again,
>
> I'm preparing a new patch with less quirks.

New patch: not much different but hopefully better understandable now.
I also added a comment about why we are allowed to just strip advises.
Also did some testing - seems to work ok.

[0001-WIP-Try-to-fix-edebug-remove-instrumentation-for-adv.patch (text/x-diff, inline)]
From 29380dcd30523e057d8fd45106f1d077e4212198 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen <at> web.de>
Date: Thu, 14 Nov 2019 17:47:51 +0100
Subject: [PATCH] WIP: Try to fix edebug-remove-instrumentation for advised
 funs

---
 lisp/emacs-lisp/edebug.el | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index 5d52704410..e0fcdf0f86 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -4571,6 +4571,23 @@ edebug-unload-function
   ;; Continue standard unloading.
   nil)

+(defun edebug--unwrap*-symbol-function (symbol)
+  ;; Try to unwrap SYMBOL's symbol function.  The result is suitable
+  ;; to be fbound to SYMBOL with `defalias'.  When no unwrapping could
+  ;; be done return nil.
+  (pcase (symbol-function symbol)
+    ((or (and `(macro . ,(and (pred advice--p) ad)) (let was-macro t))
+         (and (pred advice--p) ad                   (let was-macro nil)))
+     ;; `defalias' takes care of any advises so we can just strip them
+     (let* ((orig-f (advice--cd*r ad))
+            (unwrapped (edebug-unwrap* orig-f)))
+       (cond
+        ((equal unwrapped orig-f) nil)
+        (was-macro               `(macro . ,unwrapped))
+        (t                       unwrapped))))
+    (sym-fun (let ((unwrapped (edebug-unwrap* sym-fun)))
+               (if (equal sym-fun unwrapped) nil unwrapped)))))
+
 (defun edebug-remove-instrumentation (functions)
   "Remove Edebug instrumentation from FUNCTIONS.
 Interactively, the user is prompted for the function to remove
@@ -4582,10 +4599,10 @@ edebug-remove-instrumentation
        (lambda (symbol)
          (when (and (get symbol 'edebug)
                     (or (functionp symbol)
-                        (macrop symbol)))
-           (let ((unwrapped (edebug-unwrap* (symbol-function symbol))))
-             (unless (equal unwrapped (symbol-function symbol))
-               (push symbol functions)))))
+                        (macrop symbol))
+                    (edebug--unwrap*-symbol-function
+                     symbol))
+           (push symbol functions)))
        obarray)
       (unless functions
         (error "Found no functions to remove instrumentation from"))
@@ -4599,8 +4616,9 @@ edebug-remove-instrumentation
           functions)))))
   ;; Remove instrumentation.
   (dolist (symbol functions)
-    (setf (symbol-function symbol)
-          (edebug-unwrap* (symbol-function symbol))))
+    (when-let ((unwrapped
+                (edebug--unwrap*-symbol-function symbol)))
+      (defalias symbol unwrapped)))
   (message "Removed edebug instrumentation from %s"
            (mapconcat #'symbol-name functions ", ")))

--
2.24.0

[Message part 3 (text/plain, inline)]

Thanks,

Michael.

This bug report was last modified 4 years and 304 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.