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

Fix Windows arm64 build #371

Merged
merged 10 commits into from
Jul 9, 2024
Merged

Fix Windows arm64 build #371

merged 10 commits into from
Jul 9, 2024

Conversation

madebr
Copy link
Collaborator

@madebr madebr commented Jun 17, 2024

I disabled the ci job, but when enabled it would look as follows:
https://github.com/madebr/dethrace/actions/runs/9550571423

Also, it's completely untested

Copy link

@ArminiusTux ArminiusTux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these changes dethrace now successfully compiles und runs under Windows on ARM (Win 11 v23H2).

Tested with MSVC (VS v17.10.3) & Clang v18.1.6.

@ArminiusTux
Copy link

ArminiusTux commented Jun 22, 2024

Thank you @madebr for this fix!

dethrace
How about a neat icon for this game - maybe @Toshiba-3 or @Memorix101 could help?

@madebr
Copy link
Collaborator Author

madebr commented Jun 22, 2024

Thank you @madebr for this fix! How about a neat icon for this game - maybe @Toshiba-3 or @Memorix101 could help?

Great to hear!
The arm64 incompatibility was in the error reporting code, which you hopefully never see.
You'd need to purposefully add a crashing bug to the game to verify my fixes are correct.
If they are working, the code should print a stacktrace of the crash location.

@dethrace-labs
Perhaps we should use dbghelp instead: CaptureStackBackTrace, Syminitialize, SymFromAddr and SymGetLineFromAddr are way simpler and not architecture dependent.
They are used in the SDL tests to track memory allocations (and detect leaks).
(Or perhaps these are not useful)

@dethrace-labs
Copy link
Owner

@madebr agreed - when I had a quick look on this issue I thought CaptureStackBackTrace et all would be much simpler.

@ArminiusTux for the icon I’m working on building a proper app package for MacOS and as part of that will include the windows icon config

@madebr
Copy link
Collaborator Author

madebr commented Jul 1, 2024

I looked into stacktrace generation past weekend, and I don't think CaptureStackBackTrace is useful here.
That function captures the stack of the current thread stack where in an error state, we want to print the stack of another failing thread stack.
CaptureStackBackTrace is useful for assert-like functions to show where the assertion failed, and how you got there.

I used these somewhat complicated functions to print stacktraces of crashed child processes on ci.
https://github.com/libsdl-org/SDL/blob/main/test/win32/sdlprocdump.c
(a few tests of SDL2/SDL3 very occasionally segfault on ci and nobody has been able to reproduce it)

#elif defined(DETHRACE_CPU_ARM64)
void *addr = (void*)ExceptionInfo->ContextRecord->Pc;
#endif
addr2line(windows_program_name, addr);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rely on having an addr2line executable on windows? We shouldn't use SymGetLineFromAddr64 or something instead?

Copy link
Collaborator Author

@madebr madebr Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. That's an error (addr2line).
I'll fix it using functions from DbgHelp.

@madebr
Copy link
Collaborator Author

madebr commented Jul 5, 2024

My latest changes will also print a stacktrace-like on wine where dbghelp is not 100% supported, and when addr2line.exe does not exist:

Dethrace version: v0.7.1-13-g0ad96de2
Using root directory: \home\maarten\projects\dethrace\cmake-build-debug-mingw64\
Game mode: Carmageddon
Error: EXCEPTION_INT_DIVIDE_BY_ZERO
0: Z:\home\maarten\projects\dethrace\cmake-build-debug-mingw64\dethrace.exe 0x40126f20
1: Z:\home\maarten\projects\dethrace\cmake-build-debug-mingw64\dethrace.exe 0x400012ee
2: Z:\home\maarten\projects\dethrace\cmake-build-debug-mingw64\dethrace.exe 0x400013e6
3: C:\windows\system32\kernel32.dll 0xffa88c79
4: C:\windows\system32\ntdll.dll 0xffc86e8f

This is how it looks like on Windows with MSVC:

Error: EXCEPTION_INT_DIVIDE_BY_ZERO
0: dethrace!main+0x151 C:\Users\maarten\source\repos\dethrace\src\DETHRACE\main.c Line 48
1: dethrace!invoke_main+0x39 D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl Line 79
2: dethrace!__scrt_common_main_seh+0x12e D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl Line 288
3: dethrace!__scrt_common_main+0xe D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl Line 331
4: dethrace!mainCRTStartup+0xe D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp Line 17
5: C:\WINDOWS\System32\KERNEL32.DLL 0x6ba77344
6: C:\WINDOWS\SYSTEM32\ntdll.dll 0x6ce7cc91

This is how it looks like with MingW on Windows with no addr2line:

Error: EXCEPTION_INT_DIVIDE_BY_ZERO
0: C:\Users\maarten\source\repos\dethrace\build\Debug-mingw\dethrace.exe 0x8629580a
1: C:\Users\maarten\source\repos\dethrace\build\Debug-mingw\dethrace.exe 0x8617143f
2: C:\Users\maarten\source\repos\dethrace\build\Debug-mingw\dethrace.exe 0x86171117
3: C:\WINDOWS\System32\KERNEL32.DLL 0x6ba77344
4: C:\WINDOWS\SYSTEM32\ntdll.dll 0x6ce7cc91

I kept addr2line support, but it will only be used when the environment variable ADDR2LINE is set (and an addr2line executable actually exists).
It always prints the following on my Windows system:

Error: EXCEPTION_INT_DIVIDE_BY_ZERO
0: ?? ??:0
1: ?? ??:0
2: ?? ??:0
3: ?? ??:0
4: ?? ??:0

edit:
The last commit also prints the address, and changes the MSVC output to

0: 0x9dcd40b1 dethrace!main+0x151 C:\Users\maarten\source\repos\dethrace\src\DETHRACE\main.c Line 48
1: 0x9debf9a9 dethrace!invoke_main+0x39 D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl Line 79
2: 0x9debf84e dethrace!__scrt_common_main_seh+0x12e D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl Line 288
3: 0x9debf70e dethrace!__scrt_common_main+0xe D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl Line 331
4: 0x9debfa3e dethrace!mainCRTStartup+0xe D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp Line 17
5: 0x6ba77344 KERNEL32!BaseThreadInitThunk+0x14
6: 0x6ce7cc91 ntdll!RtlUserThreadStart+0x21

@madebr madebr merged commit e3a50e3 into dethrace-labs:main Jul 9, 2024
6 checks passed
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

Successfully merging this pull request may close these issues.

3 participants