switching font backends in .emacs.desktop causes crash

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

switching font backends in .emacs.desktop causes crash

Robert Pluim

Playing around with the various X font backend build options resulted
in me having a .emacs.desktop like so:

;; -*- mode: emacs-lisp; lexical-binding:t; coding: utf-8-emacs; -*-
;; --------------------------------------------------------------------------
;; Desktop File for Emacs
;; --------------------------------------------------------------------------
;; Created Fri Feb  8 09:02:42 2019
;; Desktop file format version 208
;; Emacs version 27.0.50

;; Global section:
(setq desktop-saved-frameset [frameset 1 (23645 14242 497425
32000) (desktop . "208") "rpluim@rpluim-ubuntu" nil
nil ((((minibuffer . t) (undecorated) (override-redirect) (font-backend x))))])

and .emacs:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(desktop-save-mode t)
)

I rebuilt with the XFT and X backends (default configuration), and
got:

    $ ./emacs
    Fatal error 11: Segmentation fault
    Backtrace:
    ./emacs(+0x1338ce)[0x5568bfc208ce]
    ./emacs(+0x119e4a)[0x5568bfc06e4a]
    ./emacs(+0x131c9e)[0x5568bfc1ec9e]
    ./emacs(+0x131f48)[0x5568bfc1ef48]
    ./emacs(+0x131fcc)[0x5568bfc1efcc]
    /lib/x86_64-linux-gnu/libpthread.so.0(+0x12890)[0x7ff5f243f890]
    /usr/lib/x86_64-linux-gnu/libXft.so.2(XftCharIndex+0xd)[0x7ff5f5c5568d]

Poking around with gdb, I see that the xftfont field of xftfont_info
is NULL, so I set a watchpoint:

    $ gdb emacs
    (gdb) l xftfont.c:320
    315  ASET (font_object, FONT_FILE_INDEX, filename);
    316  font = XFONT_OBJECT (font_object);
    317  font->pixel_size = size;
    318  font->driver = &xftfont_driver;
    319  font->encoding_charset = font->repertory_charset = -1;
    320
    321  xftfont_info = (struct font_info *) font;
    322  xftfont_info->display = display;
    323  xftfont_info->xftfont = xftfont;
    324  xftfont_info->x_display_id = FRAME_DISPLAY_INFO (f)->x_id;
    (gdb) b 324
    Breakpoint 3 at 0x204b47: file xftfont.c, line 324.
    (gdb) r
    Starting program: /home/rpluim/repos/emacs-real-master/src/emacs
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
    [New Thread 0x7fffe4a29700 (LWP 12037)]
    [New Thread 0x7fffdf41b700 (LWP 12039)]
    [New Thread 0x7fffdea0d700 (LWP 12040)]

    Thread 1 "emacs" hit Breakpoint 3, xftfont_open (f=0x55555646b2a0,
        entity=XIL(0x5555560a6975), pixel_size=27) at xftfont.c:324
    324  xftfont_info->x_display_id = FRAME_DISPLAY_INFO (f)->x_id;
    (gdb) watch -l xftfont_info->xftfont
    Hardware watchpoint 4: -location xftfont_info->xftfont
    (gdb) d 3
    (gdb) c
    Continuing.

    Thread 1 "emacs" hit Hardware watchpoint 4: -location xftfont_info->xftfont

    Old value = (XftFont *) 0x5555564738e0
    New value = (XftFont *) 0x0
    xftfont_close (font=0x5555560a6a60) at xftfont.c:464
    464 }
    (gdb) bt
    #0  0x000055555575914e in xftfont_close (font=0x5555560a6a60) at xftfont.c:464
    #1  0x00005555556fd454 in font_clear_cache (cache=XIL(0x555555e4c8b3), driver=driver@entry=0x5555559e11e0 <xftfont_driver>, f=0x55555646b2a0) at font.c:2643
    #2  0x0000555555702e35 in font_finish_cache (driver=0x5555559e11e0 <xftfont_driver>, f=0x55555646b2a0) at font.c:2588
    #3  0x0000555555702e35 in font_update_drivers (f=f@entry=0x55555646b2a0, new_drivers=new_drivers@entry=XIL(0x555558155c13)) at font.c:3545
    #4  0x00005555555a2a0f in x_set_font_backend (f=0x55555646b2a0, new_value=<optimized out>, old_value=XIL(0x555555e4c7b3)) at frame.c:4400
    #5  0x00005555555a1408 in x_set_frame_parameters (f=f@entry=0x55555646b2a0, alist=alist@entry=XIL(0x55555815b603)) at frame.c:3933
    #6  0x00005555555a1e9c in Fmodify_frame_parameters (frame=<optimized out>, alist=XIL(0x55555815b603)) at frame.c:3197
   
    Lisp Backtrace:
    "modify-frame-parameters" (0xffffb898)
    "frameset--restore-frame" (0xffffbc90)
    "frameset-restore" (0xffffc1f0)
    "desktop-restore-frameset" (0xffffc458)
    "desktop-read" (0xffffc7e0)
    0x563cec70 PVEC_COMPILED
    "run-hooks" (0xffffcae0)
    "command-line" (0xffffd388)
    "normal-top-level" (0xffffd700)

So it looks like we're closing the xft font backend, because of the
(font-backend x) in the desktop file, and flushing the font cache. Looking at where it crashes exactly:

    (gdb) c
    Continuing.

    Thread 1 "emacs" received signal SIGSEGV, Segmentation fault.
    0x00007ffff446468d in XftCharIndex () from /usr/lib/x86_64-linux-gnu/libXft.so.2
    (gdb) bt
    #0  0x00007ffff446468d in XftCharIndex () at /usr/lib/x86_64-linux-gnu/libXft.so.2
    #1  0x0000555555758689 in xftfont_encode_char (font=<optimized out>, c=<optimized out>)
    at xftfont.c:532
    #2  0x00005555555d60a9 in get_char_glyph_code (char2b=<synthetic pointer>, font=0x555557b49470, c=<optimized out>) at xdisp.c:25915
    #3  0x00005555555d60a9 in x_produce_glyphs (it=0x7fffffff9b00) at xdisp.c:28294

Here we're using xftfont_encode_char, even though we've just closed
the XFT font backend and should be using the X one for the minibuffer?
Is the 'it' there caching XFT information?

I have no idea how to fix this. I can reproduce at will if more gdb
info is needed (BTW, emacs-26 has the same issue).

    Lisp Backtrace:
    "message" (0xffffc458)
    "desktop-read" (0xffffc7e0)
    0x563cec70 PVEC_COMPILED
    "run-hooks" (0xffffcae0)
    "command-line" (0xffffd388)
    "normal-top-level" (0xffffd700)

Reply | Threaded
Open this post in threaded view
|

Re: switching font backends in .emacs.desktop causes crash

martin rudalics
 >      Thread 1 "emacs" received signal SIGSEGV, Segmentation fault.
 >      0x00007ffff446468d in XftCharIndex () from /usr/lib/x86_64-linux-gnu/libXft.so.2
 >      (gdb) bt
 >      #0  0x00007ffff446468d in XftCharIndex () at /usr/lib/x86_64-linux-gnu/libXft.so.2
 >      #1  0x0000555555758689 in xftfont_encode_char (font=<optimized out>, c=<optimized out>)
 >      at xftfont.c:532
 >      #2  0x00005555555d60a9 in get_char_glyph_code (char2b=<synthetic pointer>, font=0x555557b49470, c=<optimized out>) at xdisp.c:25915
 >      #3  0x00005555555d60a9 in x_produce_glyphs (it=0x7fffffff9b00) at xdisp.c:28294
 >
 > Here we're using xftfont_encode_char, even though we've just closed
 > the XFT font backend and should be using the X one for the minibuffer?
 > Is the 'it' there caching XFT information?
 >
 > I have no idea how to fix this. I can reproduce at will if more gdb
 > info is needed (BTW, emacs-26 has the same issue).
 >
 >      Lisp Backtrace:
 >      "message" (0xffffc458)
 >      "desktop-read" (0xffffc7e0)
 >      0x563cec70 PVEC_COMPILED
 >      "run-hooks" (0xffffcae0)
 >      "command-line" (0xffffd388)
 >      "normal-top-level" (0xffffd700)

This looks like Bug#23386: Segfault when messing with font-backend.

martin

Reply | Threaded
Open this post in threaded view
|

Re: switching font backends in .emacs.desktop causes crash

Robert Pluim
martin rudalics <[hidden email]> writes:

>>      Thread 1 "emacs" received signal SIGSEGV, Segmentation fault.
>>      0x00007ffff446468d in XftCharIndex () from /usr/lib/x86_64-linux-gnu/libXft.so.2
>>      (gdb) bt
>>      #0  0x00007ffff446468d in XftCharIndex () at /usr/lib/x86_64-linux-gnu/libXft.so.2
>>      #1  0x0000555555758689 in xftfont_encode_char (font=<optimized out>, c=<optimized out>)
>>      at xftfont.c:532
>>      #2 0x00005555555d60a9 in get_char_glyph_code (char2b=<synthetic
>> pointer>, font=0x555557b49470, c=<optimized out>) at xdisp.c:25915
>>      #3  0x00005555555d60a9 in x_produce_glyphs (it=0x7fffffff9b00) at xdisp.c:28294
>>
>> Here we're using xftfont_encode_char, even though we've just closed
>> the XFT font backend and should be using the X one for the minibuffer?
>> Is the 'it' there caching XFT information?
>>
>> I have no idea how to fix this. I can reproduce at will if more gdb
>> info is needed (BTW, emacs-26 has the same issue).
>>
>>      Lisp Backtrace:
>>      "message" (0xffffc458)
>>      "desktop-read" (0xffffc7e0)
>>      0x563cec70 PVEC_COMPILED
>>      "run-hooks" (0xffffcae0)
>>      "command-line" (0xffffd388)
>>      "normal-top-level" (0xffffd700)
>
> This looks like Bug#23386: Segfault when messing with font-backend.

It is in fact exactly that. I tried the patch there, it works for
me. How come it never went in?

Robert

Reply | Threaded
Open this post in threaded view
|

Re: switching font backends in .emacs.desktop causes crash

martin rudalics
 >> This looks like Bug#23386: Segfault when messing with font-backend.
 >
 > It is in fact exactly that. I tried the patch there, it works for
 > me.

Which one did you try?  Noam's or Dmitry's?

 > How come it never went in?

Bceause Eli normally doesn't use X.  And Dmitry left us a month later
because we offended him after he broke the tooltip code on NS.  Maybe
we have better luck with Noam.

martin

Reply | Threaded
Open this post in threaded view
|

Re: switching font backends in .emacs.desktop causes crash

Eli Zaretskii
In reply to this post by Robert Pluim
> From: Robert Pluim <[hidden email]>
> Date: Fri, 08 Feb 2019 15:49:38 +0100
> Cc: [hidden email]
>
> >>      Lisp Backtrace:
> >>      "message" (0xffffc458)
> >>      "desktop-read" (0xffffc7e0)
> >>      0x563cec70 PVEC_COMPILED
> >>      "run-hooks" (0xffffcae0)
> >>      "command-line" (0xffffd388)
> >>      "normal-top-level" (0xffffd700)
> >
> > This looks like Bug#23386: Segfault when messing with font-backend.
>
> It is in fact exactly that. I tried the patch there, it works for
> me. How come it never went in?

Which patch?  There were quite a few in that bug's discussion.

Reply | Threaded
Open this post in threaded view
|

Re: switching font backends in .emacs.desktop causes crash

Robert Pluim
In reply to this post by martin rudalics
martin rudalics <[hidden email]> writes:

>>> This looks like Bug#23386: Segfault when messing with font-backend.
>>
>> It is in fact exactly that. I tried the patch there, it works for
>> me.
>
> Which one did you try?  Noam's or Dmitry's?
>

Dmitry's

>> How come it never went in?
>
> Bceause Eli normally doesn't use X.  And Dmitry left us a month later
> because we offended him after he broke the tooltip code on NS.  Maybe
> we have better luck with Noam.

OK. Iʼm unlikely to be using X much in the near future, and the cause
is pretty obscure, so thereʼs no hurry for it to go in. [1]

Robert

Footnotes:
[1]  And in the glorious GTK only future, there will be only one font
     backend :-)


Reply | Threaded
Open this post in threaded view
|

Re: switching font backends in .emacs.desktop causes crash

Robert Pluim
In reply to this post by Eli Zaretskii
Eli Zaretskii <[hidden email]> writes:

>> From: Robert Pluim <[hidden email]>
>> Date: Fri, 08 Feb 2019 15:49:38 +0100
>> Cc: [hidden email]
>>
>> >>      Lisp Backtrace:
>> >>      "message" (0xffffc458)
>> >>      "desktop-read" (0xffffc7e0)
>> >>      0x563cec70 PVEC_COMPILED
>> >>      "run-hooks" (0xffffcae0)
>> >>      "command-line" (0xffffd388)
>> >>      "normal-top-level" (0xffffd700)
>> >
>> > This looks like Bug#23386: Segfault when messing with font-backend.
>>
>> It is in fact exactly that. I tried the patch there, it works for
>> me. How come it never went in?
>
> Which patch?  There were quite a few in that bug's discussion.

This one <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23386#43>

Robert

Reply | Threaded
Open this post in threaded view
|

Re: switching font backends in .emacs.desktop causes crash

Eli Zaretskii
> From: Robert Pluim <[hidden email]>
> Cc: [hidden email]
> Date: Fri, 08 Feb 2019 17:16:43 +0100
>
> >> > This looks like Bug#23386: Segfault when messing with font-backend.
> >>
> >> It is in fact exactly that. I tried the patch there, it works for
> >> me. How come it never went in?
> >
> > Which patch?  There were quite a few in that bug's discussion.
>
> This one <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23386#43>

How about installing that on master?