ii8 / havoc

minimal terminal emulator for wayland
Other
103 stars 17 forks source link

maximizing window sends SIGABRT which segfaults afterwards #37

Closed matu3ba closed 2 years ago

matu3ba commented 2 years ago

Running with gdb --ex run ./havoc and maximizing (moving out of bound on upper part) in KDE Plasma on Wayland has the following behavior. Note, that resizing to halfsize (left and right side) or moving terminal out of bounds does not have the problem.

Starting program: /home/misterspoon/dev/git/c/havoc/havoc 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[Detaching after fork from child process 376481]

Program received signal SIGABRT, Aborted.
0x00007ffff7c56d22 in raise () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff7c56d22 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff7c40862 in abort () from /usr/lib/libc.so.6
#2  0x0000555555559a0f in main ()

Valgrind with valgrind ./havoc shows additionally

==376548== Process terminating with default action of signal 6 (SIGABRT): dumping core
==376548==    at 0x4A6BD22: raise (in /usr/lib/libc-2.33.so)
==376548==    by 0x4A55861: abort (in /usr/lib/libc-2.33.so)
==376548==    by 0x10DA0E: main (in /home/misterspoon/dev/git/c/havoc/havoc)
ii8 commented 2 years ago

Hm I don't use KDE myself. Maximizing or moving the window up and out works fine in sway and weston.

Could you run it with debugging symbols in gdb and tell me at which line number it aborts?

ii8 commented 2 years ago

Here is how you can make a debug version:

make clean
make CFLAGS="-g -O0"

Also there is no segfault it looks like, the program just ends because of the abort call.

matu3ba commented 2 years ago

I guess I need to dig into the KDE logs for this. Can you give me a starting point where to look for a look of screen/window actions and what caused them?

ii8 commented 2 years ago

We don't need kde logs for now, maybe later though. The first thing to find out is which abort call in havoc it is.

To do that you just have to compile a debug version of havoc like this:

make clean
make CFLAGS="-g -O0"

Then run it in gdb again and make it crash like you did before, then we will see the line number where the abort happened. That will help with finding out what is causing it.

matu3ba commented 2 years ago

on 1a5a6ce5256293631e4caf07cd498c68028df6c5

make clean
make CFLAGS="-g -O0"
gdb --ex run ./havoc
(gdb) bt
#0  0x00007ffff7c55d22 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff7c3f862 in abort () from /usr/lib/libc.so.6
#2  0x000055555555f7c7 in swap_buffers () at main.c:562
#3  0x000055555555ffd9 in redraw () at main.c:709
#4  0x0000555555562e22 in main (argc=1, argv=0x7fffffffe1b0) at main.c:1957
(gdb) l
1814                    " Use empty string for defaults.\n"
1815              "  -l         Keep window open after the child process exits.\n"
1816              "  -s <name>  Wayland display server to connect to.\n"
1817              "  -i <id>    Wayland app ID to use instead of \"havoc\".\n"
1818              "  -v         Show version information.\n"
1819              "  -h         Show this help.\n");
1820    }
1821    
1822    #define take(s) (*(argv+1) \
1823        ? *++argv \

abort() gets called here:

static struct buffer *swap_buffers(void)
{
    struct buffer *buf;

    assert(term.configured);

    if (!term.buf[0].busy)
        buf = &term.buf[0];
    else if (!term.buf[1].busy)
        buf = &term.buf[1];
    else
        abort();

    if (term.resize) {
        buffer_unmap(buf);
        if (buffer_init(buf) < 0)
            abort();
    }

    return buf;
}
ii8 commented 2 years ago

So it looks like the KDE compositor is telling havoc to redraw without releasing buffers first. I've added error messages instead of just aborting but I can't do much more I think, no way to redraw if there are no buffers to use so it will now freeze instead (which doesn't matter I guess if its offscreen).

matu3ba commented 2 years ago

works now, thanks alot!

One last question: Do you think I should file a bug upstream for this behavior?

ii8 commented 2 years ago

I will do it myself, it'll be easier for me to explain I think.

ii8 commented 2 years ago

The report is here: https://bugs.kde.org/show_bug.cgi?id=446978 @matu3ba could you add a comment there telling them the kde version and linux distro you are using, thanks.