From 992f4c8c2d77eab8a9d7d6fc1d1460f14bb953c7 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 27 Mar 2020 17:39:42 +0100 Subject: [PATCH] Implement search for symbol base from address. --- server/TracyWorker.cpp | 8 ++++++++ server/TracyWorker.hpp | 1 + 2 files changed, 9 insertions(+) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index a1cc0b62..9ba20a55 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2279,6 +2279,14 @@ const char* Worker::GetSymbolCode( uint64_t sym, uint32_t& len ) const return it->second.data; } +uint64_t Worker::GetSymbolForAddress( uint64_t address, uint32_t& offset ) const +{ + auto it = std::lower_bound( m_data.symbolLoc.begin(), m_data.symbolLoc.end(), address, [] ( const auto& l, const auto& r ) { return l.addr + l.len < r; } ); + if( it == m_data.symbolLoc.end() || address < it->addr ) return 0; + offset = address - it->addr; + return it->addr; +} + int64_t Worker::GetZoneEnd( const ZoneEvent& ev ) { auto ptr = &ev; diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index a353d7b0..bf402d52 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -432,6 +432,7 @@ public: uint64_t GetCanonicalPointer( const CallstackFrameId& id ) const; 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; #ifndef TRACY_NO_STATISTICS const VarArray& GetParentCallstack( uint32_t idx ) const { return *m_data.parentCallstackPayload[idx]; }