From 88b1955a5a381e6267384fc142d6b4178b137c42 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 20 Jun 2018 01:26:05 +0200 Subject: [PATCH] Filename in callstack frame is not a persistent pointer. --- client/TracyCallstack.cpp | 10 ++++++++-- client/TracyProfiler.cpp | 2 ++ server/TracyEvent.hpp | 2 +- server/TracyWorker.cpp | 13 ++++++++----- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/client/TracyCallstack.cpp b/client/TracyCallstack.cpp index b9032a51..50a32214 100644 --- a/client/TracyCallstack.cpp +++ b/client/TracyCallstack.cpp @@ -78,15 +78,21 @@ CallstackEntry DecodeCallstackPtr( uint64_t ptr ) line.SizeOfStruct = sizeof( IMAGEHLP_LINE64 ); if( SymGetLineFromAddr64( proc, ptr, &displacement, &line ) == 0 ) { - ret.file = "[unknown]"; + line.FileName = "[unknown]"; ret.line = 0; } else { - ret.file = line.FileName; ret.line = line.LineNumber; } + const auto fsz = strlen( line.FileName ); + auto file = (char*)tracy_malloc( fsz + 1 ); + memcpy( file, line.FileName, fsz ); + file[fsz] = '\0'; + + ret.file = file; + return ret; } diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index a3fbaf78..e7c87ea5 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -565,6 +565,7 @@ void Profiler::SendCallstackFrame( uint64_t ptr ) auto frame = DecodeCallstackPtr( ptr ); SendString( uint64_t( frame.name ), frame.name, QueueType::CustomStringData ); + SendString( uint64_t( frame.file ), frame.file, QueueType::CustomStringData ); QueueItem item; MemWrite( &item.hdr.type, QueueType::CallstackFrame ); @@ -577,6 +578,7 @@ void Profiler::SendCallstackFrame( uint64_t ptr ) AppendData( &item, QueueDataSize[(int)QueueType::CallstackFrame] ); tracy_free( (void*)frame.name ); + tracy_free( (void*)frame.file ); #endif } diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index c5eefb5c..7a453f46 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -161,8 +161,8 @@ static_assert( std::is_standard_layout::value, "MemEvent is not standa struct CallstackFrame { - uint64_t file; StringIdx name; + StringIdx file; uint32_t line; }; diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index d37b3769..3922324d 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2116,8 +2116,10 @@ void Worker::ProcessCallstackMemory( const QueueCallstackMemory& ev ) void Worker::ProcessCallstackFrame( const QueueCallstackFrame& ev ) { auto fmit = m_data.callstackFrameMap.find( ev.ptr ); - auto it = m_pendingCustomStrings.find( ev.name ); - assert( it != m_pendingCustomStrings.end() ); + auto nit = m_pendingCustomStrings.find( ev.name ); + assert( nit != m_pendingCustomStrings.end() ); + auto fit = m_pendingCustomStrings.find( ev.file ); + assert( fit != m_pendingCustomStrings.end() ); // Frames may be duplicated due to recursion if( fmit == m_data.callstackFrameMap.end() ) @@ -2125,14 +2127,15 @@ void Worker::ProcessCallstackFrame( const QueueCallstackFrame& ev ) CheckString( ev.file ); auto frame = m_slab.Alloc(); - frame->name = StringIdx( it->second.idx ); - frame->file = ev.file; + frame->name = StringIdx( nit->second.idx ); + frame->file = StringIdx( fit->second.idx ); frame->line = ev.line; m_data.callstackFrameMap.emplace( ev.ptr, frame ); } - m_pendingCustomStrings.erase( it ); + m_pendingCustomStrings.erase( nit ); + m_pendingCustomStrings.erase( m_pendingCustomStrings.find( ev.file ) ); } void Worker::MemAllocChanged( int64_t time )