Subject: Re: bug#72692: Emacs 31.05 (40eecd594ac) get SIGSEGV on Linux (Linux 6.6.45 Kde Wayland)

From: Pip Cet <[email-masked]>
Date: Mon, 19 Aug 2024 16:34:59 +0000

"Eli Zaretskii" <[email-masked]> writes:

>> Date: Mon, 19 Aug 2024 15:03:13 +0000
>> From: Pip Cet <[email-masked]>
>> Cc: [email-masked], [email-masked]
>>
>> I'll check whether setting f->face_change = true in the relevant places
>> is enough to avoid the bug...
>
> Thanks, but I'd also like to see the callers which call
> free_realized_face in a way that causes the latter to call
> free_face_fontset.  That's why I asked for backtraces from those
> calls, but I don't think you sent such backtraces.  What you sent was

Just for the record, you asked:

> So can you show a backtrace from the call to free_realized_faces
> (supposedly called by realize_basic_faces?) which causes these
> printfs:
> > fontset 103 used for face 0x117cca0
> > fontset 103 used for face 0x2a7a3c0
> > fontset 103 used for face 0x117cca0
> > fontset 103 used for face 0x2a62860

... which I misunderstood.  Sorry.

Is this what you want?

Thread 1 "emacs" hit Breakpoint 3, free_realized_face (f=0x11d1cc8, face=0x11e22b0) at xfaces.c:4612
4612				  fprintf (stderr, "Freeing fontset %d that's still in use by %p (ASCII face %p==%p)!\n", face->fontset,
(gdb) p face->fontset
$1 = 83
(gdb) bt
#0  free_realized_face (f=0x11d1cc8, face=0x11e22b0) at xfaces.c:4612
#1  0x000000000055fe5d in realize_face (cache=0x12731e0, attrs=0x7fffffffb5f0, former_face_id=0) at xfaces.c:6117
#2  0x000000000055faf7 in realize_default_face (f=0x11d1cc8) at xfaces.c:6030
#3  0x000000000055f023 in realize_basic_faces (f=0x11d1cc8) at xfaces.c:5882
#4  0x000000000055084f in recompute_basic_faces (f=0x11d1cc8) at xfaces.c:737
#5  0x0000000000445160 in gui_set_alpha_background (f=0x11d1cc8, arg=XIL(0x7ffff33a80c7), oldval=XIL(0x7ffff33a80c7)) at frame.c:5237
#6  0x00000000005a511e in x_set_alpha_background (f=0x11d1cc8, arg=XIL(0x7ffff33a80c7), oldval=XIL(0x7ffff33a80c7)) at xfns.c:742
#7  0x0000000000442194 in gui_set_frame_parameters_1 (f=0x11d1cc8, alist=XIL(0), default_parameter=false) at frame.c:4400
#8  0x0000000000442d6f in gui_set_frame_parameters (f=0x11d1cc8, alist=XIL(0x7ffff33a3223)) at frame.c:4560
#9  0x000000000044042b in Fmodify_frame_parameters (frame=XIL(0), alist=XIL(0x7ffff33a3223)) at frame.c:3549
#10 0x00000000006c043c in funcall_subr (subr=0xe8d920 <Smodify_frame_parameters>, numargs=2, args=0x7fffe41ff2f8) at eval.c:3140
#11 0x000000000071b3ab in exec_byte_code (fun=XIL(0x7ffff249ab35), args_template=771, nargs=3, args=0x7fffffffc038) at bytecode.c:813
#12 0x00000000006c0a6c in funcall_lambda (fun=XIL(0x7ffff249ab35), nargs=3, arg_vector=0x7fffffffc020) at eval.c:3229
#13 0x00000000006c0903 in apply_lambda (fun=XIL(0x7ffff249ab35), args=XIL(0x7ffff336a2d3), count=...) at eval.c:3192
#14 0x00000000006bee34 in eval_sub (form=XIL(0x7ffff336a2c3)) at eval.c:2622
#15 0x00000000006b98f3 in Fprogn (body=XIL(0x7ffff336a353)) at eval.c:430
#16 0x00000000006b9923 in prog_ignore (body=XIL(0x7ffff336a2b3)) at eval.c:441
#17 0x00000000006bb4ee in Fwhile (args=XIL(0x7ffff336a1f3)) at eval.c:1121
#18 0x00000000006be8bb in eval_sub (form=XIL(0x7ffff336a1e3)) at eval.c:2526
#19 0x00000000006fff09 in readevalloop_eager_expand_eval (val=XIL(0x7ffff336a1e3), macroexpand=XIL(0xb370)) at lread.c:2355
#20 0x0000000000700773 in readevalloop
    (readcharfun=XIL(0x143d9a5), infile0=0x0, sourcename=XIL(0x127a2f4), printflag=false, unibyte=XIL(0), readfun=XIL(0), start=XIL(0), end=XIL(0))
    at lread.c:2537
#21 0x0000000000700ac2 in Feval_buffer (buffer=XIL(0x143d9a5), printflag=XIL(0), filename=XIL(0x127a2f4), unibyte=XIL(0), do_allow_print=XIL(0x30))
    at lread.c:2612
#22 0x00000000006c04f3 in funcall_subr (subr=0xe9f0e0 <Seval_buffer>, numargs=5, args=0x7fffe41ff290) at eval.c:3146
#23 0x000000000071b3ab in exec_byte_code (fun=XIL(0x7ffff25bab55), args_template=257, nargs=1, args=0x7fffe41ff298) at bytecode.c:813
#24 0x00000000006c0a6c in funcall_lambda (fun=XIL(0x7ffff280f18d), nargs=4, arg_vector=0x7fffffffcdb8) at eval.c:3229
#25 0x00000000006bfe66 in funcall_general (fun=XIL(0x7ffff280f18d), numargs=4, args=0x7fffffffcdb8) at eval.c:3021
#26 0x00000000006c0115 in Ffuncall (nargs=5, args=0x7fffffffcdb0) at eval.c:3070
#27 0x00000000006fe3fa in Fload (file=XIL(0x127a614), noerror=XIL(0), nomessage=XIL(0x30), nosuffix=XIL(0), must_suffix=XIL(0)) at lread.c:1615
#28 0x00000000006c04f3 in funcall_subr (subr=0xe9f060 <Sload>, numargs=3, args=0x7fffe41ff1b0) at eval.c:3146
#29 0x000000000071b3ab in exec_byte_code (fun=XIL(0x7ffff2a036c5), args_template=769, nargs=3, args=0x7fffe41ff4a0) at bytecode.c:813
#30 0x00000000006c0a6c in funcall_lambda (fun=XIL(0x7ffff2a529cd), nargs=0, arg_vector=0x7fffffffd590) at eval.c:3229
#31 0x00000000006c0903 in apply_lambda (fun=XIL(0x7ffff2a529cd), args=XIL(0), count=...) at eval.c:3192
#32 0x00000000006bee34 in eval_sub (form=XIL(0x7ffff2c113fb)) at eval.c:2622
#33 0x00000000006be367 in Feval (form=XIL(0x7ffff2c113fb), lexical=XIL(0x30)) at eval.c:2439
#34 0x00000000005e5392 in top_level_2 () at keyboard.c:1179
#35 0x00000000006bc3d6 in internal_condition_case (bfun=0x5e532b <top_level_2>, handlers=XIL(0x90), hfun=0x5e4c03 <cmd_error>) at eval.c:1598
#36 0x00000000005e53ed in top_level_1 (ignore=XIL(0)) at keyboard.c:1191
#37 0x00000000006bb89a in internal_catch (tag=XIL(0x12360), func=0x5e53ab <top_level_1>, arg=XIL(0)) at eval.c:1277
#38 0x00000000005e5275 in command_loop () at keyboard.c:1140
#39 0x00000000005e46dc in recursive_edit_1 () at keyboard.c:749
#40 0x00000000005e48ef in Frecursive_edit () at keyboard.c:832
#41 0x00000000005e05cf in main (argc=4, argv=0x7fffffffdb98) at emacs.c:2624

Lisp Backtrace:
"modify-frame-parameters" (0xe41ff2f8)
"set-frame-parameter" (0xffffc020)
"while" (0xffffc300)
"eval-buffer" (0xe41ff290)
"load-with-code-conversion" (0xffffcdb8)
"load" (0xe41ff1b0)
"command-line-1" (0xe41ff0b8)
"command-line" (0xe41ff040)
"normal-top-level" (0xffffd590)
(gdb) p face->ascii_face
$2 = (struct face *) 0x11e22b0

> a backtrace from realize_gui_face and another one from the abort.  The
> former is too early, the latter too late.  I'd like to see the code
> which causes the fontset to be freed in a way that avoids re-realizing
> all of the faces that use the fontset.  That's where the problem is,
> at least at my current level of understanding this issue.

Indeed, I can report that the bug doesn't seem to occur after this
simple change:

diff --git a/src/xfaces.c b/src/xfaces.c
index 684b6ccfac7..a4ac9c0787a 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -736,6 +736,7 @@ recompute_basic_faces (struct frame *f)
       clear_face_cache (false);
       if (!realize_basic_faces (f))
        emacs_abort ();
+      f->face_change = true;
     }
 }

So something like that (though moving the call down into
realize_basic_faces or even further would be good) would probably work
for the OP, and emacs-30?

Pip