From 12da626fd168805ded20d01aadedad1a5740eb81 Mon Sep 17 00:00:00 2001 From: Marcos Slomp Date: Tue, 17 Feb 2026 14:27:07 -0800 Subject: [PATCH] ensure executable path is inspected when looking for pdb files --- public/client/TracyCallstack.cpp | 35 ++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/public/client/TracyCallstack.cpp b/public/client/TracyCallstack.cpp index ac224227..4fe0754b 100644 --- a/public/client/TracyCallstack.cpp +++ b/public/client/TracyCallstack.cpp @@ -378,6 +378,22 @@ void InitCallstackCritical() ___tracy_RtlWalkFrameChainPtr = (___tracy_t_RtlWalkFrameChain)GetProcAddress( GetModuleHandleA( "ntdll.dll" ), "RtlWalkFrameChain" ); } +static void SymError( const char* function, DWORD code ) { + char message[1024] = {}; + int written = snprintf( message, sizeof( message ), "ERROR: %s FAILED with code %u (0x%x) | ", function, code, code ); + written += FormatMessageA( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + code, + MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), + (LPSTR)&message[written], + sizeof(message) - written, + NULL + ); + fprintf( stderr, "%s\n", message ); + OutputDebugStringA( message ); +} + void DbgHelpInit() { if( s_shouldResolveSymbolsOffline ) return; @@ -392,8 +408,23 @@ void DbgHelpInit() DBGHELP_LOCK; #endif - SymInitialize( GetCurrentProcess(), nullptr, true ); - SymSetOptions( SYMOPT_LOAD_LINES ); + // append executable path to the _NT_SYMBOL_PATH environment variable + char buffer [32767]; // max env var length on Windows (including null-terminator) + DWORD length = GetEnvironmentVariableA( "_NT_SYMBOL_PATH", buffer, sizeof( buffer ) ); + buffer[length] = ';'; + buffer[++length] = '\0'; + length += GetModuleFileNameA( NULL, &buffer[length], sizeof( buffer ) - length ); + while( length > 0 && buffer[--length] != '\\ ') + buffer[length] = '\0'; + assert( length < sizeof( buffer ) ); + if( SetEnvironmentVariableA( "_NT_SYMBOL_PATH", buffer ) == FALSE ) { + SymError( "SetEnvironmentVariableA", GetLastError() ); + } + + SymSetOptions( SymGetOptions() | SYMOPT_LOAD_LINES ); + if( SymInitialize( GetCurrentProcess(), NULL, TRUE ) == FALSE ) { + SymError( "SymInitialize", GetLastError() ); + } #ifdef TRACY_DBGHELP_LOCK DBGHELP_UNLOCK;