Make source code query handling easier to follow.

Also, limit debuginfod source file upload to not exceed target frame size.
This commit is contained in:
Bartosz Taudul 2022-05-01 22:52:20 +02:00
parent b6f155bb6a
commit 6455fcfa91
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -3813,11 +3813,13 @@ void Profiler::HandleSourceCodeQuery()
assert( m_queryData );
InitRpmalloc();
bool ok = false;
struct stat st;
if( stat( m_queryData, &st ) == 0 && (uint64_t)st.st_mtime < m_exectime && st.st_size < ( TargetFrameSize - 16 ) )
if( stat( m_queryData, &st ) == 0 && (uint64_t)st.st_mtime < m_exectime )
{
if( st.st_size < ( TargetFrameSize - 16 ) )
{
FILE* f = fopen( m_queryData, "rb" );
tracy_free_fast( m_queryData );
if( f )
{
auto ptr = (char*)tracy_malloc_fast( st.st_size );
@ -3826,16 +3828,10 @@ void Profiler::HandleSourceCodeQuery()
if( rd == (size_t)st.st_size )
{
SendLongString( (uint64_t)ptr, ptr, rd, QueueType::SourceCode );
}
else
{
AckSourceCodeNotAvailable();
ok = true;
}
tracy_free_fast( ptr );
}
else
{
AckSourceCodeNotAvailable();
}
}
#ifdef TRACY_DEBUGINFOD
@ -3850,45 +3846,31 @@ void Profiler::HandleSourceCodeQuery()
{
struct stat st;
fstat( d, &st );
if( st.st_size < ( TargetFrameSize - 16 ) )
{
lseek( d, 0, SEEK_SET );
auto ptr = (char*)tracy_malloc_fast( st.st_size );
auto rd = read( d, ptr, st.st_size );
close( d );
if( rd == (size_t)st.st_size )
{
SendLongString( (uint64_t)ptr, ptr, rd, QueueType::SourceCode );
}
else
{
AckSourceCodeNotAvailable();
ok = true;
}
tracy_free_fast( ptr );
}
else
{
AckSourceCodeNotAvailable();
close( d );
}
}
else
{
AckSourceCodeNotAvailable();
}
tracy_free_fast( m_queryData );
}
#endif
else
{
tracy_free_fast( m_queryData );
AckSourceCodeNotAvailable();
}
m_queryData = nullptr;
if( m_queryImage )
{
if( !ok ) AckSourceCodeNotAvailable();
tracy_free_fast( m_queryData );
tracy_free_fast( m_queryImage );
m_queryData = nullptr;
m_queryImage = nullptr;
}
}
#if defined _WIN32 && defined TRACY_TIMER_QPC
int64_t Profiler::GetTimeQpc()