From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#38195: 27.0.50; `edebug-remove-instrumentation' doesn't work for adviced functions Date: Thu, 14 Nov 2019 14:08:24 -0500 Message-ID: References: <87mucz98y9.fsf@web.de> <87r22brq3b.fsf@gnus.org> <87eeya9z3z.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="136672"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Lars Ingebrigtsen , 38195@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Nov 14 20:09:13 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iVKUS-000ZLF-Lk for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Nov 2019 20:09:12 +0100 Original-Received: from localhost ([::1]:60932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVKUR-0002Ph-0n for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Nov 2019 14:09:11 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53391) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVKUJ-0002Oe-Ud for bug-gnu-emacs@gnu.org; Thu, 14 Nov 2019 14:09:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iVKUI-00013D-HM for bug-gnu-emacs@gnu.org; Thu, 14 Nov 2019 14:09:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54650) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iVKUI-000132-BC for bug-gnu-emacs@gnu.org; Thu, 14 Nov 2019 14:09:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iVKUI-00005V-34 for bug-gnu-emacs@gnu.org; Thu, 14 Nov 2019 14:09:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Nov 2019 19:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38195 X-GNU-PR-Package: emacs Original-Received: via spool by 38195-submit@debbugs.gnu.org id=B38195.1573758516304 (code B ref 38195); Thu, 14 Nov 2019 19:09:02 +0000 Original-Received: (at 38195) by debbugs.gnu.org; 14 Nov 2019 19:08:36 +0000 Original-Received: from localhost ([127.0.0.1]:35238 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iVKTs-0008WU-AA for submit@debbugs.gnu.org; Thu, 14 Nov 2019 14:08:36 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:44063) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iVKTp-0008WF-TR for 38195@debbugs.gnu.org; Thu, 14 Nov 2019 14:08:34 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 430FC449CDB; Thu, 14 Nov 2019 14:08:27 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id CC249449CD9; Thu, 14 Nov 2019 14:08:25 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1573758505; bh=RzC2lX14fb8r7j4F22Pl7kDkgiqcEgTvJW8PlX4kg50=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=QrgIHmpttPfkKjThv0WL8Jdy+6Y8hLuibRkAiCaTxunOfKZ3BVRIcCy3Z7t8t5ury rVy/KvaEzQjxw7lqKGY5VO3y9m3+k7AMmxnr7tueGq7A8Lubw0qaSxzJ+YEH9ISxB/ hGvPzP58HkUiSJQ+CqiHCXmcDnsmniVZNbT+dQZdw1jJxZgEemGsuBbcXaQIcaCkuE 69OEDU+rXH6JA4YwusqWx26RKLlJ5AGzIds4SoUnKzY20DRKDDLNeK7Y//tfkQgyD/ 1+up4Cm00ii72wH+IzW2bMyhczN5hdOVrL8tagmUYU1vVLFULU29nEZvGe+2IDyyx0 PK8IfOIOwP4Cw== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 9AF59120850; Thu, 14 Nov 2019 14:08:25 -0500 (EST) In-Reply-To: <87eeya9z3z.fsf@web.de> (Michael Heerdegen's message of "Thu, 14 Nov 2019 17:55:28 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:171610 Archived-At: > +(defun edebug--advised-p (symbol) > + ;; Non-nil when SYMBOL's `symbol-function' is advised. The non-nil > + ;; return value is the unwrapped base function if it was wrapped, > + ;; and the symbol t else. Do you really mean "advised"? It seems that this tests whether the code is *instrumented* by looking past the (potential) pieces of advice. I'll assume the above should say "instrumented", but if not, then disregard the rest because I'm just confused. > + (pcase (symbol-function symbol) > + ((and (pred advice--p) > + (app advice--cd*r orig-f) > + (let unwrapped (edebug-unwrap* orig-f))) > + (if (equal unwrapped orig-f) t unwrapped)) > + (`(macro . ,(and (pred advice--p) > + (app advice--cd*r orig-f) > + (let unwrapped (edebug-unwrap* orig-f)))) > + (if (equal unwrapped orig-f) t `(macro . ,unwrapped))))) [ That's pretty ugly. I think I'd move the `app` and the `let` outside of those patterns and into the code of the corresponding branch. ] > - (let ((unwrapped (edebug-unwrap* (symbol-function symbol)))) > - (unless (equal unwrapped (symbol-function symbol)) > - (push symbol functions))))) > + (if-let ((advised (edebug--advised-p symbol))) > + (unless (eq advised t) > + (push symbol functions)) > + (let ((unwrapped (edebug-unwrap* > + (symbol-function symbol)))) > + (unless (equal unwrapped (symbol-function symbol)) > + (push symbol functions)))))) How 'bout using something like (defun edebug--symbol-function (sym) (let ((def (symbol-function sym))) (if (eq 'macro (car-safe def)) (setq def (cdr def))) (advice--cdr* def))) and replacing (some) uses of `symbol-function` with it? > ;; Remove instrumentation. > (dolist (symbol functions) > - (setf (symbol-function symbol) > - (edebug-unwrap* (symbol-function symbol)))) > + (if-let ((advised (edebug--advised-p symbol))) > + (unless (eq advised t) > + (funcall (or (get symbol 'defalias-fset-function) #'fset) > + symbol advised)) > + (setf (symbol-function symbol) > + (edebug-unwrap* (symbol-function symbol))))) Yuck! Can't we just use `defalias` rather than `fset` (and that should take care of calling `defalias-fset-function` when needed)? > I'm not sure if I should use `indirect-function' somewhere instead of > `symbol-function', That's a question for Edebug's ;-) In the above I assumed that there's a good reason why it uses `symbol-function` so I preserved it. > but I also don't understand (and also didn't yet try to find out) why > nadvice doesn't use `indirect-function' for its manipulations. That's because if I have `foo` as an alias for `bar` and I advise `foo` I don't want it to affect `bar`: if you want to affect both, then you should advise `bar`. Stefan