From 8d9c45a6f6d1219831f0676baec1253cf31986f6 Mon Sep 17 00:00:00 2001 From: Andrew Eikum Date: Thu, 21 Oct 2021 09:42:40 -0500 Subject: [PATCH] steam_helper: Add PROTON_WAIT_ATTACH for debuggers to attach to game process at startup CW-Bug-Id: #19567 --- README.md | 1 + steam_helper/steam.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index c56eeba3..c338e62e 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,7 @@ the Wine prefix. Removing the option will revert to the previous behavior. | | `PROTON_LOG_DIR` | Output log files into the directory specified. Defaults to your home directory. | | | `PROTON_DUMP_DEBUG_COMMANDS` | When running a game, Proton will write some useful debug scripts for that game into `$PROTON_DEBUG_DIR/proton_$USER/`. | | | `PROTON_DEBUG_DIR` | Root directory for the Proton debug scripts, `/tmp` by default. | +| | `PROTON_WAIT_ATTACH` | Wait for a debugger to attach to steam.exe before launching the game process. To attach to the game process at startup, debuggers should be set to follow child processes. | | | `PROTON_CRASH_REPORT_DIR` | Write crash logs into this directory. Does not clean up old logs, so may eat all your disk space eventually. | | `wined3d` | `PROTON_USE_WINED3D` | Use OpenGL-based wined3d instead of Vulkan-based DXVK for d3d11, d3d10, and d3d9. | | `nod3d11` | `PROTON_NO_D3D11` | Disable `d3d11.dll`, for d3d11 games which can fall back to and run better with d3d9. | diff --git a/steam_helper/steam.cpp b/steam_helper/steam.cpp index f226e672..0c1d95fd 100644 --- a/steam_helper/steam.cpp +++ b/steam_helper/steam.cpp @@ -62,6 +62,12 @@ EXTERN_C HANDLE CDECL __wine_make_process_system(void); #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a)) +static bool env_nonzero(const char *env) +{ + const char *v = getenv(env); + return v != NULL && *v && v[0] != '0'; +} + static void set_active_process_pid(void) { DWORD pid = GetCurrentProcessId(); @@ -1177,6 +1183,22 @@ int main(int argc, char *argv[]) setup_steam_registry(); setup_steam_files(); + if (env_nonzero("PROTON_WAIT_ATTACH")) + { + unsigned int sleep_count = 0; + WINE_TRACE("PROTON_WAIT_ATTACH is set, waiting for debugger...\n"); + while (!IsDebuggerPresent()) + { + Sleep(100); + ++sleep_count; + if (sleep_count >= 10) + { + WINE_TRACE("still waiting for debugger...\n"); + sleep_count = 0; + } + } + } + wait_handle = __wine_make_process_system(); game_process = TRUE; }