Accessor for getting source file, line from address.

This commit is contained in:
Bartosz Taudul 2020-04-02 00:31:53 +02:00
parent 2dd5912fee
commit d204742bb8
2 changed files with 28 additions and 5 deletions

View File

@ -38,6 +38,18 @@ static tracy_force_inline CallstackFrameId PackPointer( uint64_t ptr )
return id; return id;
} }
static tracy_force_inline uint64_t PackFileLine( uint32_t fileIdx, uint32_t line )
{
return ( uint64_t( fileIdx ) << 32 ) | line;
}
static tracy_force_inline uint32_t UnpackFileLine( uint64_t packed, uint32_t& line )
{
line = packed & 0xFFFFFFFF;
return packed >> 32;
}
static const uint8_t FileHeader[8] { 't', 'r', 'a', 'c', 'y', Version::Major, Version::Minor, Version::Patch }; static const uint8_t FileHeader[8] { 't', 'r', 'a', 'c', 'y', Version::Major, Version::Minor, Version::Patch };
enum { FileHeaderMagic = 5 }; enum { FileHeaderMagic = 5 };
static const int CurrentVersion = FileVersion( Version::Major, Version::Minor, Version::Patch ); static const int CurrentVersion = FileVersion( Version::Major, Version::Minor, Version::Patch );
@ -2312,6 +2324,21 @@ uint64_t Worker::GetSymbolForAddress( uint64_t address, uint32_t& offset ) const
return it->addr; return it->addr;
} }
StringIdx Worker::GetLocationForAddress( uint64_t address, uint32_t& line ) const
{
auto it = m_data.codeAddressToLocation.find( address );
if( it == m_data.codeAddressToLocation.end() )
{
line = 0;
return StringIdx();
}
else
{
const auto idx = UnpackFileLine( it->second, line );
return StringIdx( idx );
}
}
int64_t Worker::GetZoneEnd( const ZoneEvent& ev ) int64_t Worker::GetZoneEnd( const ZoneEvent& ev )
{ {
auto ptr = &ev; auto ptr = &ev;
@ -5504,11 +5531,6 @@ void Worker::ProcessSymbolInformation( const QueueSymbolInformation& ev )
m_pendingCustomStrings.erase( fit ); 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 ) void Worker::ProcessCodeInformation( const QueueCodeInformation& ev )
{ {
assert( m_pendingCodeInformation > 0 ); assert( m_pendingCodeInformation > 0 );

View File

@ -436,6 +436,7 @@ public:
const SymbolData* GetSymbolData( uint64_t sym ) const; const SymbolData* GetSymbolData( uint64_t sym ) const;
const char* GetSymbolCode( uint64_t sym, uint32_t& len ) const; const char* GetSymbolCode( uint64_t sym, uint32_t& len ) const;
uint64_t GetSymbolForAddress( uint64_t address, uint32_t& offset ) const; uint64_t GetSymbolForAddress( uint64_t address, uint32_t& offset ) const;
StringIdx GetLocationForAddress( uint64_t address, uint32_t& line ) const;
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
const VarArray<CallstackFrameId>& GetParentCallstack( uint32_t idx ) const { return *m_data.parentCallstackPayload[idx]; } const VarArray<CallstackFrameId>& GetParentCallstack( uint32_t idx ) const { return *m_data.parentCallstackPayload[idx]; }