Subject: bug#8789: 23.3; debug backtrace buffer changes window on step-through

From: martin rudalics <[email-masked]>
Date: Fri, 24 Feb 2012 19:42:59 +0100

> At first, some general things:
 >
 >  (1) If the user starts the debugger, do we really want that the
 >      Backtrace buffer pops up in some other frame only because it was
 >      displayed there in some window before?
 >
 >  (2) A problem with this approach: if the Backtrace buffer was already
 >      visible in several windows, it still hops around, because the
 >      window `display-buffer-in-window-previously-showing-it' returns is
 >      not unique.
 >
 >
 > Now to my tests in detail:
 >
 >  - When I start debugging with a 3-windowed frame, and this is the first
 >    time at all that I use the debugger at all, even then, the debugger
 >    hops around.  This has to do with (1), but I don't know why it hops
 >    the first time.

I finally managed to look into this issue and it's non-trivial for two
reasons:

(A) `debug' wraps all interesting actions in a `save-window-excursion'.
     Since `set-window-configuration' does not use `set-window-buffer' to
     restore the old buffer, it does not call `record-window-buffer'
     either.  This means that *Backtrace*, when displayed by `debug'
     only, never ends up on the previous buffers list of any window that
     shows it.  This explains why the debugger "hops the first time".

(B) When the debugger buffer has not existed before calling `debug', the
     line (kill-buffer debugger-buffer) will kill it and remove it from
     the previous buffers lists of all windows (this is needed to avoid
     that these lists get arbitrarily large).  In this case there's no
     way to find a window where the buffer was shown previously.

(A) can be fixed easily by having `set-window-configuration' record the
buffer it's going to replace by the saved one.  So if we avoid killing
the buffer in (B) all issues cited above can be resolved.

 > But it gets much worse.  Do the following:
 >
 >  - emacs -Q
 >  - require 'debug, and load your patch
 >  - M-x debug-on-entry dired RET
 >  - C-x d RET
 >  - hit d three times -> Emacs crashs!
 >
 > This is reproducible here.  I use GNU Emacs 24.0.93.1
 > (i486-pc-linux-gnu, GTK+ Version 3.2.3)\n of 2012-02-16 on zelenka,
 > modified by Debian, btw.
 >
 >
 > This is all a horror to debug.  Tell me if I can help with something.

This must be a different issue.  Please get a backtrace of this ASAP.

Thanks, martin