Filename in callstack frame is not a persistent pointer.

This commit is contained in:
Bartosz Taudul 2018-06-20 01:26:05 +02:00
parent 56479b86fa
commit 88b1955a5a
4 changed files with 19 additions and 8 deletions

View File

@ -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;
}

View File

@ -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
}

View File

@ -161,8 +161,8 @@ static_assert( std::is_standard_layout<MemEvent>::value, "MemEvent is not standa
struct CallstackFrame
{
uint64_t file;
StringIdx name;
StringIdx file;
uint32_t line;
};

View File

@ -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<CallstackFrame>();
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 )