Subject: bug#45541: 28.0.50; Frequent crashes on ARM macOS

From: Philipp Stephani <[email-masked]>
Date: Wed, 30 Dec 2020 15:42:24 +0100

Am Mi., 30. Dez. 2020 um 15:05 Uhr schrieb Alan Third <[email-masked]>:
>
> On Wed, Dec 30, 2020 at 02:01:18PM +0100, Philipp Stephani wrote:
> > Am Mi., 30. Dez. 2020 um 01:10 Uhr schrieb Alan Third <[email-masked]>:
> > >
> > > On Tue, Dec 29, 2020 at 11:32:43PM +0100, Philipp wrote:
> > > >
> > > > With an Emacs built from the emacs-27 branch I get frequent crashes on
> > > > ARM64 macOS (Big Sur).  I haven't managed to produce an Elisp stacktrace
> > > > yet, but here's the crash report:
> > > <snip>
> > > > Looks like a crash in ns_mouse_position.
> > >
> > > Can you check that the build includes this?
> > >
> > > 6aa9fe3e1b4052b2acde86404a90e35893ebfa00?
> > > Fix crash in ns_mouse_position (bug#44313)
> >
> > Yes, according to "git branch --contains" the commit is present.  The
> > exception report makes me think that NSApp is null or invalid, but how
> > should that be possible?
>
> I have no idea... What's happening when the crash occurs? I take it
> the mouse is being moved, but are frames opening and closing or
> anything?

I'm now able to reproduce this consistently. It happens when a tooltip
appears and you hover over that tooltip (try M-x locate and move the
mouse around).
The crash is in the line
  if (f && FRAME_NS_P (f))
in nsterm.m in ns_mouse_position, so apparently "f" is not NULL, but
also not valid.
Interestingly I can only reproduce the issue in optimized builds.
The LLDB backtrace is:
* thread #1, queue = 'com.apple.main-thread', stop reason =
EXC_BAD_ACCESS (code=1, address=0x38d0)
    frame #0: 0x00000001001d87fc
emacs`ns_mouse_position(fp=<unavailable>, insist=<unavailable>,
bar_window=<unavailable>, part=<unavailable>, x=<unavailable>,
y=<unavailable>, time=<unavailable>) at nsterm.m:2538:12 [opt]
   2535       && FRAME_LIVE_P (dpyinfo->last_mouse_frame))
   2536     f = dpyinfo->last_mouse_frame;
   2537
-> 2538   if (f && FRAME_NS_P (f))
   2539     {
   2540       view = FRAME_NS_VIEW (f);
   2541
Target 0: (emacs) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason =
EXC_BAD_ACCESS (code=1, address=0x38d0)
  * frame #0: 0x00000001001d87fc
emacs`ns_mouse_position(fp=<unavailable>, insist=<unavailable>,
bar_window=<unavailable>, part=<unavailable>, x=<unavailable>,
y=<unavailable>, time=<unavailable>) at nsterm.m:2538:12 [opt]
    frame #1: 0x00000001000112c8 emacs`Fmouse_pixel_position at
frame.c:2498:7 [opt]
    frame #2: 0x000000010013fe48
emacs`funcall_subr(subr=0x0000000100251778, numargs=<unavailable>,
args=<unavailable>) at eval.c:2866:19 [opt]
    frame #3: 0x000000010013f420 emacs`Ffuncall(nargs=<unavailable>,
args=<unavailable>) at eval.c:2795:11 [opt]
    frame #4: 0x0000000100180208
emacs`exec_byte_code(bytestr=<unavailable>, vector=<unavailable>,
maxdepth=<unavailable>, args_template=<unavailable>,
nargs=4611686018813263872, args=<unavailable>) at bytecode.c:633:12
[opt]
    frame #5: 0x00000001001403c0
emacs`funcall_lambda(fun=<unavailable>, nargs=<unavailable>,
arg_vector=<unavailable>) at eval.c:2990:11 [opt] [artificial]
    frame #6: 0x000000010013f3a8 emacs`Ffuncall(nargs=<unavailable>,
args=<unavailable>) at eval.c:0 [opt]
    frame #7: 0x000000010013fb0c emacs`call1(fn=0x00000000000094b0,
arg1=0x00000001160244d4) at eval.c:2655:10 [opt]
    frame #8: 0x00000001000c0c1c
emacs`show_help_echo(help=0x00000001160244d4, window=<unavailable>,
object=<unavailable>, pos=<unavailable>) at keyboard.c:2093:14 [opt]
    frame #9: 0x00000001000c130c
emacs`read_char(commandflag=<unavailable>, map=<unavailable>,
prev_event=0x0000000000000000, used_mouse_menu=<unavailable>,
end_time=<unavailable>) at keyboard.c:3117:7 [opt]
    frame #10: 0x00000001000bf220
emacs`read_key_sequence(keybuf=0x000000016fdff1e0,
prompt=0x0000000000000000, dont_downcase_last=false,
can_return_switch_frame=true, fix_current_buffer=true,
prevent_redisplay=<unavailable>) at keyboard.c:9554:12 [opt]
    frame #11: 0x00000001000bdcd0 emacs`command_loop_1 at
keyboard.c:1350:15 [opt]
    frame #12: 0x000000010013da6c
emacs`internal_condition_case(bfun=(emacs`command_loop_1 at
keyboard.c:1236), handlers=0x0000000000000090, hfun=(emacs`cmd_error
at keyboard.c:919)) at eval.c:1356:25 [opt]
    frame #13: 0x00000001000cc6ac
emacs`command_loop_2(ignore=0x0000000000000000) at keyboard.c:1091:11
[opt]
    frame #14: 0x000000010013d354
emacs`internal_catch(tag=<unavailable>, func=(emacs`command_loop_2 at
keyboard.c:1087), arg=0x0000000000000000) at eval.c:1117:25 [opt]
    frame #15: 0x00000001001fe690 emacs`recursive_edit_1.cold.1 at
keyboard.c:1070:2 [opt]
    frame #16: 0x00000001000bcdc0 emacs`recursive_edit_1 [inlined]
command_loop at keyboard.c:1067:5 [opt]
    frame #17: 0x00000001000bcdbc emacs`recursive_edit_1 at keyboard.c:714 [opt]
    frame #18: 0x00000001000bcf68 emacs`Frecursive_edit at
keyboard.c:786:3 [opt]
    frame #19: 0x00000001000bc3b0 emacs`main(argc=<unavailable>,
argv=<unavailable>) at emacs.c:2066:3 [opt]
    frame #20: 0x000000018d25cf34 libdyld.dylib`start + 4