Subject: bug#75632: 31.0.50; igc: Crash report

From: Eli Zaretskii <[email-masked]>
Date: Fri, 17 Jan 2025 22:31:48 +0200

> Resent-To: [email-masked]
> Cc: Gerd Möllmann <[email-masked]>,
>  [email-masked]
> Date: Fri, 17 Jan 2025 15:26:10 +0000
> From:  Pip Cet via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> "Ihor Radchenko" <[email-masked]> writes:
> 
> > Pip Cet <[email-masked]> writes:
> >
> >> "Ihor Radchenko" <[email-masked]> writes:
> >>
> >>> Just got the following:
> >>
> >> Yes, that's the signal handling bug.  I'm not entirely sure why we
> >> removed the fix that was in scratch/igc, but we did, so we need another
> >> one.
> >> ...
> >> to handle_user_signal, which will silently ignore SIGUSR* received while
> >> MPS may have locked the arena.
> >
> > I indeed sent SIGUSR2 just before I saw the crash.
> 
> It'd be nice if that simply worked.  I think debugging with SIGUSR* is
> important, so I've pushed a fix (and I'm closing this bug; if further
> discussion is needed, feel free to revert and reopen).

This breaks the MS-Windows build: temacs crashes as below:

  Loading loadup.el (source)...
  Dump mode: pbootstrap
  Using load-path (d:/gnu/git/emacs/feature/lisp d:/gnu/git/emacs/feature/lisp/emacs-lisp d:/gnu/git/emacs/feature/lisp/progmodes d:/gnu/git/emacs/feature/lisp/language d:/gnu/git/emacs/feature/lisp/international d:/gnu/git/emacs/feature/lisp/textmodes d:/gnu/git/emacs/feature/lisp/vc)
  Loading emacs-lisp/debug-early...
  Loading emacs-lisp/byte-run...
  Loading emacs-lisp/backquote...
  Loading subr...
  Loading keymap...
  Loading version...
  Loading widget...
  Loading custom...
  Loading emacs-lisp/map-ynp...
  Loading international/mule...
  Loading international/mule-conf...
  Loading env...
  Loading format...
  Loading bindings...
  Loading window...
  Loading files...
  Loading emacs-lisp/macroexp...
  Loading cus-face...
  Loading faces...
  Loading loaddefs...
  Loading d:/gnu/git/emacs/feature/lisp/theme-loaddefs.el (source)...
  Loading button...
  Loading emacs-lisp/cl-preloaded...
  Loading emacs-lisp/oclosure...
  Loading obarray...
  Loading abbrev...
  Loading help...
  Loading jka-cmpr-hook...
  Loading epa-hook...
  Loading international/mule-cmds...
  Loading case-table...
  Loading d:/gnu/git/emacs/feature/lisp/international/charprop.el (source)...
  Loading international/characters...
  Loading international/charscript...
  Loading international/emoji-zwj...
  Loading composite...
  Loading language/chinese...
  Loading language/cyrillic...
  Loading language/indian...
  Loading language/sinhala...
  Loading language/english...
  Loading language/ethiopic...
  Loading language/european...
  Loading language/czech...
  Loading language/slovak...
  Loading language/romanian...
  Loading language/greek...
  Loading language/hebrew...
  Loading international/cp51932...
  Loading international/eucjp-ms...
  Loading language/japanese...
  Loading language/korean...
  Loading language/lao...
  Loading language/tai-viet...
  Loading language/thai...
  Loading language/tibetan...
  Loading language/vietnamese...
  Loading language/misc-lang...
  Loading language/utf-8-lang...
  Loading language/georgian...
  Loading language/khmer...
  Loading language/burmese...
  Loading language/cham...
  Loading language/philippine...
  Loading language/indonesian...
  Loading indent...
  Loading emacs-lisp/cl-generic...
  Loading simple...
  Loading emacs-lisp/seq...
  Loading emacs-lisp/nadvice...
  Loading minibuffer...
  Loading frame...
  Loading startup...
  Loading term/tty-colors...
  Loading font-core...
  Loading emacs-lisp/syntax...
  Loading font-lock...
  Loading jit-lock...
  Loading mouse...
  Loading scroll-bar...
  Loading select...
  Loading emacs-lisp/timer...
  Loading emacs-lisp/easymenu...
  Loading isearch...
  Loading rfn-eshadow...
  Loading menu-bar...
  Loading tab-bar...
  Loading emacs-lisp/lisp...
  Loading textmodes/page...
  Loading register...
  Loading textmodes/paragraphs...
  Loading progmodes/prog-mode...
  Loading emacs-lisp/lisp-mode...
  Loading textmodes/text-mode...
  Loading textmodes/fill...
  Loading newcomment...
  Loading replace...
  Loading emacs-lisp/tabulated-list...
  Loading buff-menu...
  Loading fringe...
  Loading emacs-lisp/regexp-opt...
  Loading image...
  Loading international/fontset...
  Loading dnd...
  Loading tool-bar...
  Loading term/common-win...
  Loading w32-vars...
  Loading term/w32-win...
  Loading disp-table...
  Loading w32-fns...
  Loading ls-lisp...
  Loading dos-w32...
  Loading touch-screen...
  Loading mwheel...
  Loading progmodes/elisp-mode...
  Loading emacs-lisp/float-sup...
  Loading vc/vc-hooks...
  Loading vc/ediff-hook...
  Loading uniquify...
  Loading electric...
  Loading paren...
  Loading emacs-lisp/shorthands...
  Loading emacs-lisp/eldoc...
  Loading emacs-lisp/cconv...
  Loading cus-start...
  Loading tooltip...
  Loading international/iso-transl...
  Loading emacs-lisp/rmc...
  Loading d:/gnu/git/emacs/feature/lisp/leim/leim-list.el (source)...
  Finding pointers to doc strings...
  Finding pointers to doc strings...done
  Dumping under the name bootstrap-emacs.pdmp
  Dumping fingerprint: 18388262a2082a9a0cae7f9f7b2f954b596ec03f060bf8e73cbd63063b9a1d95

  pdumper.c:939: Emacs fatal error: assertion failed: should_end >= end

  Thread 1 hit Breakpoint 1, terminate_due_to_signal (sig=sig@entry=22,
      backtrace_limit=backtrace_limit@entry=2147483647) at emacs.c:432
  432     {
  (gdb) bt
  #0  terminate_due_to_signal (sig=sig@entry=22,
      backtrace_limit=backtrace_limit@entry=2147483647) at emacs.c:432
  #1  0x00f836f4 in die (
      msg=msg@entry=0x15369e9 <gdb_make_enums_visible+1745> "should_end >= end",
      file=file@entry=0x1536431 <gdb_make_enums_visible+281> "pdumper.c",
      line=line@entry=939) at alloc.c:8388
  #2  0x00f88e8a in dump_igc_finish_obj (ctx=ctx@entry=0xbfebd8) at pdumper.c:939
  #3  0x00f8caca in dump_object_finish (sz=40, out=0xbfe990, ctx=0xbfebd8)
      at pdumper.c:1003
  #4  dump_subr (subr=0x11611e0 <Swatch_debug_on_event.43963>, ctx=0xbfebd8)
      at pdumper.c:3093
  #5  dump_vectorlike (offset=6440296, lv=XIL(0x11611e5), ctx=0xbfebd8)
      at pdumper.c:3187
  #6  dump_object (ctx=ctx@entry=0xbfebd8, object=XIL(0x11611e5))
      at pdumper.c:3318
  #7  0x00f8e7f4 in dump_drain_copied_objects (ctx=0xbfebd8) at pdumper.c:3539
  #8  Fdump_emacs_portable (filename=<optimized out>,
      track_referrers=<optimized out>) at pdumper.c:4524
  #9  0x00fb3ecc in eval_sub (form=XIL(0xc35cedb)) at eval.c:2623
  #10 0x00fb3cd9 in eval_sub (form=XIL(0xc35ce1b)) at eval.c:2571
  #11 0x00fb514a in Fprogn (body=XIL(0xc35d0e3)) at eval.c:452
  #12 Flet (args=<optimized out>) at eval.c:1122
  #13 0x00fb3cd9 in eval_sub (form=XIL(0xc35cd33)) at eval.c:2571
  #14 0x00fb58cc in Funwind_protect (args=XIL(0xc35d0f3)) at lisp.h:1563
  #15 0x00fb3cd9 in eval_sub (form=XIL(0xc35cd23)) at eval.c:2571
  #16 0x00fb514a in Fprogn (body=XIL(0)) at eval.c:452
  #17 Flet (args=<optimized out>) at eval.c:1122
  #18 0x00fb3cd9 in eval_sub (form=XIL(0xc35ccf3)) at eval.c:2571
  #19 0x00fb514a in Fprogn (body=XIL(0xc35dbb3)) at eval.c:452
  #20 Flet (args=<optimized out>) at eval.c:1122
  #21 0x00fb3cd9 in eval_sub (form=XIL(0xc35c793)) at eval.c:2571
  #22 0x00fb3cd9 in eval_sub (form=XIL(0xc35c773)) at eval.c:2571
  #23 0x00fb48b4 in Fprogn (body=XIL(0)) at eval.c:452
  #24 Fif (args=XIL(0xc35c32b)) at eval.c:408
  #25 0x00fb3cd9 in eval_sub (form=form@entry=XIL(0xc35c25b)) at eval.c:2571
  #26 0x00ff023c in readevalloop (readcharfun=readcharfun@entry=XIL(0x6120),
      infile0=infile0@entry=0xbff638,
      sourcename=sourcename@entry=XIL(0xb04a364),
      printflag=printflag@entry=false, unibyte=unibyte@entry=XIL(0),
      readfun=readfun@entry=XIL(0), start=start@entry=XIL(0),
      end=<optimized out>, end@entry=XIL(0)) at lread.c:2540
  #27 0x00ff0cd9 in Fload (file=XIL(0xb04a004), noerror=XIL(0),
      nomessage=XIL(0), nosuffix=XIL(0), must_suffix=<optimized out>)
      at lisp.h:1229
  #28 0x00fb3e69 in eval_sub (form=form@entry=XIL(0xb04a02b)) at eval.c:2634
  #29 0x00fb5e32 in Feval (form=XIL(0xb04a02b), lexical=lexical@entry=XIL(0x20))
      at eval.c:2479
  #30 0x00f0ef8b in top_level_2 () at lisp.h:1229
  #31 0x00fae15b in internal_condition_case (
      bfun=bfun@entry=0xf0ef2c <top_level_2>, handlers=handlers@entry=XIL(0x60),
      hfun=hfun@entry=0xf18d54 <cmd_error>) at eval.c:1627
  #32 0x00f0f6b8 in top_level_1 (ignore=XIL(0)) at lisp.h:1229
  #33 0x00fae077 in internal_catch (tag=tag@entry=XIL(0xc560),
      func=func@entry=0xf0f68c <top_level_1>, arg=arg@entry=XIL(0))
      at eval.c:1306
  #34 0x00f0ed3f in command_loop () at lisp.h:1229
  #35 0x00f188fa in recursive_edit_1 () at keyboard.c:760
  #36 0x00f18c01 in Frecursive_edit () at keyboard.c:843
  #37 0x0115fc05 in main (argc=<optimized out>, argv=<optimized out>)
      at emacs.c:2658

  Lisp Backtrace:
  "dump-emacs-portable" (0xbfed90)
  "if" (0xbfee1c)
  "let" (0xbfef1c)
  "unwind-protect" (0xbfefcc)
  "let" (0xbff0bc)
  "let" (0xbff1ac)
  "if" (0xbff23c)
  "if" (0xbff2ec)
  "load" (0xbff8e0)
  (gdb) up
  #1  0x00f836f4 in die (
      msg=msg@entry=0x15369e9 <gdb_make_enums_visible+1745> "should_end >= end",
      file=file@entry=0x1536431 <gdb_make_enums_visible+281> "pdumper.c",
      line=line@entry=939) at alloc.c:8388
  8388      terminate_due_to_signal (SIGABRT, INT_MAX);
  (gdb)
  #2  0x00f88e8a in dump_igc_finish_obj (ctx=ctx@entry=0xbfebd8) at pdumper.c:939
  939           eassert (should_end >= end);
  (gdb) p should_end
  $1 = <optimized out>
  (gdb) p end
  $2 = 0x1b5c35b0 ""
  (gdb) p igc_dump_finish_obj (ctx->igc_obj_dumped, ctx->igc_type, base, end)
  value has been optimized out
  (gdb) p base
  $3 = <optimized out>
  p igc_dump_finish_obj (ctx->igc_obj_dumped, ctx->igc_type, (char *) ctx->buf + ctx->igc_base_offset, end)
  $4 = 0x1b5c3588 ""

The following patch seems to fix that, but I'm not sure it's the
correct fix.  Can you explain why we need to add-variable-watcher for
this in init_keyboard, in particular in temacs?  since init_keyboard
is called both in temacs and in emacs, it sounds like the code, when
called in emacs, will try to free memory that was malloced in temacs,
is that right?

diff --git a/src/keyboard.c b/src/keyboard.c
index 82505e7..a5d85e9 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -12817,6 +12817,7 @@ init_keyboard (void)
 #endif
 
 #ifdef HAVE_MPS
+  if (initialized)
   {
     Lisp_Object watcher;