Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segmentation fault while running fatty #2

Closed
paolo-sz opened this issue Apr 22, 2020 · 34 comments
Closed

segmentation fault while running fatty #2

paolo-sz opened this issue Apr 22, 2020 · 34 comments

Comments

@paolo-sz
Copy link
Owner

paolo-sz commented Apr 22, 2020

moved from thread #1

@mskyaxl
Copy link

mskyaxl commented Apr 22, 2020

could it be the windows version? or the cygwin version that I'm using?

@paolo-sz
Copy link
Owner Author

Iit could be the issue pop-ups because of one of the things you mention but the root cause is surely something wrong in fatty code... that's the reason to try DEBUG and gdb.
BTW I'm running win10.

@mskyaxl
Copy link

mskyaxl commented Apr 22, 2020

me too: build 19041

@paolo-sz
Copy link
Owner Author

Which flavor (gcc -dumpmachine) of cygwin are you running, i686 or x86_64?
I'm using x86_64 and I never tested all the compile/execute flow on the i686 version...

@mskyaxl
Copy link

mskyaxl commented Apr 22, 2020

mosky@MOSKY-PC ~
$ gcc -dumpmachine
x86_64-pc-cygwin

@mskyaxl
Copy link

mskyaxl commented Apr 22, 2020

I will downgrade the gcc and see what's happenning :)
UPDATE: the GCC us the same gcc-g++ 9.3.0-2

@paolo-sz
Copy link
Owner Author

yes, I've updated to the latest... but still no issue.
Have you ever tried to run fatty by double-click in windows file explorer or by windows command prompt instead of cygwin terminal (this may avoid some issues, if any, with, at least, some environment variables)?

@mskyaxl
Copy link

mskyaxl commented Apr 22, 2020

Yes, I have tried to run it outside cygwin I have the same issues. I am waiting now for gdb to be installed, among others in a try to make my setup to be closer to yours.

@mskyaxl
Copy link

mskyaxl commented Apr 22, 2020

build.log

I have attached my compile log, maybe you spot something :)

@paolo-sz
Copy link
Owner Author

Are you sure you have checked-out my latest commit?
I do not see a warning that should be there if you have the latest code...

@mskyaxl
Copy link

mskyaxl commented Apr 22, 2020

I'll try again :)

Can you also can you check if you haven't missed any linked files/ignored files?

@paolo-sz
Copy link
Owner Author

paolo-sz commented Apr 22, 2020

100% match except the missing warning I'm telling you.
build.log
All committed and pushed on github.

@mskyaxl
Copy link

mskyaxl commented Apr 22, 2020

build.txt
Strange, It tells me I'm on master :)

And indeed the variable is not used

auto is_key_down = [&](uchar vk) -> bool { return GetKeyState(vk) & 0x80; };

@paolo-sz
Copy link
Owner Author

Ok, I found an issue in the code and I added some checkpoints all around in order to have a clear information of what is happening in case of such kind of issues (in the future).
Just do a pull and recompile all.
If you still have issues, recompile with DEBUG=1 and run under gdb... a message window should pop-up telling you exactly where the issue has been triggered...

@mskyaxl
Copy link

mskyaxl commented Apr 23, 2020

You are correct! This is where it has been triggered.
image

@paolo-sz
Copy link
Owner Author

paolo-sz commented Apr 23, 2020

it is hard to debug remotely... and I'm not able neither to replicate the issue nor to debug with breakpoints...
Lets try this, open winsearch.txt, go to the win_search_visible function and replace

TERM_VAR_REF(true)

with

TERM_VAR_REF(false)
if (!term_p) return false;

recompile and see what happens...

@mskyaxl
Copy link

mskyaxl commented Apr 23, 2020

no crash with the changes :)

@paolo-sz
Copy link
Owner Author

good but I fear this is only a dirty workaround... I will try to understand better what is happening here..

@mskyaxl
Copy link

mskyaxl commented Apr 23, 2020

Thanks! I will have some time tomorrow evening or saturday to do a proper debug. maybe I can help somehow.

@mskyaxl
Copy link

mskyaxl commented Apr 24, 2020

It's failing apparently on this line
image

@paolo-sz
Copy link
Owner Author

Mmmm.... seems pretty strange to me...
I'm far from understand all the mintty/fatty code but I think that the executable we run does something, forks into a child and then dies leaving the child running... and I think you catch that point, where the parent dies.
I'm pretty new to this kind of multi process debugging but googling a little bit I should have found a way to get the exact call stack at the point you get your assert.
Maybe you already know it but here is the procedure i found:

  • Get back to the faulty winsearch.c code
  • run fatty under gdb
  • the assert pop-up triggers, do not close the assert window
  • the gdb session should now be back to prompt with a message similar to "[Inferior 1 (process 15252) exited normally", leave it running as is.
  • open another terminal, run ps and take note of the PID of fatty (don't know you but I'm running the newly compiled fatty under a fatty terminal and I got two fatty process, I need to choose the right one which is pretty simple looking to their paths...)
  • move back to gdb and type attach <fatty_noted_PID>
  • now type thread 1 (maybe thread 1 is not the right thread... if so, just try with thread 2... and so on.
  • and finally bt
  • now you should see exactly the call sequence that bring you to the winsearch.c function

Let me know th result.

@mskyaxl
Copy link

mskyaxl commented Apr 25, 2020

#0  0x00007ffceb9811c4 in win32u!NtUserWaitMessage ()
   from /cygdrive/c/WINDOWS/System32/win32u.dll
#1  0x00007ffcec8cd131 in USER32!DialogBoxIndirectParamAorW ()
   from /cygdrive/c/WINDOWS/System32/USER32.dll
#2  0x00007ffcec8ccea1 in USER32!DialogBoxIndirectParamAorW ()
   from /cygdrive/c/WINDOWS/System32/USER32.dll
#3  0x00007ffcec91b8fb in USER32!SoftModalMessageBox ()
   from /cygdrive/c/WINDOWS/System32/USER32.dll
#4  0x00007ffcec91a215 in USER32!DrawStateA ()
   from /cygdrive/c/WINDOWS/System32/USER32.dll
#5  0x00007ffcec91b007 in USER32!MessageBoxTimeoutW ()
   from /cygdrive/c/WINDOWS/System32/USER32.dll
#6  0x00007ffcec91b08e in USER32!MessageBoxW ()
   from /cygdrive/c/WINDOWS/System32/USER32.dll
#7  0x0000000180043452 in __assert_func (
    file=0x100587247 <doc_info+71> "winsearch.c", line=474,
    func=<optimized out>, failedexpr=<optimized out>)
    at /usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/assert.cc:42
#8  0x0000000100467264 in win_search_visible (term_p=0x0) at winsearch.c:474
#9  0x0000000100467105 in win_update_search (term_p=0x0) at winsearch.c:448
#10 0x000000010045f40b in win_proc (wnd=0xe0784, message=794,
    wp=18446744073709551615, lp=2147483649) at winmain.c:2892
#11 0x00007ffcec8ae338 in USER32!CallWindowProcW ()
   from /cygdrive/c/WINDOWS/System32/USER32.dll
#12 0x00007ffcec8ad933 in USER32!SendMessageW ()
   from /cygdrive/c/WINDOWS/System32/USER32.dll
#13 0x00007ffcec8ad68a in USER32!SendMessageW ()
   from /cygdrive/c/WINDOWS/System32/USER32.dll
#14 0x00007ffce87f0444 in UxTheme!SetWindowTheme ()
   from /cygdrive/c/WINDOWS/system32/uxtheme.dll
#15 0x000000010045b05e in win_dark_mode (w=0xe0784) at winmain.c:1490
#16 0x000000010046479d in main (argc=1, argv=0x80005e3a0) at winmain.c:5019

Thanks! I actually did not know about this :)

@paolo-sz
Copy link
Owner Author

Great, thanks!
I'm able to get exactly your behavior now... the clue is the win10 dark mode for app (I got dark mode enabled for windows but light for app).
The function win_dark_mode is called when the terminal stuff is not yet in place and then the window main procedure win_proc is triggered when the term_p is not yet available and then the issue...
So the better patch for your issue is to move down the win_dark_mode fiunction...
I'm going to commit the fix.

paolo-sz added a commit that referenced this issue Apr 25, 2020
win_dark_mode function is called before the terminals are created.
win_proc function is then triggered when the active terminal is still NULL.
@mskyaxl
Copy link

mskyaxl commented Apr 25, 2020

great! I was on the same path playing with various configuration in my windows themes. :)

@laxamar
Copy link

laxamar commented May 9, 2020

Hi,

Using cygwin-64. Latest clone still created segfault.
How can I help debug?

lax@LAX-PRIMARY ~/src/paolo-sz/fatty/bin
$ ./fatty.exe
Segmentation fault (core dumped)`

@mskyaxl
Copy link

mskyaxl commented May 9, 2020

hi, please compile with DEBUG enabled make DEBUG=1 and try to follow instructions from this comment #2 (comment)

@laxamar
Copy link

laxamar commented May 9, 2020

Alright:

[Switching to thread 1 (Thread 19616.0x4d80)]
#0  0x00007ffe27af1224 in win32u!NtUserWaitMessage () from /cygdrive/c/WINDOWS/System32/win32u.dll
(gdb) bt
#0  0x00007ffe27af1224 in win32u!NtUserWaitMessage () from /cygdrive/c/WINDOWS/System32/win32u.dll
#1  0x00007ffe29c8bf90 in USER32!DialogBoxIndirectParamAorW () from /cygdrive/c/WINDOWS/System32/USER32.dll
#2  0x00007ffe29c8bcff in USER32!DialogBoxIndirectParamAorW () from /cygdrive/c/WINDOWS/System32/USER32.dll
#3  0x00007ffe29cd2f99 in USER32!SoftModalMessageBox () from /cygdrive/c/WINDOWS/System32/USER32.dll
#4  0x00007ffe29cd19d5 in USER32!DrawStateA () from /cygdrive/c/WINDOWS/System32/USER32.dll
#5  0x00007ffe29cd2712 in USER32!MessageBoxTimeoutW () from /cygdrive/c/WINDOWS/System32/USER32.dll
#6  0x00007ffe29cd279e in USER32!MessageBoxW () from /cygdrive/c/WINDOWS/System32/USER32.dll
#7  0x0000000180043452 in __assert_func () from /usr/bin/cygwin1.dll
#8  0x000000010045c813 in win_adapt_term_size (term_p=0x0, sync_size_with_font=true, scale_font_with_size=false) at winmain.c:1927
#9  0x000000010045d557 in font_cs_reconfig (term_p=0x0, font_changed=true) at winmain.c:2164
#10 0x0000000100465859 in main (argc=1, argv=0x80005e510) at winmain.c:5208

@laxamar
Copy link

laxamar commented May 9, 2020

fatty_assert

@paolo-sz
Copy link
Owner Author

Well this issue is mainly from the same reason of the previous one... but not so easy, at least at the first look, to solve.

Attached a patch that avoids the segfault but that is a really dirty and temporary workaround (I cannot ensure it generates other side effects) that can be used while I will look better to the problem
segfault_font_cs_reconfig.patch.txt

@paolo-sz paolo-sz reopened this May 10, 2020
paolo-sz added a commit that referenced this issue May 10, 2020
Tab terminlas created as soon as possible to avoid segfaults when calling functions that need them.
@paolo-sz
Copy link
Owner Author

Now this should be definitively (I hope) fixed...

@laxamar
Copy link

laxamar commented May 11, 2020

Fixed.

Thanks!

@laxamar
Copy link

laxamar commented May 11, 2020

Stupid unrelated question. Is there a place we can configure the tab name. It follows the path, but I want to add the server I'm attached to.
image

It's inconsistent (or at least I don't get the logic)

@paolo-sz
Copy link
Owner Author

Well, the tab title is taken from escape sequences provided by the command under execution or forced while launching fatty. By default it takes the path and name of the shell.
I agree sometime it is not really clear the logic but I never touched that functionality from the original code (fatty and mintty)... or, at least, I don't remember I ever touched that... :-)

Anyway, if you want to change it by hand you can use
echo -en "\033]2;this_is_my_title\007"

@laxamar
Copy link

laxamar commented May 11, 2020

Thanks!

Feel free to close ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants