kitty segfaults when selecting in diff kitten

Created on 28 Apr 2019  路  31Comments  路  Source: kovidgoyal/kitty

if you scroll downwards and start selecting text upwards, after few scrolls kitty segfaults.

Most helpful comment

I can confirm at least on my setup, it seems to be fixed

All 31 comments

Can you post a backtrace of the crash?

On most linux distributions, it ouwld require:

make debug
cause crash
echo bt | coredumpctl gdb

I cannot reproduce with your description, on master, steps I tried:

1) Run diff kitten
2) scroll down
3) drag upwards with the mouse

Note that the diff kitten does not currently implement mouse
integration, so dragging withthe mouse will not cause the kitten to
scroll upwards.

ah, by selecting text upwards i meant selecting it and scrolling upwards with mouse wheel.

You mean yo uare holdingdown the left mouse button and usingthe wheel at
the same time?

yep

also it works fails reliably when starting selection from the last line

I cant get it to crash on my system running from aster while doing that.
Also I'm not sure I understand why you are doing that. You cannot select
multiple screenfuls of text by doing it. For that mouse support has to
be added to the kitten, which is on my TODO list

A backtrace from the crash would help.

hmm, im having some problems with that, maybe because of my weird setup. i have core file generated, but doing echo bt | coredumpctl gdb results in

Failed to acquire bus: No such file or directory
No journal files were found.
No match found.

im pretty clueless in debugging

also segfault occurs on mouse button up

uhh, if i understand correctly, i ran gdb python3 core.
bt gives this

#0  0x00007f3b74cbf038 in xlimit_for_line (line=0x7f3b73236750) at /home/solitude/git/kitty/kitty/screen.c:1564
#1  text_for_selection (self=0x7f3b3a782010, a=<optimized out>) at /home/solitude/git/kitty/kitty/screen.c:1968
#2  0x00007f3b75be7edf in _PyCFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#3  0x00007f3b75c60769 in ?? () from /usr/lib/libpython3.6m.so.1.0
#4  0x00007f3b75c628bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#5  0x00007f3b75c5f873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#6  0x00007f3b75c60625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#7  0x00007f3b75c628bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#8  0x00007f3b75c5f873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#9  0x00007f3b75c682fb in _PyFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#10 0x00007f3b75ba0081 in _PyObject_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#11 0x00007f3b75ba02ec in _PyObject_Call_Prepend () from /usr/lib/libpython3.6m.so.1.0
#12 0x00007f3b75b9ffd9 in _PyObject_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#13 0x00007f3b75ba0bb8 in _PyObject_CallMethod_SizeT () from /usr/lib/libpython3.6m.so.1.0
#14 0x00007f3b74cc5acf in screen_update_selection (self=0x7f3b3a782010, x=<optimized out>, y=<optimized out>, ended=ended@entry=true) at /home/solitude/git/kitty/kitty/screen.c:2143
#15 0x00007f3b74cd5dd4 in update_drag (modifiers=0, is_release=true, w=<optimized out>, from_button=true) at /home/solitude/git/kitty/kitty/mouse.c:169
#16 mouse_event (button=button@entry=0, modifiers=modifiers@entry=0, action=<optimized out>, action@entry=0) at /home/solitude/git/kitty/kitty/mouse.c:534
#17 0x00007f3b74cf926b in mouse_button_callback (w=0x562cbcb3e870, button=0, action=0, mods=0) at /home/solitude/git/kitty/kitty/glfw.c:222
#18 0x00007f3b731af0e4 in _glfwInputMouseClick (window=<optimized out>, button=button@entry=0, action=action@entry=0, mods=<optimized out>) at /home/solitude/git/kitty/glfw/input.c:311
#19 0x00007f3b731badc3 in processEvent (event=event@entry=0x7ffe21ca6ca0) at /home/solitude/git/kitty/glfw/x11_window.c:1267
#20 0x00007f3b731bb64c in dispatch_x11_queued_events () at /home/solitude/git/kitty/glfw/x11_window.c:2508
#21 _glfwDispatchX11Events () at /home/solitude/git/kitty/glfw/x11_window.c:2523
#22 0x00007f3b731bb785 in handleEvents (timeout=<optimized out>) at /home/solitude/git/kitty/glfw/x11_window.c:66
#23 0x00007f3b731bb7b4 in _glfwPlatformWaitEvents () at /home/solitude/git/kitty/glfw/x11_window.c:2555
#24 0x00007f3b731b65a5 in _glfwPlatformRunMainLoop (tick_callback=0x7f3b74d2da2a <process_global_state>, data=0x7f3b72a0a030) at /home/solitude/git/kitty/glfw/main_loop.h:30
#25 0x00007f3b731ae849 in glfwRunMainLoop (callback=<optimized out>, data=<optimized out>) at /home/solitude/git/kitty/glfw/init.c:342
#26 0x00007f3b74cfa64c in run_main_loop (cb=cb@entry=0x7f3b74d2da2a <process_global_state>, cb_data=cb_data@entry=0x7f3b72a0a030) at /home/solitude/git/kitty/kitty/glfw.c:1136
#27 0x00007f3b74d2a6e6 in main_loop (self=0x7f3b72a0a030, a=<optimized out>) at /home/solitude/git/kitty/kitty/child-monitor.c:955
#28 0x00007f3b75be7edf in _PyCFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#29 0x00007f3b75c60769 in ?? () from /usr/lib/libpython3.6m.so.1.0
#30 0x00007f3b75c628bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#31 0x00007f3b75c6029a in ?? () from /usr/lib/libpython3.6m.so.1.0
#32 0x00007f3b75c60413 in ?? () from /usr/lib/libpython3.6m.so.1.0
#33 0x00007f3b75c60625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#34 0x00007f3b75c628bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#35 0x00007f3b75c6029a in ?? () from /usr/lib/libpython3.6m.so.1.0
#36 0x00007f3b75c60413 in ?? () from /usr/lib/libpython3.6m.so.1.0
#37 0x00007f3b75c60625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#38 0x00007f3b75c628bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#39 0x00007f3b75c5f873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#40 0x00007f3b75c60625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#41 0x00007f3b75c628bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#42 0x00007f3b75c5f873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#43 0x00007f3b75c60625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#44 0x00007f3b75c628bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#45 0x00007f3b75c5f873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#46 0x00007f3b75c60625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#47 0x00007f3b75c628bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#48 0x00007f3b75c6029a in ?? () from /usr/lib/libpython3.6m.so.1.0
#49 0x00007f3b75c607ce in PyEval_EvalCodeEx () from /usr/lib/libpython3.6m.so.1.0
#50 0x00007f3b75c607fb in PyEval_EvalCode () from /usr/lib/libpython3.6m.so.1.0
--Type <RET> for more, q to quit, c to continue without paging--
#51 0x00007f3b75c5d6ad in ?? () from /usr/lib/libpython3.6m.so.1.0
#52 0x00007f3b75be7f2b in _PyCFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#53 0x00007f3b75c60769 in ?? () from /usr/lib/libpython3.6m.so.1.0
#54 0x00007f3b75c628bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#55 0x00007f3b75c6029a in ?? () from /usr/lib/libpython3.6m.so.1.0
#56 0x00007f3b75c607ce in PyEval_EvalCodeEx () from /usr/lib/libpython3.6m.so.1.0
#57 0x00007f3b75c607fb in PyEval_EvalCode () from /usr/lib/libpython3.6m.so.1.0
#58 0x00007f3b75c89b94 in ?? () from /usr/lib/libpython3.6m.so.1.0
#59 0x00007f3b75c8c0c1 in PyRun_FileExFlags () from /usr/lib/libpython3.6m.so.1.0
#60 0x00007f3b75c8c22d in PyRun_SimpleFileExFlags () from /usr/lib/libpython3.6m.so.1.0
#61 0x00007f3b75ca2ee2 in Py_Main () from /usr/lib/libpython3.6m.so.1.0
#62 0x0000562cbafee238 in main ()

Is that with kitty master or some other version, the line numbers dont match current source code.

well, i just cloned the git repo, you can see it in the paths

okay, i think i ran it wrong. here is new backtrace.

#0  0x00007ff21e2a4038 in xlimit_for_line (line=0x7ff21cb05660) at /home/solitude/git/kitty/kitty/screen.c:1564
#1  text_for_selection (self=0x7ff1e7cd3010, a=<optimized out>) at /home/solitude/git/kitty/kitty/screen.c:1968
#2  0x00007ff21f20cedf in _PyCFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#3  0x00007ff21f285769 in ?? () from /usr/lib/libpython3.6m.so.1.0
#4  0x00007ff21f2878bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#5  0x00007ff21f284873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#6  0x00007ff21f285625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#7  0x00007ff21f2878bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#8  0x00007ff21f284873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#9  0x00007ff21f28d2fb in _PyFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#10 0x00007ff21f1c5081 in _PyObject_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#11 0x00007ff21f1c52ec in _PyObject_Call_Prepend () from /usr/lib/libpython3.6m.so.1.0
#12 0x00007ff21f1c4fd9 in _PyObject_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#13 0x00007ff21f1c5bb8 in _PyObject_CallMethod_SizeT () from /usr/lib/libpython3.6m.so.1.0
#14 0x00007ff21e2aaacf in screen_update_selection (self=0x7ff1e7cd3010, x=<optimized out>, y=<optimized out>, 
    ended=ended@entry=true) at /home/solitude/git/kitty/kitty/screen.c:2143
#15 0x00007ff21e2badd4 in update_drag (modifiers=0, is_release=true, w=<optimized out>, from_button=true)
    at /home/solitude/git/kitty/kitty/mouse.c:169
#16 mouse_event (button=button@entry=0, modifiers=modifiers@entry=0, action=<optimized out>, action@entry=0)
    at /home/solitude/git/kitty/kitty/mouse.c:534
#17 0x00007ff21e2de26b in mouse_button_callback (w=0x56007ad71b10, button=0, action=0, mods=0)
    at /home/solitude/git/kitty/kitty/glfw.c:222
#18 0x00007ff21c5e70e4 in _glfwInputMouseClick (window=<optimized out>, button=button@entry=0, action=action@entry=0, 
    mods=<optimized out>) at /home/solitude/git/kitty/glfw/input.c:311
#19 0x00007ff21c5f2dc3 in processEvent (event=event@entry=0x7ffd06cd4940)
    at /home/solitude/git/kitty/glfw/x11_window.c:1267
#20 0x00007ff21c5f364c in dispatch_x11_queued_events () at /home/solitude/git/kitty/glfw/x11_window.c:2508
#21 _glfwDispatchX11Events () at /home/solitude/git/kitty/glfw/x11_window.c:2523
#22 0x00007ff21c5f3785 in handleEvents (timeout=<optimized out>) at /home/solitude/git/kitty/glfw/x11_window.c:66
#23 0x00007ff21c5f37b4 in _glfwPlatformWaitEvents () at /home/solitude/git/kitty/glfw/x11_window.c:2555
#24 0x00007ff21c5ee5a5 in _glfwPlatformRunMainLoop (tick_callback=0x7ff21e312a2a <process_global_state>, 
    data=0x7ff21c85c990) at /home/solitude/git/kitty/glfw/main_loop.h:30
#25 0x00007ff21c5e6849 in glfwRunMainLoop (callback=<optimized out>, data=<optimized out>)
    at /home/solitude/git/kitty/glfw/init.c:342
#26 0x00007ff21e2df64c in run_main_loop (cb=cb@entry=0x7ff21e312a2a <process_global_state>, 
    cb_data=cb_data@entry=0x7ff21c85c990) at /home/solitude/git/kitty/kitty/glfw.c:1136
#27 0x00007ff21e30f6e6 in main_loop (self=0x7ff21c85c990, a=<optimized out>)
    at /home/solitude/git/kitty/kitty/child-monitor.c:955
#28 0x00007ff21f20cedf in _PyCFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#29 0x00007ff21f285769 in ?? () from /usr/lib/libpython3.6m.so.1.0
#30 0x00007ff21f2878bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#31 0x00007ff21f28529a in ?? () from /usr/lib/libpython3.6m.so.1.0
#32 0x00007ff21f285413 in ?? () from /usr/lib/libpython3.6m.so.1.0
#33 0x00007ff21f285625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#34 0x00007ff21f2878bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#35 0x00007ff21f28529a in ?? () from /usr/lib/libpython3.6m.so.1.0
#36 0x00007ff21f285413 in ?? () from /usr/lib/libpython3.6m.so.1.0
#37 0x00007ff21f285625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#38 0x00007ff21f2878bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#39 0x00007ff21f284873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#40 0x00007ff21f285625 in ?? () from /usr/lib/libpython3.6m.so.1.0
--Type <RET> for more, q to quit, c to continue without paging--
#41 0x00007ff21f2878bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#42 0x00007ff21f284873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#43 0x00007ff21f285625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#44 0x00007ff21f2878bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#45 0x00007ff21f284873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#46 0x00007ff21f285625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#47 0x00007ff21f2878bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#48 0x00007ff21f28529a in ?? () from /usr/lib/libpython3.6m.so.1.0
#49 0x00007ff21f2857ce in PyEval_EvalCodeEx () from /usr/lib/libpython3.6m.so.1.0
#50 0x00007ff21f2857fb in PyEval_EvalCode () from /usr/lib/libpython3.6m.so.1.0
#51 0x00007ff21f2826ad in ?? () from /usr/lib/libpython3.6m.so.1.0
#52 0x00007ff21f20cf2b in _PyCFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#53 0x00007ff21f285769 in ?? () from /usr/lib/libpython3.6m.so.1.0
#54 0x00007ff21f2878bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#55 0x00007ff21f28529a in ?? () from /usr/lib/libpython3.6m.so.1.0
#56 0x00007ff21f285413 in ?? () from /usr/lib/libpython3.6m.so.1.0
#57 0x00007ff21f285625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#58 0x00007ff21f2878bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#59 0x00007ff21f28529a in ?? () from /usr/lib/libpython3.6m.so.1.0
#60 0x00007ff21f2857ce in PyEval_EvalCodeEx () from /usr/lib/libpython3.6m.so.1.0
#61 0x00007ff21f1ee626 in ?? () from /usr/lib/libpython3.6m.so.1.0
#62 0x00007ff21f1c4e68 in PyObject_Call () from /usr/lib/libpython3.6m.so.1.0
#63 0x00007ff21f2c6c1d in ?? () from /usr/lib/libpython3.6m.so.1.0
#64 0x00007ff21f2c7d41 in Py_Main () from /usr/lib/libpython3.6m.so.1.0
#65 0x0000560079cc3238 in main ()

Hmm it's an lnlined function, which is making the backtrace somewhat less helpful. Can you edit lineops.h and remove the inline keyword on line 35 andthen re-build and get a new backtrace.

uhhh

/home/solitude/git/kitty/kitty/lineops.h:36:1: error: 'xlimit_for_line' defined but not used [-Werror=unused-function]
 xlimit_for_line(Line *line) {

Oh yeah forgot that this would generate a warning. OK do slightly more involved surgery in that case, apply this patch:

```diff
diff --git a/kitty/screen.c b/kitty/screen.c
index c7a04296..22cce626 100644
--- a/kitty/screen.c
+++ b/kitty/screen.c
@@ -1567,19 +1567,33 @@ range_line_(Screen *self, int y) {
return self->linebuf->line;
}

+static index_type
+xlimit_for_line_dbg(Line *line) {

  • index_type xlimit = line->xnum;
  • printf("xlimit at start: %u\n", xlimit);
  • if (BLANK_CHAR == 0) {
  • while (xlimit > 0 && (line->cpu_cells[xlimit - 1].ch) == BLANK_CHAR) xlimit--;
  • printf("xlimit before wide check: %u\n", xlimit);
  • if (xlimit < line->xnum && (line->gpu_cells[xlimit > 0 ? xlimit - 1 : xlimit].attrs & WIDTH_MASK) == 2) xlimit++;
  • printf("xlimit after wide check: %u\n", xlimit);
  • }
  • return xlimit;
    +}
    +
    +
    #define iterate_over_rectangle(start, end, line_func, y_type) { \
    y_type min_y = MIN(start->y, end->y), max_y = MAX(start->y, end->y); \
    index_type min_x = MIN(start->x, end->x), max_x = MAX(start->x, end->x); \
    for (y_type y = min_y; y <= max_y; y++) { \
    Line *line = line_func(self, y); \
  • index_type xlimit = xlimit_for_line(line); \
  • index_type xlimit = xlimit_for_line_dbg(line); \
    xlimit = MIN(max_x + 1, xlimit); \
    index_type x_start = min_x;

#define iterate_over_region(start, end, line_func, y_type) { \
for (y_type y = start->y; y <= end->y; y++) { \
Line *line = line_func(self, y); \
- index_type xlimit = xlimit_for_line(line); \
+ index_type xlimit = xlimit_for_line_dbg(line); \
if (y == end->y) xlimit = MIN(end->x + 1, xlimit); \
index_type x_start = y == start->y ? start->x : 0;
```

this hsould make the backtrace more useful and also print out some debugging info to stdout.

#0  0x00007f6f58a0fd0a in xlimit_for_line_dbg (line=line@entry=0x7f6f571fa660)
    at /home/solitude/git/kitty/kitty/screen.c:1576
1576            while (xlimit > 0 && (line->cpu_cells[xlimit - 1].ch) == BLANK_CHAR) xlimit--;
[Current thread is 1 (Thread 0x7f6f5959e6c0 (LWP 19375))]
(gdb) bt
#0  0x00007f6f58a0fd0a in xlimit_for_line_dbg (line=line@entry=0x7f6f571fa660)
    at /home/solitude/git/kitty/kitty/screen.c:1576
#1  0x00007f6f58a113bd in text_for_selection (self=0x7f6f1e3e6010, a=<optimized out>)
    at /home/solitude/git/kitty/kitty/screen.c:1982
#2  0x00007f6f59983edf in _PyCFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#3  0x00007f6f599fc769 in ?? () from /usr/lib/libpython3.6m.so.1.0
#4  0x00007f6f599fe8bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#5  0x00007f6f599fb873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#6  0x00007f6f599fc625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#7  0x00007f6f599fe8bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#8  0x00007f6f599fb873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#9  0x00007f6f59a042fb in _PyFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#10 0x00007f6f5993c081 in _PyObject_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#11 0x00007f6f5993c2ec in _PyObject_Call_Prepend () from /usr/lib/libpython3.6m.so.1.0
#12 0x00007f6f5993bfd9 in _PyObject_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#13 0x00007f6f5993cbb8 in _PyObject_CallMethod_SizeT () from /usr/lib/libpython3.6m.so.1.0
#14 0x00007f6f58a17d81 in screen_update_selection (self=0x7f6f1e3e6010, x=<optimized out>, y=<optimized out>, 
    ended=ended@entry=true) at /home/solitude/git/kitty/kitty/screen.c:2157
#15 0x00007f6f58a3b3f8 in update_drag (modifiers=0, is_release=true, w=<optimized out>, from_button=true)
    at /home/solitude/git/kitty/kitty/mouse.c:169
#16 mouse_event (button=button@entry=0, modifiers=modifiers@entry=0, action=<optimized out>, action@entry=0)
    at /home/solitude/git/kitty/kitty/mouse.c:534
#17 0x00007f6f58a1e1f3 in mouse_button_callback (w=0x558b90fa1e40, button=0, action=0, mods=0)
    at /home/solitude/git/kitty/kitty/glfw.c:223
#18 0x00007f6f56d5e0e4 in _glfwInputMouseClick (window=<optimized out>, button=button@entry=0, action=action@entry=0, 
    mods=<optimized out>) at /home/solitude/git/kitty/glfw/input.c:311
#19 0x00007f6f56d69dc3 in processEvent (event=event@entry=0x7fff4e9ae700)
    at /home/solitude/git/kitty/glfw/x11_window.c:1267
#20 0x00007f6f56d6a64c in dispatch_x11_queued_events () at /home/solitude/git/kitty/glfw/x11_window.c:2508
#21 _glfwDispatchX11Events () at /home/solitude/git/kitty/glfw/x11_window.c:2523
#22 0x00007f6f56d6a785 in handleEvents (timeout=<optimized out>) at /home/solitude/git/kitty/glfw/x11_window.c:66
#23 0x00007f6f56d6a7b4 in _glfwPlatformWaitEvents () at /home/solitude/git/kitty/glfw/x11_window.c:2555
#24 0x00007f6f56d655a5 in _glfwPlatformRunMainLoop (tick_callback=0x7f6f58a2519e <process_global_state>, 
    data=0x7f6f56fd2990) at /home/solitude/git/kitty/glfw/main_loop.h:30
#25 0x00007f6f56d5d849 in glfwRunMainLoop (callback=<optimized out>, data=<optimized out>)
    at /home/solitude/git/kitty/glfw/init.c:342
#26 0x00007f6f58a1f5e3 in run_main_loop (cb=cb@entry=0x7f6f58a2519e <process_global_state>, 
    cb_data=cb_data@entry=0x7f6f56fd2990) at /home/solitude/git/kitty/kitty/glfw.c:1137
#27 0x00007f6f58a21e5a in main_loop (self=0x7f6f56fd2990, a=<optimized out>)
    at /home/solitude/git/kitty/kitty/child-monitor.c:960
#28 0x00007f6f59983edf in _PyCFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#29 0x00007f6f599fc769 in ?? () from /usr/lib/libpython3.6m.so.1.0
#30 0x00007f6f599fe8bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#31 0x00007f6f599fc29a in ?? () from /usr/lib/libpython3.6m.so.1.0
#32 0x00007f6f599fc413 in ?? () from /usr/lib/libpython3.6m.so.1.0
#33 0x00007f6f599fc625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#34 0x00007f6f599fe8bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#35 0x00007f6f599fc29a in ?? () from /usr/lib/libpython3.6m.so.1.0
#36 0x00007f6f599fc413 in ?? () from /usr/lib/libpython3.6m.so.1.0
#37 0x00007f6f599fc625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#38 0x00007f6f599fe8bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
--Type <RET> for more, q to quit, c to continue without paging--
#39 0x00007f6f599fb873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#40 0x00007f6f599fc625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#41 0x00007f6f599fe8bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#42 0x00007f6f599fb873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#43 0x00007f6f599fc625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#44 0x00007f6f599fe8bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#45 0x00007f6f599fb873 in ?? () from /usr/lib/libpython3.6m.so.1.0
#46 0x00007f6f599fc625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#47 0x00007f6f599fe8bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#48 0x00007f6f599fc29a in ?? () from /usr/lib/libpython3.6m.so.1.0
#49 0x00007f6f599fc7ce in PyEval_EvalCodeEx () from /usr/lib/libpython3.6m.so.1.0
#50 0x00007f6f599fc7fb in PyEval_EvalCode () from /usr/lib/libpython3.6m.so.1.0
#51 0x00007f6f599f96ad in ?? () from /usr/lib/libpython3.6m.so.1.0
#52 0x00007f6f59983f2b in _PyCFunction_FastCallDict () from /usr/lib/libpython3.6m.so.1.0
#53 0x00007f6f599fc769 in ?? () from /usr/lib/libpython3.6m.so.1.0
#54 0x00007f6f599fe8bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#55 0x00007f6f599fc29a in ?? () from /usr/lib/libpython3.6m.so.1.0
#56 0x00007f6f599fc413 in ?? () from /usr/lib/libpython3.6m.so.1.0
#57 0x00007f6f599fc625 in ?? () from /usr/lib/libpython3.6m.so.1.0
#58 0x00007f6f599fe8bb in _PyEval_EvalFrameDefault () from /usr/lib/libpython3.6m.so.1.0
#59 0x00007f6f599fc29a in ?? () from /usr/lib/libpython3.6m.so.1.0
#60 0x00007f6f599fc7ce in PyEval_EvalCodeEx () from /usr/lib/libpython3.6m.so.1.0
#61 0x00007f6f59965626 in ?? () from /usr/lib/libpython3.6m.so.1.0
#62 0x00007f6f5993be68 in PyObject_Call () from /usr/lib/libpython3.6m.so.1.0
#63 0x00007f6f59a3dc1d in ?? () from /usr/lib/libpython3.6m.so.1.0
#64 0x00007f6f59a3ed41 in Py_Main () from /usr/lib/libpython3.6m.so.1.0
#65 0x0000558b8fd31238 in main ()

And what was the output on stdout in the terminal from which you ran kitty

xlimit before wide check: 118
xlimit after wide check: 118
xlimit at start: 119
xlimit before wide check: 118
xlimit after wide check: 118
xlimit at start: 119
xlimit before wide check: 118
xlimit after wide check: 118
xlimit at start: 119
xlimit before wide check: 118
xlimit after wide check: 118
xlimit at start: 119
Segmentation fault (core dumped)

xlimit statements repeated with same values

Hmm that indicates there is some memory corruption happening somewhere,
unfortunately not in the xlimit_for_line function. The only way that can
crash is if line->cpu_cells is not valid. Change

printf("xlimit at start: %u\n", xlimit);

to

printf("xlimit at start: %u and cpu_cells: %p\n", xlimit, (void*)line->cpu_cells);

that should confirm that my hypothesis is correct. Also could you make a
short screencap video of exactly what you are doing to cause this crash,
it would be really helpful if I could reproduce it.

xlimit at start: 240 and cpu_cells: 0x55db4ee1d430
xlimit before wide check: 240
xlimit after wide check: 240
xlimit at start: 240 and cpu_cells: 0x55db4ee1d430
xlimit before wide check: 240
xlimit after wide check: 240
xlimit at start: 240 and cpu_cells: 0x55db4ee1d430
xlimit before wide check: 240
xlimit after wide check: 240
xlimit at start: 240 and cpu_cells: 0x55db4ee34b30
xlimit before wide check: 240
xlimit after wide check: 240
xlimit at start: 240 and cpu_cells: 0x55db4ee1d430
xlimit before wide check: 240
xlimit after wide check: 240
xlimit at start: 240 and cpu_cells: 0x55db4ee1d430
xlimit before wide check: 240
xlimit after wide check: 240
xlimit at start: 240 and cpu_cells: 0x55db4ee1d430
xlimit before wide check: 240
xlimit after wide check: 240
xlimit at start: 240 and cpu_cells: 0x55df40b03430

https://streamable.com/2ppwm

Thanks, that does confirm my hypothesis. Sadly this is going to be a bear to debug without being able to reproduce and your video just shows you doing what I was.

There may be some good news - I'm seeing a similar crash, without using any kittens on latest release. It's essentially some sort of mouse movement - not sure what it is exactly since I'm not doing it intentionally. I'll be pulling master, compiling with debug symbols and waiting for it to happen again. It may be - and this is a guess based on nothing - that this is where the original problem is.

It's definitely not kitten related, since mouse selection happens purely
in kitty. The problem is to come up with some way of at least semi-reliably
triggerring it, I haven't been able to trigger it at all, and sadly the
backtrace does not provide enough information to isolate the root cause.

Yes, I'm not able to repeatably trigger it either. Are you doing anything funky with threading+CPython? This sort of heisenbug is usually a race of some kind

Thinking out loud here without having read any of the code, but is there a way to instrument the mouse support to keep a short history of events that can be extracted from a coredump subsequently? This would possibly give us reproducibility relatively cheaply.

I'm thinking of a way I can help you debug this since I hate posting an issue and not posting a patch, especially for something I use daily, but frankly I don't have room in my brain for the kitty codebase at the moment - lovely, well-structured and easy to understand as I'm sure it must be ;)

Nope, no threads. There is an I/O thread for processing input from child processes, but that has no relevance here and it's not a python thread in any-case. If you can trigger it sporadically, it might help if you simply built kitty with ASAN and ran it, that might give more hints about the cause.

See https://sw.kovidgoyal.net/kitty/build.html

you need to run

make asan

and use

./san-launcher to run kitty

That makes sense. Ideally it would be done by the guy who can reliably elicit a sigsegv rather than me who has to wait a couple weeks for one.. ;)

I've managed to make this crash consistently. I'm using i3, and my process is:

  • Run ./asan-launcher .
  • In the new window, run ./asan-launcher . +kitten diff asan-launcher.c gen-apc-parsers.py
  • Scroll to the bottom of the right page, select some text and scroll to the top, and release mouse
  • If it hasn't crashed by now, resizing the window crashes it instantly
AddressSanitizer:DEADLYSIGNAL
=================================================================
==18869==ERROR: AddressSanitizer: SEGV on unknown address 0x632003439ef8 (pc 0x7f65f7ba85a4 bp 0x7ffc59eb12d0 sp 0x7ffc59eb1130 T0)
==18869==The signal is caused by a READ memory access.
    #0 0x7f65f7ba85a3 in xlimit_for_line /home/zuzi/kitty/kitty/lineops.h:39
    #1 0x7f65f7ba85a3 in text_for_selection /home/zuzi/kitty/kitty/screen.c:1986
    #2 0x7f65fc53cf60 in _PyMethodDef_RawFastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x154f60)
    #3 0x7f65fc5690ee in _PyMethodDescr_FastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x1810ee)
    #4 0x7f65fc5ad8b2 in _PyEval_EvalFrameDefault (/usr/lib/libpython3.7m.so.1.0+0x1c58b2)
    #5 0x7f65fc53c6da in _PyFunction_FastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x1546da)
    #6 0x7f65fc5a9031 in _PyEval_EvalFrameDefault (/usr/lib/libpython3.7m.so.1.0+0x1c1031)
    #7 0x7f65fc4f6dba in _PyFunction_FastCallDict (/usr/lib/libpython3.7m.so.1.0+0x10edba)
    #8 0x7f65fc506817 in _PyObject_Call_Prepend (/usr/lib/libpython3.7m.so.1.0+0x11e817)
    #9 0x7f65fc4f56a1 in _PyObject_FastCallDict (/usr/lib/libpython3.7m.so.1.0+0x10d6a1)
    #10 0x7f65fc578b5e in _PyObject_CallMethod_SizeT (/usr/lib/libpython3.7m.so.1.0+0x190b5e)
    #11 0x7f65f7bddeda in screen_update_selection /home/zuzi/kitty/kitty/screen.c:2165
    #12 0x7f65f7b5e594 in update_drag /home/zuzi/kitty/kitty/mouse.c:169
    #13 0x7f65f7b5e594 in mouse_event /home/zuzi/kitty/kitty/mouse.c:534
    #14 0x7f65f7c644df in mouse_button_callback /home/zuzi/kitty/kitty/glfw.c:237
    #15 0x7f65f66250bb in _glfwInputMouseClick /home/zuzi/kitty/glfw/input.c:311
    #16 0x7f65f665cdaf in processEvent /home/zuzi/kitty/glfw/x11_window.c:1270
    #17 0x7f65f6660976 in dispatch_x11_queued_events /home/zuzi/kitty/glfw/x11_window.c:2494
    #18 0x7f65f6660976 in _glfwDispatchX11Events /home/zuzi/kitty/glfw/x11_window.c:2509
    #19 0x7f65f6660fd8 in handleEvents /home/zuzi/kitty/glfw/x11_window.c:66
    #20 0x7f65f6661004 in _glfwPlatformWaitEvents /home/zuzi/kitty/glfw/x11_window.c:2541
    #21 0x7f65f66413af in _glfwPlatformRunMainLoop /home/zuzi/kitty/glfw/main_loop.h:30
    #22 0x7f65f66225d2 in glfwRunMainLoop /home/zuzi/kitty/glfw/init.c:342
    #23 0x7f65f7c6a2a4 in run_main_loop /home/zuzi/kitty/kitty/glfw.c:1123
    #24 0x7f65f7cf9041 in main_loop /home/zuzi/kitty/kitty/child-monitor.c:969
    #25 0x7f65fc53cf60 in _PyMethodDef_RawFastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x154f60)
    #26 0x7f65fc5690ee in _PyMethodDescr_FastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x1810ee)
    #27 0x7f65fc5ad8b2 in _PyEval_EvalFrameDefault (/usr/lib/libpython3.7m.so.1.0+0x1c58b2)
    #28 0x7f65fc4f5d08 in _PyEval_EvalCodeWithName (/usr/lib/libpython3.7m.so.1.0+0x10dd08)
    #29 0x7f65fc53c881 in _PyFunction_FastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x154881)
    #30 0x7f65fc5a922c in _PyEval_EvalFrameDefault (/usr/lib/libpython3.7m.so.1.0+0x1c122c)
    #31 0x7f65fc4f5d08 in _PyEval_EvalCodeWithName (/usr/lib/libpython3.7m.so.1.0+0x10dd08)
    #32 0x7f65fc53c881 in _PyFunction_FastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x154881)
    #33 0x7f65fc5a922c in _PyEval_EvalFrameDefault (/usr/lib/libpython3.7m.so.1.0+0x1c122c)
    #34 0x7f65fc53c6da in _PyFunction_FastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x1546da)
    #35 0x7f65fc5a922c in _PyEval_EvalFrameDefault (/usr/lib/libpython3.7m.so.1.0+0x1c122c)
    #36 0x7f65fc53c6da in _PyFunction_FastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x1546da)
    #37 0x7f65fc5a922c in _PyEval_EvalFrameDefault (/usr/lib/libpython3.7m.so.1.0+0x1c122c)
    #38 0x7f65fc53c6da in _PyFunction_FastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x1546da)
    #39 0x7f65fc5a922c in _PyEval_EvalFrameDefault (/usr/lib/libpython3.7m.so.1.0+0x1c122c)
    #40 0x7f65fc4f5d08 in _PyEval_EvalCodeWithName (/usr/lib/libpython3.7m.so.1.0+0x10dd08)
    #41 0x7f65fc4f6c63 in PyEval_EvalCodeEx (/usr/lib/libpython3.7m.so.1.0+0x10ec63)
    #42 0x7f65fc4f6c8b in PyEval_EvalCode (/usr/lib/libpython3.7m.so.1.0+0x10ec8b)
    #43 0x7f65fc5bfa0c  (/usr/lib/libpython3.7m.so.1.0+0x1d7a0c)
    #44 0x7f65fc53cef2 in _PyMethodDef_RawFastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x154ef2)
    #45 0x7f65fc53d100 in _PyCFunction_FastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x155100)
    #46 0x7f65fc5ad551 in _PyEval_EvalFrameDefault (/usr/lib/libpython3.7m.so.1.0+0x1c5551)
    #47 0x7f65fc4f5d08 in _PyEval_EvalCodeWithName (/usr/lib/libpython3.7m.so.1.0+0x10dd08)
    #48 0x7f65fc53c881 in _PyFunction_FastCallKeywords (/usr/lib/libpython3.7m.so.1.0+0x154881)
    #49 0x7f65fc5a922c in _PyEval_EvalFrameDefault (/usr/lib/libpython3.7m.so.1.0+0x1c122c)
    #50 0x7f65fc4f5d08 in _PyEval_EvalCodeWithName (/usr/lib/libpython3.7m.so.1.0+0x10dd08)
    #51 0x7f65fc4f6f8b in _PyFunction_FastCallDict (/usr/lib/libpython3.7m.so.1.0+0x10ef8b)
    #52 0x7f65fc624dd6  (/usr/lib/libpython3.7m.so.1.0+0x23cdd6)
    #53 0x7f65fc626465  (/usr/lib/libpython3.7m.so.1.0+0x23e465)
    #54 0x7f65fc4c0b52 in Py_Main (/usr/lib/libpython3.7m.so.1.0+0xd8b52)
    #55 0x55c86f50b5ba in main /home/zuzi/kitty/asan-launcher.c:16
    #56 0x7f65fb71bce2 in __libc_start_main (/usr/lib/libc.so.6+0x23ce2)
    #57 0x55c86f50b17d in _start (/home/zuzi/kitty/asan-launcher+0x217d)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/zuzi/kitty/kitty/lineops.h:39 in xlimit_for_line
==18869==ABORTING

Doesn't crash for me with those steps, you are scrolling using the mouse wheel, correct?

Note that the fix I just made is speculative, since I cant reproduce the crash.

I can confirm at least on my setup, it seems to be fixed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hdriqi picture hdriqi  路  3Comments

jasminabasurita picture jasminabasurita  路  3Comments

Askannz picture Askannz  路  3Comments

drandreaskrueger picture drandreaskrueger  路  4Comments

metalelf0 picture metalelf0  路  4Comments