Symbol address decoding (win32 implementation).

This commit is contained in:
Bartosz Taudul 2020-02-26 22:32:42 +01:00
parent 03ff08a934
commit ef05570540
2 changed files with 39 additions and 1 deletions

View File

@ -231,6 +231,39 @@ static void GetModuleName( uint64_t addr, char* buf, ULONG& len )
len = 9;
}
SymbolData DecodeSymbolAddress( uint64_t ptr )
{
SymbolData sym;
const auto proc = GetCurrentProcess();
char buf[sizeof( SYMBOL_INFO ) + MaxNameSize];
auto si = (SYMBOL_INFO*)buf;
si->SizeOfStruct = sizeof( SYMBOL_INFO );
si->MaxNameLen = MaxNameSize;
const auto symValid = SymFromAddr( proc, ptr, nullptr, si ) != 0;
IMAGEHLP_LINE64 line;
DWORD displacement = 0;
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
const char* filename;
if (SymGetLineFromAddr64(proc, ptr, &displacement, &line) == 0)
{
filename = "[unknown]";
sym.line = 0;
}
else
{
filename = line.FileName;
sym.line = line.LineNumber;
}
sym.name = symValid ? CopyString( si->Name, si->NameLen ) : CopyString( "[unknown]", 9 );
sym.file = CopyString( filename );
return sym;
}
CallstackEntryData DecodeCallstackPtr( uint64_t ptr )
{
int write;

View File

@ -22,11 +22,15 @@
namespace tracy
{
struct CallstackEntry
struct SymbolData
{
const char* name;
const char* file;
uint32_t line;
};
struct CallstackEntry : public SymbolData
{
uint64_t symAddr;
};
@ -37,6 +41,7 @@ struct CallstackEntryData
const char* imageName;
};
SymbolData DecodeSymbolAddress( uint64_t ptr );
const char* DecodeCallstackPtrFast( uint64_t ptr );
CallstackEntryData DecodeCallstackPtr( uint64_t ptr );
void InitCallstack();