Subject: 30.0.50; crash in restore_kboard_configuration after pop_kboard

From: Daniel Clemente <[email-masked]>
Date: Mon, 10 Jun 2024 16:05:29 +0000

This is a continuation of bug 71224 and it may be a similar issue.
It's also similar to the last bug I just reported (see thisbugnumber-1)

I'm using Emacs without X support but running it in an X terminal.
With glyph debug enabled. emacsclient, with -Q.

I was using the same reproduction procedure as in bug 71224. I was
randomly mixing these actions:
- automatically filling the Lisp stack by causing infinite recursion
every 0.1 seconds, by launching the server like this:   emacs
--fg-daemon -Q --eval '(progn (defun recurse () (recurse))
(run-with-timer 0.1 0.1 (quote recurse)))'
- call to (debug), once or twice, to open a backtrace window
- opening new frames, just 2 or 3
- closing a frame, just 1 or 2
- moving the cursor a bit, normally

After a few seconds, this happens. This is of course a rare crash,
since Emacs is in stress conditions. But debugging and consuming the
Lisp stack shouldn't crash the server. Besides, I could reproduce this
several times using the methods above and some luck.

I don't know whether a call to emacs_abort is considered a problem.

Error running timer ‘recurse’: (excessive-lisp-nesting 1601)
Error running timer ‘recurse’: (excessive-lisp-nesting 1601)
Error running timer ‘recurse’: (excessive-lisp-nesting 1601)
Error running timer ‘recurse’: (excessive-lisp-nesting 1601)

Breakpoint 1, terminate_due_to_signal (sig=6, backtrace_limit=40) at emacs.c:443
443      signal (sig, SIG_DFL);

(gdb) bt

#0  terminate_due_to_signal (sig=6, backtrace_limit=40) at emacs.c:443
#1  0x00005555556bd46e in emacs_abort () at sysdep.c:2391
#2  0x00005555556901b3 in restore_kboard_configuration (was_locked=1)
at keyboard.c:960
#3  0x0000555555772540 in do_one_unbind (this_binding=0x7fffffff8bd0,
unwinding=true,
    bindflag=SET_INTERNAL_UNBIND) at eval.c:3702
#4  0x00005555557728e5 in unbind_to (count=..., value=XIL(0)) at eval.c:3834
#5  0x000055555576be9a in unwind_to_catch (catch=0x55555605c950,
type=NONLOCAL_EXIT_THROW, value=XIL(0))
    at eval.c:1349
#6  0x000055555576c002 in Fthrow (tag=XIL(0xfc90), value=XIL(0)) at eval.c:1378
#7  0x0000555555690a5b in Ftop_level () at keyboard.c:1219
#8  0x0000555555770a79 in funcall_subr (subr=0x555555eb81e0
<Stop_level>, numargs=0, args=0x7fffffff8e10)
    at eval.c:3159
#9  0x0000555555770459 in funcall_general (fun=XIL(0x555555eb81e5),
numargs=0, args=0x7fffffff8e10)
    at eval.c:3040
#10 0x0000555555770762 in Ffuncall (nargs=1, args=0x7fffffff8e08) at eval.c:3093
#11 0x00007ffff2a44926 in
F7365727665722d676f746f2d746f706c6576656c_server_goto_toplevel_0 ()
   from /home/dc/.emacs.d/eln-cache/30.0.50-cd05323a/server-0cc44189-5a0bf11b.eln
#12 0x0000555555770a92 in funcall_subr (subr=0x555556079628,
numargs=1, args=0x7fffffff9040) at eval.c:3161
#13 0x0000555555770459 in funcall_general (fun=XIL(0x55555607962d),
numargs=1, args=0x7fffffff9040)
    at eval.c:3040
#14 0x0000555555770762 in Ffuncall (nargs=2, args=0x7fffffff9038) at eval.c:3093
#15 0x00007ffff2a45da3 in
F7365727665722d2d70726f636573732d66696c7465722d31_server__process_filter_1_0
()
   from /home/dc/.emacs.d/eln-cache/30.0.50-cd05323a/server-0cc44189-5a0bf11b.eln
#16 0x0000555555770ab9 in funcall_subr (subr=0x55555607cda8,
numargs=2, args=0x7fffffff9228) at eval.c:3163
#17 0x0000555555770459 in funcall_general (fun=XIL(0x55555607cdad),
numargs=2, args=0x7fffffff9228)
    at eval.c:3040
#18 0x0000555555770762 in Ffuncall (nargs=3, args=0x7fffffff9220) at eval.c:3093
#19 0x00007ffff2a44e39 in
F7365727665722d2d70726f636573732d66696c7465722d616c6c2d70656e64696e67_server__process_filter_all_pending_0
() from /home/dc/.emacs.d/eln-cache/30.0.50-cd05323a/server-0cc44189-5a0bf11b.eln
#20 0x0000555555770a79 in funcall_subr (subr=0x55555607ccf8,
numargs=0, args=0x7fffffff93b0) at eval.c:3159
#21 0x0000555555770459 in funcall_general (fun=XIL(0x55555607ccfd),
numargs=0, args=0x7fffffff93b0)
    at eval.c:3040
#22 0x0000555555770762 in Ffuncall (nargs=1, args=0x7fffffff93a8) at eval.c:3093
#23 0x00007ffff2a44cde in
F7365727665722d70726f636573732d66696c746572_server_process_filter_0 ()
   from /home/dc/.emacs.d/eln-cache/30.0.50-cd05323a/server-0cc44189-5a0bf11b.eln
#24 0x0000555555770ab9 in funcall_subr (subr=0x55555607cca0,
numargs=2, args=0x7fffffff9528) at eval.c:3163
#25 0x0000555555770459 in funcall_general (fun=XIL(0x55555607cca5),
numargs=2, args=0x7fffffff9528)
    at eval.c:3040
#26 0x0000555555770762 in Ffuncall (nargs=3, args=0x7fffffff9520) at eval.c:3093
#27 0x000055555576fc0b in Fapply (nargs=2, args=0x7fffffff95d0) at eval.c:2765
#28 0x00005555557701b6 in apply1 (fn=XIL(0x154140),
arg=XIL(0x7ffff0cdde13)) at eval.c:2981
#29 0x00005555557ef4f7 in read_process_output_call
(fun_and_args=XIL(0x7ffff0cddd93)) at process.c:6129
#30 0x000055555576ca19 in internal_condition_case_1
(bfun=0x5555557ef4c0 <read_process_output_call>,
    arg=XIL(0x7ffff0cddd93), handlers=XIL(0x90), hfun=0x5555557ef4fd
<read_process_output_error_handler>)
    at eval.c:1637
#31 0x00005555557f072b in read_and_dispose_of_process_output (p=0x5555562e3150,
    chars=0x55555665bc70 "\200R1VUU", nbytes=3784,
coding=0x5555560ca910) at process.c:6483
#32 0x00005555557efad2 in read_process_output
(proc=XIL(0x5555562e3155), channel=23) at process.c:6269
#33 0x00005555557eec9b in wait_reading_process_output (time_limit=30,
nsecs=0, read_kbd=-1,
    do_display=true, wait_for_cell=XIL(0), wait_proc=0x0,
just_wait_proc=0) at process.c:5947
#34 0x0000555555594fbd in sit_for (timeout=make_fixnum(30),
reading=true, display_option=1)
    at dispnew.c:6334
#35 0x00005555556954a3 in read_char (commandflag=1,
map=XIL(0x7ffff0ceec33), prev_event=XIL(0),
    used_mouse_menu=0x7fffffff9fef, end_time=0x0) at keyboard.c:2923
#36 0x00005555556a6a52 in read_key_sequence (keybuf=0x7fffffffa200,
prompt=XIL(0),
    dont_downcase_last=false, can_return_switch_frame=true,
fix_current_buffer=true,
    prevent_redisplay=false, disable_text_conversion_p=false) at
keyboard.c:10728
#37 0x000055555569113a in command_loop_1 () at keyboard.c:1429
#38 0x000055555576c938 in internal_condition_case (bfun=0x555555690d0b
<command_loop_1>,
    handlers=XIL(0x90), hfun=0x5555556901b6 <cmd_error>) at eval.c:1613
#39 0x00005555556908e9 in command_loop_2 (handlers=XIL(0x90)) at keyboard.c:1168
--Type <RET> for more, q to quit, c to continue without paging--

#40 0x000055555576bd65 in internal_catch (tag=XIL(0x68d0),
func=0x5555556908bf <command_loop_2>,
    arg=XIL(0x90)) at eval.c:1292
#41 0x00005555556907ff in command_loop () at keyboard.c:1138
#42 0x000055555568fc58 in recursive_edit_1 () at keyboard.c:754
#43 0x00005555556e383c in read_minibuf (map=XIL(0x7ffff2105ecb), initial=XIL(0),
    prompt=XIL(0x5555561ac234), expflag=false,
histvar=XIL(0x2aaa9bfbc348), histpos=make_fixnum(0),
    defalt=XIL(0), allow_props=false, inherit_input_method=false) at
minibuf.c:905
#44 0x00005555556e4f80 in Fread_from_minibuffer
(prompt=XIL(0x5555561ac234), initial_contents=XIL(0),
    keymap=XIL(0x7ffff2105ecb), read=XIL(0), hist=XIL(0x2aaa9bfbc348),
default_value=XIL(0),
    inherit_input_method=XIL(0)) at minibuf.c:1385
#45 0x0000555555770c28 in funcall_subr (subr=0x555555ebb6c0
<Sread_from_minibuffer>, numargs=7,
    args=0x7ffff0dff0e8) at eval.c:3173
#46 0x00005555557cce11 in exec_byte_code (fun=XIL(0x7ffff2105b85),
args_template=2050, nargs=8,
    args=0x7fffffffafa8) at bytecode.c:812
#47 0x000055555577110b in funcall_lambda (fun=XIL(0x7ffff2105b85),
nargs=8, arg_vector=0x7fffffffaf68)
    at eval.c:3252
#48 0x00005555557704a5 in funcall_general (fun=XIL(0x7ffff2105b85),
numargs=8, args=0x7fffffffaf68)
    at eval.c:3044
#49 0x0000555555770762 in Ffuncall (nargs=9, args=0x7fffffffaf60) at eval.c:3093
#50 0x00005555556e6a26 in Fcompleting_read
(prompt=XIL(0x5555561ac234), collection=XIL(0x7ffff1f1e9dd),
    predicate=XIL(0x5555563bc6a5), require_match=XIL(0x30),
initial_input=XIL(0),
    hist=XIL(0x2aaa9bfbc348), def=XIL(0), inherit_input_method=XIL(0))
at minibuf.c:2035
#51 0x00007ffff19caede in
F726561642d657874656e6465642d636f6d6d616e642d31_read_extended_command_1_0
()
   from /opt/dc/emacs/bin/../lib/emacs/30.0.50/native-lisp/30.0.50-cd05323a/preloaded/simple-fab5b0cf-ba5c37db.eln
[…]

(gdb) xbacktrace

"recursive-edit" (0xffffc5d0)
"debug" (0xffffca50)
"funcall-interactively" (0xffffca48)
"command-execute" (0xffffcf38)
"execute-extended-command" (0xffffd280)
"funcall-interactively" (0xffffd278)
"command-execute" (0xffffda38)

(gdb) frame 2

#2  0x00005555556901b3 in restore_kboard_configuration (was_locked=1)
at keyboard.c:960
li960            emacs_abort ();
(gdb) list

955        {
956          struct kboard *prev = current_kboard;
957          pop_kboard ();
958          /* The pop should not change the kboard.  */
959          if (single_kboard && current_kboard != prev)
960            emacs_abort ();
961        }
962    }
963
964    ^L
(gdb) p single_kboard

$1 = true
(gdb) p current_kboard

$2 = (KBOARD *) 0x555556266360
(gdb) p prev

$3 = (struct kboard *) 0x5555562bb780
(gdb)

(gdb) p *prev
$6 = {
  next_kboard = 0x555556b7ae50,
  Voverriding_terminal_local_map_ = XIL(0),
  Vlast_command_ = XIL(0x2aaa9bc0bfc0),
  Vreal_last_command_ = XIL(0x2aaa9bc0bfc0),
  Vkeyboard_translate_table_ = XIL(0x5555562e32bd),
  Vlast_repeatable_command_ = XIL(0x2aaa9bc0bfc0),
  Vprefix_arg_ = XIL(0),
  Vlast_prefix_arg_ = XIL(0),
  kbd_queue_ = XIL(0),
  defining_kbd_macro_ = XIL(0),
  kbd_macro_buffer = 0x0,
  kbd_macro_ptr = 0xd69707803020008,
  kbd_macro_end = 0x72030200080e0008,
  kbd_macro_bufsize = 0,
  Vlast_kbd_macro_ = XIL(0),
  Vsystem_key_alist_ = XIL(0),
  system_key_syms_ = XIL(0),
  Vwindow_system_ = XIL(0),
  Vlocal_function_key_map_ = XIL(0x7ffff0d0e373),
  Vinput_decode_map_ = XIL(0x7ffff0d0e383),
  Vdefault_minibuffer_frame_ = XIL(0),
  reference_count = 1,
  echo_string_ = XIL(0),
  kbd_queue_has_data = false,
  immediate_echo = false,
  echo_prompt_ = XIL(0)
}
(gdb) p *current_kboard
$7 = {
  next_kboard = 0x5555562bb780,
  Voverriding_terminal_local_map_ = XIL(0),
  Vlast_command_ = XIL(0),
  Vreal_last_command_ = XIL(0),
  Vkeyboard_translate_table_ = XIL(0x555555ff9dd5),
  Vlast_repeatable_command_ = XIL(0),
  Vprefix_arg_ = XIL(0),
  Vlast_prefix_arg_ = XIL(0),
  kbd_queue_ = XIL(0),
  defining_kbd_macro_ = XIL(0),
  kbd_macro_buffer = 0x0,
  kbd_macro_ptr = 0x267010200030e2e,
  kbd_macro_end = 0x230e00230d7a01,
  kbd_macro_bufsize = 0,
  Vlast_kbd_macro_ = XIL(0),
  Vsystem_key_alist_ = XIL(0),
  system_key_syms_ = XIL(0),
  Vwindow_system_ = XIL(0),
  Vlocal_function_key_map_ = XIL(0x7ffff0a60053),
  Vinput_decode_map_ = XIL(0x7ffff0a60063),
  Vdefault_minibuffer_frame_ = XIL(0),
  reference_count = 1,
  echo_string_ = XIL(0),
  kbd_queue_has_data = false,
  immediate_echo = false,
  echo_prompt_ = XIL(0)
}
(gdb)

(gdb) p *prev->next_kboard->next_kboard->next_kboard->next_kboard->next_kboard
$12 = {
  next_kboard = 0x0,
  Voverriding_terminal_local_map_ = XIL(0),
  Vlast_command_ = XIL(0x2aaa9bd8f770),
  Vreal_last_command_ = XIL(0x2aaa9bd8f770),
  Vkeyboard_translate_table_ = XIL(0x5555560796fd),
  Vlast_repeatable_command_ = XIL(0x2aaa9bd8f770),
  Vprefix_arg_ = XIL(0),
  Vlast_prefix_arg_ = XIL(0),
  kbd_queue_ = XIL(0),
  defining_kbd_macro_ = XIL(0),
  kbd_macro_buffer = 0x0,
  kbd_macro_ptr = 0x0,
  kbd_macro_end = 0x0,
  kbd_macro_bufsize = 0,
  Vlast_kbd_macro_ = XIL(0),
  Vsystem_key_alist_ = XIL(0),
  system_key_syms_ = XIL(0),
  Vwindow_system_ = XIL(0),
  Vlocal_function_key_map_ = XIL(0x7ffff2bb09c3),
  Vinput_decode_map_ = XIL(0x7ffff2bb09b3),
  Vdefault_minibuffer_frame_ = XIL(0),
  reference_count = 0,
  echo_string_ = XIL(0),
  kbd_queue_has_data = false,
  immediate_echo = false,
  echo_prompt_ = XIL(0)
}

(gdb) p kboard_stack

$4 = (struct kboard_stack *) 0x555556182f90
(gdb) p *kboard_stack

$5 = {
  kboard = 0x555556266360,
  next = 0x0
}
(gdb)

(gdb) p *kboard_stack->kboard
$14 = {
  next_kboard = 0x5555562bb780,
  Voverriding_terminal_local_map_ = XIL(0),
  Vlast_command_ = XIL(0),
  Vreal_last_command_ = XIL(0),
  Vkeyboard_translate_table_ = XIL(0x555555ff9dd5),
  Vlast_repeatable_command_ = XIL(0),
  Vprefix_arg_ = XIL(0),
  Vlast_prefix_arg_ = XIL(0),
  kbd_queue_ = XIL(0),
  defining_kbd_macro_ = XIL(0),
  kbd_macro_buffer = 0x0,
  kbd_macro_ptr = 0x267010200030e2e,
  kbd_macro_end = 0x230e00230d7a01,
  kbd_macro_bufsize = 0,
  Vlast_kbd_macro_ = XIL(0),
  Vsystem_key_alist_ = XIL(0),
  system_key_syms_ = XIL(0),
  Vwindow_system_ = XIL(0),
  Vlocal_function_key_map_ = XIL(0x7ffff0a60053),
  Vinput_decode_map_ = XIL(0x7ffff0a60063),
  Vdefault_minibuffer_frame_ = XIL(0),
  reference_count = 1,
  echo_string_ = XIL(0),
  kbd_queue_has_data = false,
  immediate_echo = false,
  echo_prompt_ = XIL(0)
}

define print_terminal_list
  set var $t = terminal_list
  while $t
    p $t->name
    set var $t = $t->next_terminal
  end
end

(gdb) print_terminal_list
$1 = 0x5555560687b0 "/dev/pts/31"
$2 = 0x5555561cd5b0 "/dev/pts/30"
$3 = 0x55555618c9a0 "/dev/pts/26"
$4 = 0x55555625aca0 "/dev/pts/29"
$5 = 0x5555560d6e90 "/dev/pts/27"
$6 = 0x555556a782a0 "/dev/pts/25"
$7 = 0x5555563cbc20 "/dev/pts/24"
$8 = 0x55555631e9a0 "/dev/pts/23"
$9 = 0x555556182f40 "/dev/pts/18"
$10 = 0x555555fe2870 "initial_terminal"
(gdb)

In GNU Emacs 30.0.50 (build 8, x86_64-pc-linux-gnu) of 2024-06-09 built
 on sonn
Repository revision: 19806248167b9c4edaadbf4ed428a62fd8c5e412
Repository branch: master
System Description: Devuan GNU/Linux 5 (daedalus)

Configured using:
 'configure --prefix=/opt/dc/emacs/ --with-tiff=no --without-tiff
 --without-libsystemd --without-dbus --with-mailutils
 --with-native-compilation --with-x-toolkit=no --without-imagemagick
 --without-xft --without-harfbuzz --without-freetype --without-libotf
 --without-xwidgets --without-xpm --without-jpeg --without-gif
 --without-png --without-webp --without-rsvg --without-cairo --without-x
 --enable-checking=yes,glyphs 'CFLAGS=-g3 -O0''

Configured features:
GMP GNUTLS LCMS2 LIBSELINUX LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER SECCOMP SOUND SQLITE3 THREADS XIM ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=SCIM
  locale-coding-system: utf-8-unix

Major mode: Dired by name

Minor modes in effect:
  server-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort hashcash mail-extr compile comint ansi-osc ansi-color ring
tool-bar comp-run comp-common rx emacsbug message mailcap yank-media
puny rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search time-date subr-x mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils pp
dired-aux cl-loaddefs cl-lib regexp-opt dired dnd dired-loaddefs
term/rxvt term/xterm xterm byte-opt gv bytecomp byte-compile server rmc
iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads inotify lcms2 multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 79456 11259) (symbols 48 7266 2) (strings 32 19563 4524)
 (string-bytes 1 555520) (vectors 16 9518)
 (vector-slots 8 101651 9432) (floats 8 33 11518)
 (intervals 56 2220 0) (buffers 984 14))