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.devel Subject: Re: Fontification error backtrace [Was: Why is it so difficult to get a Lisp backtrace?] Date: Tue, 28 Jun 2022 19:31:59 +0000 Message-ID: References: <87edzchi3d.fsf@gnus.org> <83sfnsadow.fsf@gnu.org> <83o7yg9f0w.fsf@gnu.org> <83r1396lvr.fsf@gnu.org> <83edz87ivz.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38960"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jun 28 21:33:04 2022 Return-path: Envelope-to: ged-emacs-devel@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 1o6GxL-0009u5-L7 for ged-emacs-devel@m.gmane-mx.org; Tue, 28 Jun 2022 21:33:03 +0200 Original-Received: from localhost ([::1]:51456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6GxK-00041A-8j for ged-emacs-devel@m.gmane-mx.org; Tue, 28 Jun 2022 15:33:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6GwP-000385-Ql for emacs-devel@gnu.org; Tue, 28 Jun 2022 15:32:05 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:10719 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1o6GwM-0002I9-K3 for emacs-devel@gnu.org; Tue, 28 Jun 2022 15:32:05 -0400 Original-Received: (qmail 94675 invoked by uid 3782); 28 Jun 2022 19:32:00 -0000 Original-Received: from acm.muc.de (p4fe1595e.dip0.t-ipconnect.de [79.225.89.94]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 28 Jun 2022 21:31:59 +0200 Original-Received: (qmail 8045 invoked by uid 1000); 28 Jun 2022 19:31:59 -0000 Content-Disposition: inline In-Reply-To: <83edz87ivz.fsf@gnu.org> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.1; envelope-from=acm@muc.de; helo=mail.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:291700 Archived-At: Hello, Eli. On Tue, Jun 28, 2022 at 21:17:04 +0300, Eli Zaretskii wrote: > > Date: Tue, 28 Jun 2022 17:28:38 +0000 > > Cc: larsi@gnus.org, emacs-devel@gnu.org > > From: Alan Mackenzie > > > > > > > . emit the backtrace int *Messages* > > > > > > > . add the backtrace to delayed-warnings-list > > > > > > Why can't the backtrace be generated and stored, and only displayed at a > > > > > > subsequent redisplay (probably the next one)? > > > > > That's what the second alternative above already does. > > > > OK, I've got some code. :-) > > > Sigh. I suggested two alternatives, but you effectively > > > ignored/rejected both of them. Why? > > *Messages* just doesn't feel the right place to put a backtrace. > That's where we currently log all the errors during redisplay, since > Emacs 21.1. So why this one is different? It's not a single line, or a small number of lines. It could potentially be a stack overflow error, generating a large backtrace, which might have more lines than message-log-max. > But you _really_ dislike *Messages*, then put the stuff into another > buffer, like *backtrace-in-redisplay* or somesuch. I'm currently using the buffer *Backtrace*. Is there anything wrong with that? > > delayed-warnings-list consists of a list of structured lists, rather than > > the vanilla text output by debug-early. > Why is it a problem? You could again stash the backtrace somewhere > and only show the name of that buffer in the warning text. Using > delayed-warnings-list makes sure the problem is not missed. > > Also these delayed warnings get displayed between post-command-hook > > and redisplay, which is not an optimal time to display a backtrace > > generated in redisplay. > The buffer with warnings pops up very soon after redisplay, which is > more-or-less exactly what you wanted? OK, I've never used it. On reading the documentation, I expected it to wait until after the next command. > > > Third, why are you singling out the fontifications? they are not the > > > only source of Lisp errors in code called by the display engine. > > > Moreover, handle_fontified_prop is not the only way of calling > > > expensive Lisp code that deals with faces. > > All that's true, yet fontification errors are an important source of > > difficult to debug errors. We could certainly extend the new backtrace > > mechanism to handle these other types of bug, too. > It makes very little sense to me to create infrastructure that caters > only to your current and immediate problem. If we introduce such a > feature, it should work with any Lisp called from redisplay. OK. It shouldn't actually be much more difficult to keep the new facility generic. > > > > As already noted, the *Backtrace* buffer doesn't appear on the screen, > > > > yet. Any hints on how to achieve this would be most welcome. > > > Any reasons you'd want that? Once the buffer exists, why do you need > > > to actually pop it up (and thus potentially disrupt the very > > > window/frame configuration which you are trying to debug)? > > A debug-on-error backtrace gets displayed immediately, so it would help > > consistency. If the window where the error occurred isn't occupying its > > entire frame, there should be room to put the backtrace somewhere else, I > > think. I'm not at all experienced with things like pop-to-buffer, but > > they're supposed to be very flexible. > I think showing a delayed-warning with the text that mentions the > buffer with the backtrace is completely adequate. It stops short of > popping the window with a backtrace itself, but that could be added > later, if necessary, perhaps as a feature of delayed-warning. I think that would be a good compromise. > > > > It seems I could really do with after-redisplay-hook, in which I > > > > could call pop-to-buffer, then cause redisplay to be restarted. > > > I think you misunderstand what such a hook could do, and why it could > > > be useful, if at all, in the first place. If all you want is to cause > > > the main loop perform some command after redisplay cycle ends, we > > > already have several mechanisms in place for doing that. > > That's what I want, yes, but couldn't find any such mechanism anywhere > > when I looked. > One thing that comes to mind is a timer. Another thing is pushing > something onto unread-command-events. I'm sure there are more. OK, yes, maybe a timer would be the thing. > > Yes. How about what you suggested above, namely creating the backtrace > > in save_eval_handler rather than signal_or_quit, at least as a second > > attempt. Though I don't think this would handle errors in other Lisp > > called from redisplay. Now I remember why I created the backtrace in signal_or_quit - it needs to be done before the stack gets unwound, which happens later in signal_or_quit. On return to save_eval_handler is just too late for this. > It will, because any Lisp we call goes though safe_eval. The only > reason why your original proposal didn't was because it bound the > variable which enables this only in handle_fontified_prop. But we > don't need this flag if the logic to decide what to do with the error > will be in save_eval_handler. Then the mechanism I've implemented, namely to set redisplay_deep_handler to the handler which would handle an error, could be made to serve for other sorts of Lisp code. Probably I'll need to rename some variables whose name contains "fontification" and suchlike. > And you need to consider one more factor: code from display engine, > including fontification via handle_fontified_prop, is called also from > user commands, not via redisplay_internal. For example, commands like > C-n and C-v invoke display code. Errors signaled there _can_ be left > to go to top-level and probably could call the debugger. To test > whether any given code was called from redisplay_internal, test the > value of the variable redisplaying_p. OK, this is a further complication. But it would be good to get to the debugger if possible, rather than just having a "historical" backtrace. -- Alan Mackenzie (Nuremberg, Germany).