Subject: Re: bug#71289: 30.0.50; cmcheckmagic aborts when tty_write_glyphs writes "Garbage collecting..." in some cases

From: Daniel Clemente <[email-masked]>
Date: Fri, 31 May 2024 17:07:45 +0000

> Thanks, but these backtraces are not enough, because they don't
> explain why was emacs_abort called.  We need to see all the values
> involved in this condition:
>
>  if (curX (tty) == FrameCols (tty))
>    {
>      if (!MagicWrap (tty) || curY (tty) >= FrameRows (tty) - 1) <<<<<<<<<<<
>        emacs_abort ();

These were the variables just before emacs_abort, and (abort==1) when aborting.

At point cmcheckmagic, ¿abort? 0. MagicWrap 1, curY 0, vs. 3 - 1. Now
tty has 3 rows, 14 cols
At point cmcheckmagic, ¿abort? 0. MagicWrap 1, curY 1, vs. 3 - 1. Now
tty has 3 rows, 14 cols
At point cmcheckmagic, ¿abort? 1. MagicWrap 1, curY 3, vs. 3 - 1. Now
tty has 3 rows, 14 cols

I got them by adding:
fprintf(stderr, "At point cmcheckmagic, ¿abort? %d. MagicWrap %d, curY
%d, vs. %d - 1. Now tty has %d rows, %d cols\n",
      (!MagicWrap (tty) || curY (tty) >= FrameRows (tty) - 1),
      MagicWrap(tty), curY(tty), FrameRows(tty),
      FrameRows(tty), FrameCols(tty));

I forgot curX, which is:
(gdb) p curX(tty)
$1 = 14

To reproduce this I had to try many random operations. The last thing
I did was increasing the size of an X window showing dired, from very
small (1 line, ~10 cols to 3x14); this works well most of the time but
this time this happened.

Backtrace.

(gdb) bt full
#0  terminate_due_to_signal (sig=6, backtrace_limit=40) at emacs.c:443
No locals.
#1  0x00005555556bdab0 in emacs_abort () at sysdep.c:2391
No locals.
#2  0x000055555566995d in cmcheckmagic (tty=0x5555572c4c90) at cm.c:124
No locals.
#3  0x000055555566de6f in tty_write_glyphs (f=0x555561525f60,
string=0x5555610141c0, len=14) at term.c:819
        conversion_buffer = 0x55555f7e9160 "x \\  3 dc   dc)
(Dired by name Helm Projectile yas) 7:39PM 0.41", ' ' <repeats 80
times>, "`UU"
        coding = 0x555559956cf0
        n = 14
        stringlen = 0
        tty = 0x5555572c4c90
#4  0x0000555555678203 in write_glyphs (f=0x555561525f60,
string=0x555561013f20, len=14) at terminal.c:163
No locals.
#5  0x000055555559194a in update_frame_line (f=0x555561525f60, vpos=3,
updating_menu_p=false)
    at dispnew.c:5321
        obody = 0x0
        nbody = 0x555561013f20
        op1 = 0x300000011
        op2 = 0x7fffffff78e0
        np1 = 0x7ffff549ed90 <__GI___fflush_unlocked+48>
        nend = 0x5555610141c0
        tem = 0
        osp = 32767
        nsp = -34592
        begmatch = 32767
        endmatch = -178330144
        olen = 0
        nlen = 14
        current_matrix = 0x555560cad240
        desired_matrix = 0x5555603cf860
        current_row = 0x555560c681c8
        desired_row = 0x55556045e7b8
        must_write_whole_line_p = true
        write_spaces_p = true
        colored_spaces_p = true
#6  0x0000555555590b8d in update_frame_1 (f=0x555561525f60,
force_p=true, inhibit_id_p=false,
    set_cursor_p=true, updating_menu_p=false) at dispnew.c:5008
        current_matrix = 0x555560cad240
        desired_matrix = 0x5555603cf860
        i = 3
        pause_p = 85
        preempt_count = 17
#7  0x000055555558cf9f in update_frame (f=0x555561525f60,
force_p=true, inhibit_hairy_id_p=false)
    at dispnew.c:3346
        paused_p = false
        root_window = 0x555560baa508
#8  0x00005555555cf876 in redisplay_internal () at xdisp.c:17478
        gcscrollbars = true
        f_redisplay_flag = true
        f = 0x555561525f60
        w = 0x555561526388
        sw = 0x555561526388
        fr = 0x555561525f60
        pending = false
        must_finish = false
        match_p = false
        tlbufpos = {
          charpos = 0,
          bytepos = 116
        }
--Type <RET> for more, q to quit, c to continue without paging--
        tlendpos = {
          charpos = 29241,
          bytepos = 29273
        }
        number_of_visible_frames = 7
        sf = 0x555561525f60
        polling_stopped_here = true
        tail = XIL(0x5555614f3903)
        frame = XIL(0x555561525f65)
        MAX_HSCROLL_RETRIES = MAX_HSCROLL_RETRIES
        hscroll_retries = 0
        MAX_GARBAGED_FRAME_RETRIES = MAX_GARBAGED_FRAME_RETRIES
        garbaged_frame_retries = 0
        consider_all_windows_p = true
        update_miniwindow_p = false
        count = {
          bytes = 2304
        }
#9  0x00005555555d01aa in redisplay_preserve_echo_area (from_where=11)
at xdisp.c:17761
        count = {
          bytes = 2272
        }
#10 0x00005555557ee631 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:5585
        process_skipped = false
        wrapped = false
        channel_start = 0
        child_fd = 6
        last_read_channel = 13
        channel = 1024
        nfds = -1
        Available = {
          fds_bits = {8768089968, 0 <repeats 15 times>}
        }
        Writeok = {
          fds_bits = {0 <repeats 16 times>}
        }
        check_write = true
        check_delay = 1
        no_avail = true
        xerrno = 4
        proc = XIL(0xa00000fff)
        timeout = {
          tv_sec = 28,
          tv_nsec = 503054580
        }
        end_time = {
          tv_sec = 1717173578,
          tv_nsec = 474082259
        }
        timer_delay = {
          tv_sec = 0,
          tv_nsec = 502843472
        }
        got_output_end_time = {
          tv_sec = 1717173578,
          tv_nsec = 474082259
        }
        MINIMUM = MINIMUM
        TIMEOUT = TIMEOUT
        FOREVER = FOREVER
        wait = TIMEOUT
--Type <RET> for more, q to quit, c to continue without paging--
        got_some_output = -1
        prev_wait_proc_nbytes_read = 0
        retry_for_async = false
        count = {
          bytes = 2240
        }
        now = {
          tv_sec = 1717173549,
          tv_nsec = 971027679
        }
#11 0x0000555555594f26 in sit_for (timeout=make_fixnum(30),
reading=true, display_option=1)
    at dispnew.c:6321
        sec = 30
        nsec = 0
        do_display = true
        curbuf_eq_winbuf = false
        nbytes = 21845
#12 0x0000555555695ae5 in read_char (commandflag=1,
map=XIL(0x555560278023), prev_event=XIL(0),
    used_mouse_menu=0x7fffffff966f, end_time=0x0) at keyboard.c:2923
        tem0 = XIL(0x555555770001)
        timeout = 30
        count1 = {
          bytes = 2208
        }
        delay_level = 4
        buffer_size = 50
        c = XIL(0)
        local_getcjmp = {{
            __jmpbuf = {0, -8236620451292018264, 0, 140737168851264,
93825052522836, 0,
              -8236620451436721752, -2817863054631007832},
            __mask_was_saved = 0,
            __saved_mask = {
              __val = {93464216335616, 139753184, 140737245531531,
93825002663168, 0, 0, 140737488327872,
                93824993653913, 40800, 140737488327952,
93824993660639, 1, 0, 93464225410400, 96,
                93825002663168}
            }
          }}
        save_jump = {{
            __jmpbuf = {0, 0, 0, 0, 0, 0, 0, 0},
            __mask_was_saved = 0,
            __saved_mask = {
              __val = {0 <repeats 16 times>}
            }
          }}
        tem = XIL(0x5555557806e9)
        save = XIL(0x67e0)
        previous_echo_area_message = XIL(0)
        also_record = XIL(0)
        reread = false
        recorded = false
        polling_stopped_here = false
        orig_kboard = 0x555560b58160
        jmpcount = {
          bytes = 2208

        }