From d204742bb842b2c6aa085f2855bf131a105bb591 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 2 Apr 2020 00:31:53 +0200 Subject: [PATCH] Accessor for getting source file, line from address. --- server/TracyWorker.cpp | 32 +++++++++++++++++++++++++++----- server/TracyWorker.hpp | 1 + 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 3529b21e..c63bf710 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -38,6 +38,18 @@ static tracy_force_inline CallstackFrameId PackPointer( uint64_t ptr ) 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 }; enum { FileHeaderMagic = 5 }; 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; } +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 ) { auto ptr = &ev; @@ -5504,11 +5531,6 @@ 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 ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 555a5e14..0db36bf8 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -436,6 +436,7 @@ public: const SymbolData* GetSymbolData( uint64_t sym ) const; const char* GetSymbolCode( uint64_t sym, uint32_t& len ) const; uint64_t GetSymbolForAddress( uint64_t address, uint32_t& offset ) const; + StringIdx GetLocationForAddress( uint64_t address, uint32_t& line ) const; #ifndef TRACY_NO_STATISTICS const VarArray& GetParentCallstack( uint32_t idx ) const { return *m_data.parentCallstackPayload[idx]; }