Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Improve crash stacktraces #14

Merged
merged 2 commits into from
Aug 20, 2024
Merged

Improve crash stacktraces #14

merged 2 commits into from
Aug 20, 2024

Conversation

rr-
Copy link
Contributor

@rr- rr- commented Aug 20, 2024

To provide players with detailed stack traces, we need to embed debug information, including symbol names, into our DLL and EXE files. Recently, we've implemented platform-specific stack resolution techniques: using the backtrace library on Linux and Windows APIs on Windows. However, a challenge arises with Windows: it can only resolve symbol names from PDB-based debug information. Our compiler, MinGW, generates debug information in DWARF format (since it's based on GCC), which Windows cannot interpret. As a result, current stack traces on Windows lack meaningful information.

We have a few potential solutions to address this issue:

  • Switching to the MSVC compiler for Windows, which is impractical
  • Using the cv2pdb project, which can convert and embed PDB into EXEs
  • Developing our own stack resolver capable of parsing DWARF debug information

I had little luck with cv2pdb. It turns out, however, that there is already a project which implements the third solution – it's called dwarfstack and is available here: https://github.com/ssbssa/dwarfstack/

And so, this PR switches the Windows stack resolver from its APIs to this library. Instead of trying to link it statically via Docker's toolchain like we do for SDL and others, I found it easier to use Meson's wrap system. This mechanism lets us use external code just as if it were our own, without having to actually add it to our codebase – even if the upstream repo doesn't use Meson itself. It's really neat IMO.

Example output information from TR2X with a simulated crash in Text_DrawText:

libtrx/log_windows.c 87 Log_CrashHandler == CRASH REPORT ==
libtrx/log_windows.c 88 Log_CrashHandler EXCEPTION CODE: c0000005
libtrx/log_windows.c 89 Log_CrashHandler EXCEPTION ADDRESS: 77ce4be9
libtrx/log_windows.c 90 Log_CrashHandler STACK TRACE:
libtrx/log_windows.c 46 Log_StackTrace --- 0x77ca0000: Z:\home\rr-\work\priv\TR2X\test\TR2X.dll
libtrx/log_windows.c 58 Log_StackTrace 00. 0x77ce4be9: (/app/build/win/game/text.c:351:18) Text_DrawText
libtrx/log_windows.c 46 Log_StackTrace --- 0x77ca0000: Z:\home\rr-\work\priv\TR2X\test\TR2X.dll
libtrx/log_windows.c 58 Log_StackTrace 01. 0x77ce492c: (/app/build/win/game/text.c:312:13) Text_Draw
libtrx/log_windows.c 58 Log_StackTrace 02. 0x77cb3875: (/app/build/win/game/inventory.c:309:9) Inv_Display
libtrx/log_windows.c 58 Log_StackTrace 03. 0x77ca24d7: (/app/build/win/decomp/decomp.c:575:5) TitleSequence
libtrx/log_windows.c 58 Log_StackTrace 04. 0x77ce3530: (/app/build/win/game/shell.c:133:29) Shell_Main
libtrx/log_windows.c 58 Log_StackTrace 05. 0x77ca19d9: (/app/build/win/decomp/decomp.c:241:9) WinMain
libtrx/log_windows.c 46 Log_StackTrace --- 0x00400000: Z:\home\rr-\work\priv\TR2X\test\Tomb2.exe
libtrx/log_windows.c 52 Log_StackTrace 06. 0x00459e9e: Z:\home\rr-\work\priv\TR2X\test\Tomb2.exe
libtrx/log_windows.c 46 Log_StackTrace --- 0x7beb0000: C:\windows\system32\kernel32.dll
libtrx/log_windows.c 52 Log_StackTrace 07. 0x7bed8b5f: C:\windows\system32\kernel32.dll
libtrx/log_windows.c 46 Log_StackTrace --- 0x7bf30000: C:\windows\system32\ntdll.dll
libtrx/log_windows.c 52 Log_StackTrace 08. 0x7bf84972: C:\windows\system32\ntdll.dll
libtrx/log_windows.c 52 Log_StackTrace 09. 0x7bf853d4: C:\windows\system32\ntdll.dll
libtrx/log_windows.c 82 Log_CreateMiniDump Crash dump info put in Z:\home\rr-\work\priv\TR2X\test\TR2X.dmp

@rr- rr- requested review from a team, eikehein, lahm86 and walkawayy and removed request for a team August 20, 2024 16:23
@rr- rr- merged commit 444fd60 into main Aug 20, 2024
2 checks passed
@rr- rr- deleted the better-crashes branch August 20, 2024 17:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants