Subject: bug#51026: 29.0.50; Edebug leaves data in symbols plist after instrumentation

From: Arthur Miller <[email-masked]>
Date: Tue, 05 Oct 2021 10:20:14 +0200

1. Instrument any defun/macro for edebug with C-u M-x RET eval-defun
2. Remove instrumentation with M-x edebug-remove-instrumentation RET
3. Check the chosed symbols plist: M-x (symbol-plist 'whatever-you-used)

Edebug data will be present in plist after instrumentation is removed.

Attached patch is suggestion to fix 'edebug-remove-instrumentation' to
remove unnecessary data after instrumentation.

Is edebug-remove-instrumentation only function that can remove edebug
instrumentation?

I am not though sure, if some other place needs to be patched, I am
thinking mostly of edebug-read-and-maybe-wrap-form. 

>From 057a4278bf0b8c8a8985850b505f0a1addd8156f Mon Sep 17 00:00:00 2001
From: Arthur Miller <[email-masked]>
Date: Tue, 5 Oct 2021 09:17:20 +0200
Subject: [PATCH] Clean edebug props on instrumentation removal

* lisp/emacs-lisp/edebug.el (edebug--strip-plist): New function.
(edebug-remove-instrumentation): Added call to 'edebug--strip-plist'.
---
 lisp/emacs-lisp/edebug.el | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index a38c8bd5ca..da8a3f1eb8 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -4529,6 +4529,13 @@ edebug--unwrap*-symbol-function
         (was-macro               `(macro . ,unwrapped))
         (t                       unwrapped))))))
 
+(defun edebug--strip-plist (symbol)
+  "Remove edebug related properties from SYMBOL's plist."
+  (dolist (prop '(edebug edebug-behavior edebug-coverage
+                         edebug-form-spec edebug-freq-count
+                         ghost-edebug))
+    (cl-remprop symbol prop)))
+
 (defun edebug-remove-instrumentation (functions)
   "Remove Edebug instrumentation from FUNCTIONS.
 Interactively, the user is prompted for the function to remove
@@ -4560,6 +4567,7 @@ edebug-remove-instrumentation
   (dolist (symbol functions)
     (when-let ((unwrapped
                 (edebug--unwrap*-symbol-function symbol)))
+      (edebug--strip-plist symbol)
       (defalias symbol unwrapped)))
   (message "Removed edebug instrumentation from %s"
            (mapconcat #'symbol-name functions ", ")))
-- 
2.33.0

In GNU Emacs 29.0.50 (build 2, x86_64-pc-linux-gnu, cairo version 1.17.4)
 of 2021-10-04 built on pascal
Repository revision: c6be44d9b3ec09195f6279e9a503175f8fd60e14
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12013000
System Description: Arch Linux

Configured using:
 'configure --without-modules --with-cairo --with-compress-install
 --with-x-toolkit=no --with-gnutls --without-gconf --without-xwidgets
 --without-toolkit-scroll-bars --without-xaw3d --without-gsettings
 --with-mailutils --with-native-compilation 'CFLAGS=-O2 -march=native
 -mtune=native''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM HARFBUZZ JPEG JSON LCMS2
LIBOTF LIBSYSTEMD LIBXML2 M17N_FLT NATIVE_COMP NOTIFY INOTIFY OLDXMENU
PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF X11 XDBE XIM XPM ZLIB

Important settings:
  value of $LANG: sv_SE.UTF-8
  locale-coding-system: utf-8-unix

Major mode: ELisp/l

Minor modes in effect:
  text-scale-mode: t
  show-paren-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg rfc6068 epg-config gnus-util rmail
rmail-loaddefs auth-source eieio eieio-core eieio-loaddefs
password-cache json map mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils time-date compile text-property-search
comint ansi-color ring helper edmacro kmacro help-fns radix-tree edebug
comp comp-cstr warnings rx cl-seq cl-macs cl-extra debug backtrace
help-mode find-func trace elp face-remap vc-git diff-mode easy-mmode
vc-dispatcher cl-loaddefs cl-lib seq gv subr-x byte-opt bytecomp
byte-compile cconv paren iso-transl tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting font-render-setting cairo x multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 123973 8004)
 (symbols 48 10003 0)
 (strings 32 29672 1979)
 (string-bytes 1 1004452)
 (vectors 16 21210)
 (vector-slots 8 371233 17772)
 (floats 8 50 42)
 (intervals 56 638 1)
 (buffers 992 15))