From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#65620: void function edebug-after Date: Fri, 1 Sep 2023 21:27:12 +0000 Message-ID: References: <87ledsku08.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15547"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Michael Heerdegen , acm@muc.de, 65620@debbugs.gnu.org To: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 01 23:28:09 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qcBgX-0003s2-Hn for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Sep 2023 23:28:09 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qcBgL-0003Ch-LU; Fri, 01 Sep 2023 17:27:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qcBgH-0003CO-7p for bug-gnu-emacs@gnu.org; Fri, 01 Sep 2023 17:27:53 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcBgG-0002LH-WE for bug-gnu-emacs@gnu.org; Fri, 01 Sep 2023 17:27:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qcBgQ-0003MJ-Aa for bug-gnu-emacs@gnu.org; Fri, 01 Sep 2023 17:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Sep 2023 21:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65620 X-GNU-PR-Package: emacs Original-Received: via spool by 65620-submit@debbugs.gnu.org id=B65620.169360365412877 (code B ref 65620); Fri, 01 Sep 2023 21:28:02 +0000 Original-Received: (at 65620) by debbugs.gnu.org; 1 Sep 2023 21:27:34 +0000 Original-Received: from localhost ([127.0.0.1]:34302 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qcBfx-0003Lc-Dw for submit@debbugs.gnu.org; Fri, 01 Sep 2023 17:27:33 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:31161) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qcBfu-0003LL-RP for 65620@debbugs.gnu.org; Fri, 01 Sep 2023 17:27:31 -0400 Original-Received: (qmail 64823 invoked by uid 3782); 1 Sep 2023 23:27:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=muc.de; i=@muc.de; q=dns/txt; s=default; t=1693603634; h=date : to : cc : subject : message-id : references : mime-version : content-type : content-transfer-encoding : in-reply-to : from : from; bh=dcBbCvk+5smHrTP3s8LRSvFuYg9oG5LpXWKbL+0cb4Q=; b=kVoX1oSKvSuggXTy3KZjC9NaLZkCKifaV3vr6d99nCoIqkBpDIhegWCtLstKKY18K053L K+jwNHvJDzIVc3M9SJkZF2n1ZF6PymgI/SsNGdzy+zovnQGksxJD/JrmLpqQ1bGq3/620/A BgYwygOgQYnTh0qcb3rr6EIM44X3Cn4LAzUvu+1oxhmMH7gRTPY+ukahNl0bR8VpneRmoOZ PhlJ7UYKe8Z/NMgRR9LNHekKB3Z7FYJqN+oBbI/n+3/MP/ECcFo+FQSTN9/8iX9UdgIv8dU qHbFkusfAYgE88YEgxtbehhxjH751k+lHWpmfbg4mtPjjePOmH5Q6pHgR8sA== Original-Received: from acm.muc.de (pd953a051.dip0.t-ipconnect.de [217.83.160.81]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 01 Sep 2023 23:27:13 +0200 Original-Received: (qmail 9561 invoked by uid 1000); 1 Sep 2023 21:27:12 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:268936 Archived-At: Hello, Gerd. On Fri, Sep 01, 2023 at 14:27:42 +0200, Gerd Möllmann wrote: > On 01.09.23 11:23, Alan Mackenzie wrote: > > I think a better way of handling this would be to have a "base function" > > for edebug-after (and for edebug-before), as opposed to the nil that each > > of these currently has. These functions would throw an error asking the > > user to check the edebug spec. Something like (untested): > > > > (defun edebug-after (before-index after-index form) > > "Version of `edebug-after' to call when edebug is not yet set up. > > This function gets temporarily replaced by a real function when > > edebug becomes active." > > (error "Invalid call to `edebug-after' for %S: Is your debug spec \ > > correct?" form)) > > > > .. What do you think? > I find that an excellent idea! The error "void function edebug-after" > might indeed be considered a bit unhelpful by some :-). Haven't tested > anything either, though... Here's a working patch with a slight improvement: the error message identifies the macro suspected of having an erroneous edebug spec. diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index 9a06807bcdc..a6153d599ac 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el @@ -2469,12 +2469,50 @@ edebug-run-fast (setf (cdr (assq 'edebug edebug-behavior-alist)) '(edebug-default-enter edebug-fast-before edebug-fast-after))) -(defalias 'edebug-before nil +;; The following versions of `edebug-before' and `edebug-after' exist +;; to handle the error which occurs if either of them gets called +;; without an enclosing `edebug-enter'. This can happen, for example, +;; when a macro mistakenly has a `form' element in its edebug spec, +;; and it additionally, at macro-expansion time, calls `eval', +;; `apply', or `funcall' (etc.) on the corresponding argument. This +;; is intended to fix bug#65620. + +(defun edebug-b/a-error (func) + "Throw an error for an invalid call of FUNC. +FUNC is expected to be `edebug-before' or `edebug-after'." + (let (this-macro + (n 0) + bt-frame) + (while (and (setq bt-frame (backtrace-frame n)) + (not (and (car bt-frame) + (eq (cadr bt-frame) 'macroexpand-1)))) + (setq n (1+ n))) + (when bt-frame + (setq this-macro (caaddr bt-frame))) + + (error + (concat "Invalid call to `" (symbol-name func) "'" + (if this-macro + (concat ". Is the edebug spec for `" + (symbol-name this-macro) + "' correct?") + ""))))) + +(defun edebug-before (_before-index) "Function called by Edebug before a form is evaluated. -See `edebug-behavior-alist' for implementations.") -(defalias 'edebug-after nil +See `edebug-behavior-alist' for other implementations. This +version of `edebug-before' gets called when edebug is not yet set +up. `edebug-enter' binds the function cell to a real function +when edebug becomes active." + (edebug-b/a-error 'edebug-before)) + +(defun edebug-after (_before-index _after-index _form) "Function called by Edebug after a form is evaluated. -See `edebug-behavior-alist' for implementations.") +See `edebug-behavior-alist' for other implementations. This +version of `edebug-after' gets called when edebug is not yet set +up. `edebug-enter' binds the function cell to a real function +when edebug becomes active." + (edebug-b/a-error 'edebug-after)) (defun edebug--update-coverage (after-index value) (let ((old-result (aref edebug-coverage after-index))) -- Alan Mackenzie (Nuremberg, Germany).