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: Redisplay hook error backtraces Date: Fri, 15 Jul 2022 18:18:14 +0000 Message-ID: References: <83fsj4uvjg.fsf@gnu.org> <83mtdct5ze.fsf@gnu.org> <83bktru74y.fsf@gnu.org> <83tu7isz4w.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="7433"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, 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 Fri Jul 15 20:19:07 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 1oCPu7-0001ju-QO for ged-emacs-devel@m.gmane-mx.org; Fri, 15 Jul 2022 20:19:07 +0200 Original-Received: from localhost ([::1]:55566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oCPu6-0004kC-4V for ged-emacs-devel@m.gmane-mx.org; Fri, 15 Jul 2022 14:19:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oCPtX-00045I-Gl for emacs-devel@gnu.org; Fri, 15 Jul 2022 14:18:31 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:52861 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.90_1) (envelope-from ) id 1oCPtV-0003BB-AT for emacs-devel@gnu.org; Fri, 15 Jul 2022 14:18:31 -0400 Original-Received: (qmail 85485 invoked by uid 3782); 15 Jul 2022 18:18:16 -0000 Original-Received: from acm.muc.de (p4fe15759.dip0.t-ipconnect.de [79.225.87.89]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 15 Jul 2022 20:18:15 +0200 Original-Received: (qmail 9214 invoked by uid 1000); 15 Jul 2022 18:18:14 -0000 Content-Disposition: inline In-Reply-To: <83tu7isz4w.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=ham 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:292197 Archived-At: Hello, everybody. I know that there are technical issues in the code still to be thrashed out, but the new backtrace facility needs documentation. I've written some and a proposed patch (for debugging.texi and NEWS) is below. I've come to see that `backtrace-on-redisplay-lisp-error', although accurate, is too much of a mouthful, and I think it needs shortening. Would anybody object to me just calling this variable `debug-redisplay'? Also, I think that writing the backtrace into *Backtrace* is a bad idea, now. Users expect such a buffer to have active facilities, whereas the new backtrace is just a dead dump. Is there any objection to me instead calling the buffer something like "*Redisplay-trace*"? diff --git a/doc/lispref/debugging.texi b/doc/lispref/debugging.texi index 058c931954..3f9c9fea50 100644 --- a/doc/lispref/debugging.texi +++ b/doc/lispref/debugging.texi @@ -77,6 +77,7 @@ Debugger @menu * Error Debugging:: Entering the debugger when an error happens. +* Debugging Redisplay:: Getting backtraces from redisplay hook errors. * Infinite Loops:: Stopping and debugging a program that doesn't exit. * Function Debugging:: Entering it when a certain function is called. * Variable Debugging:: Entering it when a variable is modified. @@ -105,6 +106,10 @@ Error Debugging (The command @code{toggle-debug-on-error} provides an easy way to do this.) +Note that, for technical reasons, you cannot use the facilities +defined in this subsection to debug errors in hooks the redisplay code +has invoked. @xref{Debugging Redisplay} for help with these. + @defopt debug-on-error This variable determines whether the debugger is called when an error is signaled and not handled. If @code{debug-on-error} is @code{t}, @@ -213,6 +218,52 @@ Error Debugging bypasses the @code{condition-case} which normally catches errors in the init file. +@node Debugging Redisplay +@subsection Debugging Redisplay Hooks +@cindex redisplay hooks +@cindex debugging redisplay hooks + +When a Lisp error occurs in a hook function which redisplay has +invoked, you cannot use Emacs's usual debugging mechanisms, for +technical reasons. This subsection describes how to get a backtrace +from such an error, information which should be helpful in debugging +it. + +Note that if you have had such an error, the error handling will +likely have removed the function causing it from its hook. You will +thus need to reinitialize that hook somehow, perhaps with +@code{add-hook}, to be able to replay the bug. + +The hooks which these directions apply to are the following: +@enumerate +@item +@code{fontification-functions} (@pxref{Auto Faces}). +@item +@code{set-message-function} (@pxref{Displaying Messages}). +@item +@code{clear-message-function} (@pxref{Displaying Messages}). +@item +@code{pre-redisplay-function} (@pxref{Forcing Redisplay}). +@item +@code{pre-redisplay-functions} (@pxref{Forcing Redisplay}). +@item +@code{menu-bar-update-hook} (@pxref{Menu Bar}). +@item +@code{window-scroll-functions} (@pxref{Window Hooks}). +@end enumerate + +To generate a backtrace in these circumstances, set the variable +@code{backtrace-on-redisplay-lisp-error} to non-@code{nil}. When the +error occurs, Emacs will dump the backtrace to the buffer +@file{*Backtrace*}. This buffer is not automatically displayed in a +window; you will need to display it yourself, with a command such as +@code{switch-to-buffer-other-frame} (@key{C-x 5 b}). + +@defvar backtrace-on-redisplay-lisp-error +Set this variable to non-@code{nil} to enable the generation of a +backtrace when errors occur in any of the above hooks. +@end defvar + @node Infinite Loops @subsection Debugging Infinite Loops @cindex infinite loops diff --git a/etc/NEWS b/etc/NEWS index c2900b0bc4..0196d55306 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1227,6 +1227,13 @@ When invoked with a non-zero prefix argument, as in 'C-u C-x C-e', this command will pop up a new buffer and show the full pretty-printed value there. ++++ +*** It is now possible to generate a backtrace from errors in redisplay +hooks. To do this, set the new variable +'backtrace-on-redisplay-lisp-error' to a non-nil value. The backtrace +will be written to buffer *Backtrace*, but this buffer will not be +automatically displayed in a window. + ** Compile +++ -- Alan Mackenzie (Nuremberg, Germany).