From 3ea49f98d65c17c4218b538dfac602aa45c63412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 20 Apr 2026 12:04:08 -0700 Subject: [PATCH] Lazy load debug help once it's needed to resolve callstack. (#383) --- src/debug.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/debug.cpp b/src/debug.cpp index 51c356b..37299aa 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -46,6 +46,10 @@ # include // backtrace_syminfo #endif // BX_CONFIG_CALLSTACK_* +#ifndef BX_CONFIG_CALLSTACK_USE_DBGHELP +# define BX_CONFIG_CALLSTACK_USE_DBGHELP BX_PLATFORM_WINDOWS +#endif // BX_CONFIG_CALLSTACK_USE_DBGHELP + #ifndef BX_CONFIG_EXCEPTION_HANDLING_USE_WINDOWS_SEH # define BX_CONFIG_EXCEPTION_HANDLING_USE_WINDOWS_SEH BX_PLATFORM_WINDOWS #endif // BX_CONFIG_EXCEPTION_HANDLING_USE_WINDOWS_SEH @@ -684,7 +688,7 @@ namespace bx return total; } -#elif BX_PLATFORM_WINDOWS +#elif BX_CONFIG_CALLSTACK_USE_DBGHELP struct DbgHelpSymbolInfo { @@ -729,7 +733,7 @@ namespace bx struct DbgHelpSymbolResolve { - DbgHelpSymbolResolve() + void init() { m_imageHlpDll = dlopen("dbghelp.dll"); @@ -855,6 +859,15 @@ namespace bx total += write(_writer, _err, "\t #: %-*s Line %-*s Function ---\n", kWidth, "File ---", kWidthPc, "PC ---"); + static bool initCalled = false; + + if (!initCalled) + { + initCalled = true; + + s_dbgHelpSymbolResolve.init(); + } + for (uint32_t ii = 0; ii < _num && _err->isOk(); ++ii) { FixedString1024 functionName;