forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 270
feat(crashreporting): Add optional local Crashpad backend #3413
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
Open
CryoTheRenegade
wants to merge
4
commits into
TheSuperHackers:main
Choose a base branch
from
CryoTheRenegade:feat/crashpad
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,436
−27
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5c76d20
feat(crashreporting): Add optional local Crashpad backend
CryoTheRenegade 56e944e
docs(crashpad): Keep local validation results out of the PR
CryoTheRenegade 5efe454
ci(vcpkg): Select the root dependency manifest explicitly
CryoTheRenegade ec660df
bugfix(crashreporting): Preserve fatal dumps during shutdown
CryoTheRenegade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* SPDX-License-Identifier: GPL-3.0-or-later */ | ||
| #pragma once | ||
|
|
||
| class AsciiString; | ||
|
|
||
| // Keep this interface compatible with VC6 and tools that only use MiniDumper. | ||
| namespace CrashReporting | ||
| { | ||
| void initialize(const AsciiString& userDirectory, int major, int minor, int build); | ||
| void userDirectoryReady(const AsciiString& userDirectory); | ||
| const char* backendName(); | ||
| void captureFatal(); | ||
| void shutdown(); | ||
| } |
161 changes: 161 additions & 0 deletions
161
Core/GameEngine/Source/Common/System/CrashReporting.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| /* SPDX-License-Identifier: GPL-3.0-or-later */ | ||
| // TheSuperHackers @feature Codex 01/10/2026 Select optional local Crashpad reporting with legacy MiniDumper fallback. | ||
| #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine | ||
| #include "Common/CrashReporting.h" | ||
| #include "Common/MiniDumper.h" | ||
|
|
||
| #ifdef RTS_USE_CRASHPAD | ||
| #include "CrashpadBridge.h" | ||
| #include "gitinfo.h" | ||
|
|
||
| namespace | ||
| { | ||
| RtsCrashpadCaptureFatalFunction capture; | ||
| RtsCrashpadShutdownFunction stop; | ||
| bool awaitingUserDirectory; | ||
| int savedMajor; | ||
| int savedMinor; | ||
| int savedBuild; | ||
|
|
||
| bool StartCrashpad(const AsciiString& userDirectory, int major, int minor, int build) | ||
| { | ||
| wchar_t path[32768]; | ||
| const DWORD count = GetModuleFileNameW(nullptr, path, ARRAY_SIZE(path)); | ||
| if (!count || count >= ARRAY_SIZE(path)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| wchar_t* leaf = wcsrchr(path, L'\\'); | ||
| const wchar_t name[] = L"rts_crashpad.dll"; | ||
| if (!leaf || (leaf + 1 - path) + ARRAY_SIZE(name) > ARRAY_SIZE(path)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| memcpy(leaf + 1, name, sizeof(name)); | ||
| HMODULE module = LoadLibraryExW(path, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); | ||
| if (!module) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| RtsCrashpadInitializeFunction start = reinterpret_cast<RtsCrashpadInitializeFunction>( | ||
| GetProcAddress(module, "RtsCrashpadInitialize")); | ||
| capture = reinterpret_cast<RtsCrashpadCaptureFatalFunction>(GetProcAddress(module, "RtsCrashpadCaptureFatal")); | ||
| stop = reinterpret_cast<RtsCrashpadShutdownFunction>(GetProcAddress(module, "RtsCrashpadShutdown")); | ||
| char version[64]; | ||
| snprintf(version, ARRAY_SIZE(version), "%d.%d.%d", major, minor, build); | ||
| #if RTS_ZEROHOUR | ||
| const char* game = "Zero Hour"; | ||
| #else | ||
| const char* game = "Generals"; | ||
| #endif | ||
| if (start && capture && stop && start(userDirectory.str(), game, version, GitSHA1, GitUncommittedChanges)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| // Crashpad retains process-lifetime pointers even after failed startup. | ||
| // Keep the module loaded; its initializer restores the previous filter. | ||
| capture = nullptr; | ||
| stop = nullptr; | ||
| return false; | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| void CrashReporting::initialize(const AsciiString& userDirectory, int major, int minor, int build) | ||
| { | ||
| #ifdef RTS_USE_CRASHPAD | ||
| // Generals resolves UserDataLeafName from GameData.ini during engine init. | ||
| // Zero Hour already has its registry-derived path at WinMain startup. | ||
| awaitingUserDirectory = userDirectory.isEmpty(); | ||
| savedMajor = major; | ||
| savedMinor = minor; | ||
| savedBuild = build; | ||
| if (!awaitingUserDirectory && StartCrashpad(userDirectory, major, minor, build)) | ||
| { | ||
| OutputDebugStringA("Crash reporting: Crashpad (local only)\n"); | ||
| DEBUG_LOG(("Crash reporting: Crashpad (local only)\n")); | ||
| return; | ||
| } | ||
|
|
||
| if (!awaitingUserDirectory) | ||
| { | ||
| OutputDebugStringA("Crashpad startup failed; trying MiniDumper\n"); | ||
| DEBUG_LOG(("Crashpad startup failed; trying MiniDumper\n")); | ||
| } | ||
| #endif | ||
| #ifdef RTS_ENABLE_CRASHDUMP | ||
| MiniDumper::initMiniDumper(userDirectory); | ||
| DEBUG_LOG(("Crash reporting: %s\n", backendName())); | ||
| #endif | ||
| } | ||
|
|
||
| void CrashReporting::userDirectoryReady(const AsciiString& userDirectory) | ||
| { | ||
| #ifdef RTS_USE_CRASHPAD | ||
| // Tools never call initialize(), so this cannot start Crashpad in a tool. | ||
| if (awaitingUserDirectory && !userDirectory.isEmpty()) | ||
| { | ||
| MiniDumper::shutdownMiniDumper(); | ||
| initialize(userDirectory, savedMajor, savedMinor, savedBuild); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| const char* CrashReporting::backendName() | ||
| { | ||
| #ifdef RTS_USE_CRASHPAD | ||
| if (capture) | ||
| { | ||
| return "crashpad"; | ||
| } | ||
| #endif | ||
| #ifdef RTS_ENABLE_CRASHDUMP | ||
| if (TheMiniDumper && TheMiniDumper->IsInitialized()) | ||
| { | ||
| return "minidumper"; | ||
| } | ||
| #endif | ||
|
|
||
| return "unavailable"; | ||
| } | ||
|
|
||
| void CrashReporting::captureFatal() | ||
| { | ||
| #ifdef RTS_USE_CRASHPAD | ||
| if (capture) | ||
| { | ||
| capture(); | ||
| return; | ||
| } | ||
| #endif | ||
| #ifdef RTS_ENABLE_CRASHDUMP | ||
| if (TheMiniDumper && TheMiniDumper->IsInitialized()) | ||
| { | ||
| // Preserve both minimal and full memory dumps for the legacy backend. | ||
| TheMiniDumper->TriggerMiniDump(DumpType_Minimal); | ||
| TheMiniDumper->TriggerMiniDump(DumpType_Full); | ||
| } | ||
|
|
||
| MiniDumper::shutdownMiniDumper(); | ||
| #endif | ||
| } | ||
|
|
||
| void CrashReporting::shutdown() | ||
| { | ||
| #ifdef RTS_USE_CRASHPAD | ||
| awaitingUserDirectory = false; | ||
| if (stop) | ||
| { | ||
| stop(); | ||
| stop = nullptr; | ||
| capture = nullptr; | ||
| } | ||
| #endif | ||
| #ifdef RTS_ENABLE_CRASHDUMP | ||
| MiniDumper::shutdownMiniDumper(); | ||
| #endif | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Acquire separately with this directory's manifest. Disabled builds never run | ||
| # vcpkg or look for Crashpad. A copied, pinned installed prefix works without a | ||
| # vcpkg toolchain in the game build. | ||
| set(RTS_CRASHPAD_PACKAGE_ROOT "" CACHE PATH "Pinned x86-windows-static-md Crashpad installed prefix") | ||
| set(RTS_CRASHPAD_REVISION "7e0af1d4d45b526f01677e74a56f4a951b70517d") | ||
| set(RTS_CRASHPAD_MINI_CHROMIUM_REVISION "dce72d97d1c2e9beb5e206c6a05a702269794ca3") | ||
| set(package "${RTS_CRASHPAD_PACKAGE_ROOT}") | ||
| if(NOT EXISTS "${package}/share/crashpad/vcpkg.spdx.json") | ||
| message(FATAL_ERROR "Set RTS_CRASHPAD_PACKAGE_ROOT to the x86-windows-static-md prefix built with Dependencies/Crashpad/vcpkg.json. See docs/crashpad.md.") | ||
| endif() | ||
| file(READ "${package}/share/crashpad/vcpkg.spdx.json" provenance) | ||
| foreach(required "crashpad:x86-windows-static-md@2024-04-11#7" | ||
| "${RTS_CRASHPAD_REVISION}" "${RTS_CRASHPAD_MINI_CHROMIUM_REVISION}") | ||
| string(FIND "${provenance}" "${required}" position) | ||
| if(position EQUAL -1) | ||
| message(FATAL_ERROR "Crashpad package does not match the pinned x86 package: missing ${required}") | ||
| endif() | ||
| endforeach() | ||
|
|
||
| # The baseline port's config uses these two variables even outside a vcpkg | ||
| # toolchain. Keep the workaround scoped to this dependency directory. | ||
| get_filename_component(_VCPKG_INSTALLED_DIR "${package}" DIRECTORY) | ||
| get_filename_component(VCPKG_TARGET_TRIPLET "${package}" NAME) | ||
| list(PREPEND CMAKE_PREFIX_PATH "${package}") | ||
| find_package(crashpad CONFIG REQUIRED PATHS "${package}/share/crashpad" NO_DEFAULT_PATH) | ||
| set(handler "${package}/tools/crashpad/crashpad_handler.exe") | ||
| if(NOT EXISTS "${handler}") | ||
| message(FATAL_ERROR "The pinned package is missing its matching crashpad_handler.exe") | ||
| endif() | ||
| set(RTS_CRASHPAD_HANDLER "${handler}" PARENT_SCOPE) | ||
|
|
||
| # Deploy the redistributable x86 VC runtime from the selected Visual Studio. | ||
| # The Windows 10+ Universal CRT is supplied by the OS. Debug builds still need | ||
| # a developer installation of the non-redistributable debug CRT. | ||
| set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE) | ||
| include(InstallRequiredSystemLibraries) | ||
| if(NOT CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS) | ||
| message(FATAL_ERROR "The Visual Studio x86 redistributable runtime was not found") | ||
| endif() | ||
| set(RTS_CRASHPAD_RUNTIME_FILES "${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}" PARENT_SCOPE) | ||
|
|
||
| add_library(rts_crashpad SHARED CrashpadBridge.cpp CrashpadBridge.h CrashpadBridge.def) | ||
| target_compile_features(rts_crashpad PRIVATE cxx_std_20) | ||
| target_link_libraries(rts_crashpad PRIVATE crashpad::crashpad) | ||
| set_target_properties(rts_crashpad PROPERTIES | ||
| MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" | ||
| DISABLE_PRECOMPILE_HEADERS ON) | ||
| target_compile_options(rts_crashpad PRIVATE /Zi) | ||
| target_link_options(rts_crashpad PRIVATE /DEBUG) | ||
| target_compile_definitions(rts_crashpad PRIVATE | ||
| "RTS_CRASHPAD_COMPILER=\"${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}\"" | ||
| "RTS_CRASHPAD_CONFIGURATION=\"$<CONFIG>\"" | ||
| "RTS_CRASHPAD_REVISION=\"${RTS_CRASHPAD_REVISION}\"") | ||
|
|
||
| set(notices "${CMAKE_CURRENT_BINARY_DIR}/notices") | ||
| file(MAKE_DIRECTORY "${notices}") | ||
| configure_file("${package}/share/crashpad/copyright" "${notices}/crashpad-LICENSE" COPYONLY) | ||
| configure_file("${package}/share/zlib/copyright" "${notices}/zlib-LICENSE" COPYONLY) | ||
| configure_file("${package}/share/crashpad/vcpkg.spdx.json" "${notices}/crashpad-package.spdx.json" COPYONLY) | ||
| configure_file("${package}/share/zlib/vcpkg.spdx.json" "${notices}/zlib-package.spdx.json" COPYONLY) | ||
| configure_file("${package}/share/crashpad/vcpkg_abi_info.txt" "${notices}/crashpad-package-abi.txt" COPYONLY) | ||
| configure_file(getopt-LICENSE "${notices}/getopt-LICENSE" COPYONLY) | ||
| configure_file(mini-chromium-LICENSE "${notices}/mini-chromium-LICENSE" COPYONLY) | ||
| set(RTS_CRASHPAD_NOTICES "${notices}" PARENT_SCOPE) | ||
|
|
||
| add_executable(rts_crashpad_reports CrashpadReports.cpp) | ||
| target_compile_features(rts_crashpad_reports PRIVATE cxx_std_20) | ||
| target_link_libraries(rts_crashpad_reports PRIVATE crashpad::crashpad) | ||
| set_target_properties(rts_crashpad_reports PROPERTIES | ||
| MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL") | ||
|
|
||
| if(RTS_BUILD_CRASHPAD_TESTS) | ||
| add_subdirectory(tests) | ||
| endif() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.