unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 48337@debbugs.gnu.org, alex.bennee@linaro.org, acm@muc.de
Subject: bug#48337: Fwd: 28.0.50; Emacs crashing randomly (possibly minibuffer activity related)
Date: Wed, 12 May 2021 18:54:05 +0000	[thread overview]
Message-ID: <YJwkTQGPy/y1i+NS@ACM> (raw)
In-Reply-To: <83cztx3v04.fsf@gnu.org>

Hello, Eli.

On Tue, May 11, 2021 at 22:55:55 +0300, Eli Zaretskii wrote:
> > Date: Tue, 11 May 2021 19:45:23 +0000
> > Cc: Alex Bennée <alex.bennee@linaro.org>,
> >   48337@debbugs.gnu.org
> > From: Alan Mackenzie <acm@muc.de>

> > > Alan, the code in nth_minibuffer and its callers is unsafe.  First,
> > > Fnthcdr can return nil, and then XCAR of that in nth_minibuffer
> > > crashes.  I fixed that now on the master branch, ....

> > That Fnthcdr call "can't possibly" return nil, unless there's a bug
> > somewhere.

> Then the commentary of nth_minibuffer is outdated and should be
> updated: it claims that returning nil is part of the contract.

I will clean up this unclean coding.

> > >   Fset_buffer (nth_minibuffer (minibuf_level));

> > This, I think, can be justified - if read_minibuf_unwind can't find
> > the minibuffer it's unwinding, we've got a serious problem and ought
> > to abort Emacs ASAP.  Should that, perhaps, be an explicit assert?

> If you want to abort, assertions is not TRT, as it will not be
> compiled in an optimized build.  Call emacs_abort instead.

Thanks for the tip!

I now understand the immediate cause of the bug completely.  Partly this
is due to me seeing better backtrace information from a subsequent post
from Alex.  This backtrace contains:

#18 0x000055e3c57335da in Frun_hooks (nargs=1, args=0x7ffe48045368) at eval.c:2701
......
......
#26 0x000055e3c56a82b0 in read_minibuf (map=..., initial=..., prompt=..., expflag=false, histvar=..., histpos=..., defalt=..., allow_props=false, inherit_input_method=false) at minibuf.c:683

..  The minibuf.c:683 identifies the failing point in read_minibuf as a
call to record-window-buffer.  r-w-b ends by calling the hook
buffer-list-update-hook.

At the time of calling record-window-buffer, minibuf_level has been
incremented to 2, but  *Minibuf-2* has not yet been created and added to
minibuf.c's internal list of minibuffers.  This is an inconsistent state.

Something on buffer-list-update-hook calls active-minibuffer-window, and
because of the inconsistent state, this crashes.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

The deeper cause of the bug is that calling buffer-list-update-hook
simply doesn't belong in record-window-buffer.  That hook should be
called when the buffer list changes, not when a window's current buffer
gets "recorded".

So, as the main fix, I propose moving the call of buffer-list-update-hook
to (some of) the places where record-window-buffer gets called, those
places where the buffer list changes.  There are exactly two such places,
both in window.c.  This will prevent the chain of events in read_minibuf
outlined above.

Also, I intend to prevent the indicated inconsistency in the minibuffer
list by creating  *Minibuf-2* earlier, immediately after incrementing
minibuf_level to 2.

And, as promised, I will tidy up the untidy and unsafe coding.

Does anybody have any comments before I start hacking this?

-- 
Alan Mackenzie (Nuremberg, Germany).





  reply	other threads:[~2021-05-12 18:54 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87tunasd2u.fsf@linaro.org>
2021-05-10 19:30 ` bug#48337: Fwd: 28.0.50; Emacs crashing randomly (possibly minibuffer activity related) Alex Bennée
2021-05-10 19:34   ` bug#48337: Alex Bennée
2021-05-11  2:24   ` bug#48337: Fwd: 28.0.50; Emacs crashing randomly (possibly minibuffer activity related) Eli Zaretskii
2021-05-11  6:51     ` Alex Bennée
2021-05-11  8:23       ` Alex Bennée
2021-05-11  8:54         ` Alex Bennée
2021-05-11 12:21       ` Eli Zaretskii
2021-05-11 12:54         ` Alex Bennée
2021-05-11 13:42           ` Eli Zaretskii
2021-05-11 13:47             ` Eli Zaretskii
2021-05-11 19:45             ` Alan Mackenzie
2021-05-11 19:55               ` Eli Zaretskii
2021-05-12 18:54                 ` Alan Mackenzie [this message]
2021-05-13  7:54                   ` martin rudalics
2021-05-13  9:52                     ` Alan Mackenzie
2021-05-13 11:54                       ` Alan Mackenzie
2021-05-13 12:09                         ` Alan Mackenzie
2021-05-14 15:20                     ` Gregory Heytings
2021-05-14 16:05                       ` Eli Zaretskii
2021-05-14 17:31                         ` Gregory Heytings
2021-05-14 18:19                           ` Eli Zaretskii
2021-05-15  9:45                             ` Gregory Heytings
2021-05-11 20:14       ` Alan Mackenzie
2021-05-11 22:07         ` Alex Bennée
2021-05-14 16:31           ` Alan Mackenzie
2021-05-14 16:52             ` Alex Bennée
2021-05-14 18:40               ` Alan Mackenzie
2021-05-14 22:35                 ` Alex Bennée
2021-05-15 12:00                   ` Alan Mackenzie
2021-05-16 14:24                     ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YJwkTQGPy/y1i+NS@ACM \
    --to=acm@muc.de \
    --cc=48337@debbugs.gnu.org \
    --cc=alex.bennee@linaro.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).