Merge pull request #294 from Lectem/symbols_post_init

Call SymLoadModuleEx for modules loaded after init (Fixes #293)
This commit is contained in:
Bartosz Taudul 2021-12-22 16:36:08 +01:00 committed by GitHub
commit 2f0d4a7707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -253,7 +253,7 @@ const char* GetKernelModulePath( uint64_t addr )
return it->path; return it->path;
} }
static const char* GetModuleName( uint64_t addr ) static const char* GetModuleNameAndPrepareSymbols( uint64_t addr )
{ {
if( ( addr >> 63 ) != 0 ) if( ( addr >> 63 ) != 0 )
{ {
@ -296,6 +296,8 @@ static const char* GetModuleName( uint64_t addr )
const auto res = GetModuleFileNameA( mod[i], name, 1021 ); const auto res = GetModuleFileNameA( mod[i], name, 1021 );
if( res > 0 ) 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; auto ptr = name + res;
while( ptr > name && *ptr != '\\' && *ptr != '/' ) ptr--; while( ptr > name && *ptr != '\\' && *ptr != '/' ) ptr--;
if( ptr > name ) ptr++; if( ptr > name ) ptr++;
@ -433,6 +435,9 @@ CallstackEntryData DecodeCallstackPtr( uint64_t ptr )
#ifdef TRACY_DBGHELP_LOCK #ifdef TRACY_DBGHELP_LOCK
DBGHELP_LOCK; DBGHELP_LOCK;
#endif #endif
const auto moduleName = GetModuleNameAndPrepareSymbols(ptr);
#if !defined TRACY_NO_CALLSTACK_INLINES #if !defined TRACY_NO_CALLSTACK_INLINES
BOOL doInline = FALSE; BOOL doInline = FALSE;
DWORD ctx = 0; DWORD ctx = 0;
@ -461,7 +466,6 @@ CallstackEntryData DecodeCallstackPtr( uint64_t ptr )
si->SizeOfStruct = sizeof( SYMBOL_INFO ); si->SizeOfStruct = sizeof( SYMBOL_INFO );
si->MaxNameLen = MaxNameSize; si->MaxNameLen = MaxNameSize;
const auto moduleName = GetModuleName( ptr );
const auto symValid = SymFromAddr( proc, ptr, nullptr, si ) != 0; const auto symValid = SymFromAddr( proc, ptr, nullptr, si ) != 0;
IMAGEHLP_LINE64 line; IMAGEHLP_LINE64 line;