From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#33201: 26.1; Edebug doesn't work on closures with edebug-unwrap-results Date: Thu, 1 Nov 2018 10:00:56 +0000 Message-ID: <20181101100056.GA4504@ACM> References: <20181031150627.67149.qmail@mail.muc.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1541066421 12309 195.159.176.226 (1 Nov 2018 10:00:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 1 Nov 2018 10:00:21 +0000 (UTC) User-Agent: Mutt/1.10.1 (2018-07-13) Cc: 33201@debbugs.gnu.org To: Allen Li , Gemini Lasswell Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Nov 01 11:00:17 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gI9lw-00035K-2o for geb-bug-gnu-emacs@m.gmane.org; Thu, 01 Nov 2018 11:00:16 +0100 Original-Received: from localhost ([::1]:40953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gI9o2-0005Nk-HX for geb-bug-gnu-emacs@m.gmane.org; Thu, 01 Nov 2018 06:02:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gI9nm-0005Gh-Li for bug-gnu-emacs@gnu.org; Thu, 01 Nov 2018 06:02:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gI9ni-0004rU-Fx for bug-gnu-emacs@gnu.org; Thu, 01 Nov 2018 06:02:09 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:53483) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gI9nd-0004oP-Ss for bug-gnu-emacs@gnu.org; Thu, 01 Nov 2018 06:02:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gI9nd-0004fq-Os for bug-gnu-emacs@gnu.org; Thu, 01 Nov 2018 06:02:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Nov 2018 10:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33201 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 33201-submit@debbugs.gnu.org id=B33201.154106647117905 (code B ref 33201); Thu, 01 Nov 2018 10:02:01 +0000 Original-Received: (at 33201) by debbugs.gnu.org; 1 Nov 2018 10:01:11 +0000 Original-Received: from localhost ([127.0.0.1]:57741 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gI9mp-0004ej-0U for submit@debbugs.gnu.org; Thu, 01 Nov 2018 06:01:11 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:60237 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1gI9mm-0004eZ-To for 33201@debbugs.gnu.org; Thu, 01 Nov 2018 06:01:09 -0400 Original-Received: (qmail 40901 invoked by uid 3782); 1 Nov 2018 10:01:07 -0000 Original-Received: from acm.muc.de (p5B1479F1.dip0.t-ipconnect.de [91.20.121.241]) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 01 Nov 2018 11:01:06 +0100 Original-Received: (qmail 4521 invoked by uid 1000); 1 Nov 2018 10:00:56 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de 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: 208.118.235.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:151890 Archived-At: Hello again, Allen, hello, Gemini. On Wed, Oct 31, 2018 at 20:53:25 -0700, Allen Li wrote: > On Wed, Oct 31, 2018 at 8:06 AM Alan Mackenzie wrote: > > Yes. There is no handling for closures in 26.1's edebug. > > Handling for closures was added to the Emacs master branch on 2018-06-19 > > by Gemini Lasswell, as an incidental enhancement when introducing better > > backtrace handling. Your scenario above works fine in master. > > This fix could probably be backported to the emacs-26 branch, but how > > important is it? What were you actually trying to do when you uncovered > > this bug? > I don't remember. I have encountered this error multiple times before > and given up debugging something. Since one generally runs into bugs > when doing work (that is not hacking on Emacs itself), it's helpful to > be able to debug with minimal obstruction, otherwise it becomes an > unjustifiable distraction from the main task. OK, it sounds like it's a major problem. I've extracted the pertinent part of Gemini's patch and it appears to fix your test case in Emacs 26.1. @Gemini: The patch below is a (small) portion of e09120d68694272ea5efbe13b16936b4382389d8 from 2018-06-19, the commit that introduced Backtrace Mode. Can you see anything against applying this commit to the emacs-26 branch to fix this bug? > I'll try to get a master build working again, but it's always a balance between > instability, getting new bugfixes, and getting actual work done (which > unfortunately > doesn't include hacking on Emacs for me). Could you try this patch out, please, and let me know whether or not it fixes the bug properly. Thanks! --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el @@ -206,8 +207,7 @@ edebug-unwrap-results "Non-nil if Edebug should unwrap results of expressions. That is, Edebug will try to remove its own instrumentation from the result. This is useful when debugging macros where the results of expressions -are instrumented expressions. But don't do this when results might be -circular or an infinite loop will result." +are instrumented expressions." :type 'boolean :group 'edebug) @@ -1265,25 +1265,59 @@ edebug-make-after-form (defun edebug-unwrap (sexp) "Return the unwrapped SEXP or return it as is if it is not wrapped. The SEXP might be the result of wrapping a body, which is a list of -expressions; a `progn' form will be returned enclosing these forms." - (if (consp sexp) - (cond - ((eq 'edebug-after (car sexp)) - (nth 3 sexp)) - ((eq 'edebug-enter (car sexp)) - (macroexp-progn (nthcdr 2 (nth 1 (nth 3 sexp))))) - (t sexp);; otherwise it is not wrapped, so just return it. - ) - sexp)) +expressions; a `progn' form will be returned enclosing these forms. +Does not unwrap inside vectors, records, structures, or hash tables." + (pcase sexp + (`(edebug-after ,_before-form ,_after-index ,form) + form) + (`(lambda ,args (edebug-enter ',_sym ,_arglist + (function (lambda nil . ,body)))) + `(lambda ,args ,@body)) + (`(closure ,env ,args (edebug-enter ',_sym ,_arglist + (function (lambda nil . ,body)))) + `(closure ,env ,args ,@body)) + (`(edebug-enter ',_sym ,_args (function (lambda nil . ,body))) + (macroexp-progn body)) + (_ sexp))) (defun edebug-unwrap* (sexp) "Return the SEXP recursively unwrapped." + (let ((ht (make-hash-table :test 'eq))) + (edebug--unwrap1 sexp ht))) + +(defun edebug--unwrap1 (sexp hash-table) + "Unwrap SEXP using HASH-TABLE of things already unwrapped. +HASH-TABLE contains the results of unwrapping cons cells within +SEXP, which are reused to avoid infinite loops when SEXP is or +contains a circular object." (let ((new-sexp (edebug-unwrap sexp))) (while (not (eq sexp new-sexp)) (setq sexp new-sexp new-sexp (edebug-unwrap sexp))) (if (consp new-sexp) - (mapcar #'edebug-unwrap* new-sexp) + (let ((result (gethash new-sexp hash-table nil))) + (unless result + (let ((remainder new-sexp) + current) + (setq result (cons nil nil) + current result) + (while + (progn + (puthash remainder current hash-table) + (setf (car current) + (edebug--unwrap1 (car remainder) hash-table)) + (setq remainder (cdr remainder)) + (cond + ((atom remainder) + (setf (cdr current) + (edebug--unwrap1 remainder hash-table)) + nil) + ((gethash remainder hash-table nil) + (setf (cdr current) (gethash remainder hash-table nil)) + nil) + (t (setq current + (setf (cdr current) (cons nil nil))))))))) + result) new-sexp))) -- Alan Mackenzie (Nuremberg, Germany).