From 17855cbac55f1164aa882fcd20135770db0a03d7 Mon Sep 17 00:00:00 2001 From: Lectem Date: Wed, 8 Dec 2021 21:30:06 +0100 Subject: [PATCH 1/2] Call SymLoadModuleEx for modules loaded after init This fixes issue #293. Symbols are not loaded if the module is loaded dynamically after the SymInitialize call. This may stall the symbol resolver thread a bit the first time a module is loaded. --- client/TracyCallstack.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/TracyCallstack.cpp b/client/TracyCallstack.cpp index 0dff7c81..0e0af4a9 100644 --- a/client/TracyCallstack.cpp +++ b/client/TracyCallstack.cpp @@ -296,6 +296,8 @@ static const char* GetModuleName( uint64_t addr ) const auto res = GetModuleFileNameA( mod[i], name, 1021 ); if( res > 0 ) { + // since this is the first time we encounter this module, load its symbols (needed for modules loaded after SymInitialize) + SymLoadModuleEx(proc, NULL, name, NULL, (DWORD64)info.lpBaseOfDll, info.SizeOfImage, NULL, 0); auto ptr = name + res; while( ptr > name && *ptr != '\\' && *ptr != '/' ) ptr--; if( ptr > name ) ptr++; From 5d0466b7293fdef05bf29a782fc235b3cd0f003d Mon Sep 17 00:00:00 2001 From: Lectem Date: Sun, 12 Dec 2021 14:32:24 +0100 Subject: [PATCH 2/2] Rename GetModuleName and call it before sym* use --- client/TracyCallstack.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/TracyCallstack.cpp b/client/TracyCallstack.cpp index 0e0af4a9..afd1ebd1 100644 --- a/client/TracyCallstack.cpp +++ b/client/TracyCallstack.cpp @@ -253,7 +253,7 @@ const char* GetKernelModulePath( uint64_t addr ) return it->path; } -static const char* GetModuleName( uint64_t addr ) +static const char* GetModuleNameAndPrepareSymbols( uint64_t addr ) { if( ( addr >> 63 ) != 0 ) { @@ -435,6 +435,9 @@ CallstackEntryData DecodeCallstackPtr( uint64_t ptr ) #ifdef TRACY_DBGHELP_LOCK DBGHELP_LOCK; #endif + + const auto moduleName = GetModuleNameAndPrepareSymbols(ptr); + #if !defined TRACY_NO_CALLSTACK_INLINES BOOL doInline = FALSE; DWORD ctx = 0; @@ -463,7 +466,6 @@ CallstackEntryData DecodeCallstackPtr( uint64_t ptr ) si->SizeOfStruct = sizeof( SYMBOL_INFO ); si->MaxNameLen = MaxNameSize; - const auto moduleName = GetModuleName( ptr ); const auto symValid = SymFromAddr( proc, ptr, nullptr, si ) != 0; IMAGEHLP_LINE64 line;