1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 12:23:53 +00:00

Store code address -> source file+line mapping.

This commit is contained in:
Bartosz Taudul 2020-04-01 22:37:19 +02:00
parent b2a8b53efa
commit 0ec89e9aae
2 changed files with 30 additions and 2 deletions

View File

@ -230,6 +230,7 @@ Worker::Worker( const char* addr, int port )
, m_pendingSourceLocation( 0 )
, m_pendingCallstackFrames( 0 )
, m_pendingCallstackSubframes( 0 )
, m_pendingCodeInformation( 0 )
, m_callstackFrameStaging( nullptr )
, m_traceVersion( CurrentVersion )
, m_loadTime( 0 )
@ -2860,7 +2861,7 @@ void Worker::Exec()
if( m_pendingStrings != 0 || m_pendingThreads != 0 || m_pendingSourceLocation != 0 || m_pendingCallstackFrames != 0 ||
!m_pendingCustomStrings.empty() || m_data.plots.IsPending() || m_pendingCallstackPtr != 0 ||
m_pendingExternalNames != 0 || m_pendingCallstackSubframes != 0 || !m_pendingFrameImageData.empty() ||
!m_pendingSymbols.empty() || !m_pendingSymbolCode.empty() )
!m_pendingSymbols.empty() || !m_pendingSymbolCode.empty() || m_pendingCodeInformation != 0 )
{
continue;
}
@ -3588,6 +3589,7 @@ void Worker::AddSymbolCode( uint64_t ptr, const char* data, size_t sz )
size_t cnt = cs_disasm( handle, (const uint8_t*)code, sz, ptr, 0, &insn );
if( cnt > 0 )
{
m_pendingCodeInformation += cnt;
for( size_t i=0; i<cnt; i++ )
{
Query( ServerQueryCodeLocation, insn[i].address );
@ -4024,7 +4026,7 @@ bool Worker::Process( const QueueItem& ev )
m_serverQuerySpaceLeft++;
break;
case QueueType::CodeInformation:
// TODO
ProcessCodeInformation( ev.codeInformation );
m_serverQuerySpaceLeft++;
break;
case QueueType::Terminate:
@ -5502,6 +5504,28 @@ void Worker::ProcessSymbolInformation( const QueueSymbolInformation& ev )
m_pendingCustomStrings.erase( fit );
}
tracy_force_inline uint64_t PackFileLine( uint32_t fileIdx, uint32_t line )
{
return ( uint64_t( fileIdx ) << 32 ) | line;
}
void Worker::ProcessCodeInformation( const QueueCodeInformation& ev )
{
assert( m_pendingCodeInformation > 0 );
m_pendingCodeInformation--;
auto fit = m_pendingCustomStrings.find( ev.file );
assert( fit != m_pendingCustomStrings.end() );
if( ev.line != 0 )
{
assert( m_data.codeAddressToLocation.find( ev.ptr ) == m_data.codeAddressToLocation.end() );
m_data.codeAddressToLocation.emplace( ev.ptr, PackFileLine( fit->second.idx, ev.line ) );
}
m_pendingCustomStrings.erase( fit );
}
void Worker::ProcessCrashReport( const QueueCrashReport& ev )
{
CheckString( ev.text );

View File

@ -296,6 +296,8 @@ private:
unordered_flat_map<uint64_t, SymbolCodeData> symbolCode;
uint64_t symbolCodeSize = 0;
unordered_flat_map<uint64_t, uint64_t> codeAddressToLocation;
};
struct MbpsBlock
@ -589,6 +591,7 @@ private:
tracy_force_inline void ProcessCallstackFrameSize( const QueueCallstackFrameSize& ev );
tracy_force_inline void ProcessCallstackFrame( const QueueCallstackFrame& ev );
tracy_force_inline void ProcessSymbolInformation( const QueueSymbolInformation& ev );
tracy_force_inline void ProcessCodeInformation( const QueueCodeInformation& ev );
tracy_force_inline void ProcessCrashReport( const QueueCrashReport& ev );
tracy_force_inline void ProcessSysTime( const QueueSysTime& ev );
tracy_force_inline void ProcessContextSwitch( const QueueContextSwitch& ev );
@ -788,6 +791,7 @@ private:
uint32_t m_pendingSourceLocation;
uint32_t m_pendingCallstackFrames;
uint8_t m_pendingCallstackSubframes;
uint32_t m_pendingCodeInformation;
CallstackFrameData* m_callstackFrameStaging;
uint64_t m_callstackFrameStagingPtr;