From 7ad7496923aadc50deff627a3170a52e7c2bb490 Mon Sep 17 00:00:00 2001 From: Ben Hoffman Date: Sat, 8 Aug 2026 12:17:47 -0400 Subject: [PATCH] Add -WaitForDebugger command line flag (issue #178) Adds a cross-platform F_DEBUG_BREAK() macro (MSVC __debugbreak, Clang __builtin_debugtrap, GCC raise(SIGTRAP)) and wires -WaitForDebugger=true into Engine::Startup right after FlingConfig::Get().Init(), so a debugger can catch the process early in startup on any platform. Verified under gdb: hits the trap exactly at that line when the flag is set, and is a no-op when it's not. Co-Authored-By: Claude Sonnet 5 --- FlingEngine/Core/inc/Engine.h | 15 +++++++++++++++ FlingEngine/Core/src/Engine.cpp | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/FlingEngine/Core/inc/Engine.h b/FlingEngine/Core/inc/Engine.h index b5678aba..854dd50f 100644 --- a/FlingEngine/Core/inc/Engine.h +++ b/FlingEngine/Core/inc/Engine.h @@ -9,6 +9,7 @@ #include "World.h" #include #include +#include #include "MovingAverage.hpp" #include "Stats.h" @@ -20,6 +21,20 @@ #endif // WITH_EDITOR +/** + * Triggers a breakpoint at the call site, halting execution if a debugger is attached. + * Works across compilers/platforms so callers don't need their own #ifdef ladder. + */ +#if defined( _MSC_VER ) + #define F_DEBUG_BREAK() __debugbreak() +#elif defined( __clang__ ) + #define F_DEBUG_BREAK() __builtin_debugtrap() +#elif defined( __GNUC__ ) + #define F_DEBUG_BREAK() raise( SIGTRAP ) +#else + #define F_DEBUG_BREAK() +#endif + namespace Fling { /** diff --git a/FlingEngine/Core/src/Engine.cpp b/FlingEngine/Core/src/Engine.cpp index 9e30dab5..2c1d6d7a 100644 --- a/FlingEngine/Core/src/Engine.cpp +++ b/FlingEngine/Core/src/Engine.cpp @@ -20,6 +20,12 @@ namespace Fling FlingConfig::Get().Init(); + if (CommandLine::Get().GetValueAs("WaitForDebugger", false)) + { + F_LOG_TRACE("-WaitForDebugger was set, breaking into the debugger now"); + F_DEBUG_BREAK(); + } + ResourceManager::Get().Init(); Timing::Get().Init(); Input::Init();