From c3b67e4482b053a00e62d77d38c4e1bc59aa13a1 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 14 Jan 2019 23:08:34 +0100 Subject: [PATCH] Perform zone stack validation. --- server/TracyWorker.cpp | 23 ++++++++++++++++++----- server/TracyWorker.hpp | 6 +++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 89c32096..55a0a2f4 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1618,7 +1618,7 @@ void Worker::ServerQuery( uint8_t type, uint64_t data ) m_sock.Send( tmp, DataSize ); } -void Worker::DispatchProcess( const QueueItem& ev, char*& ptr ) +bool Worker::DispatchProcess( const QueueItem& ev, char*& ptr ) { if( ev.hdr.idx >= (int)QueueType::StringData ) { @@ -1654,11 +1654,12 @@ void Worker::DispatchProcess( const QueueItem& ev, char*& ptr ) break; } ptr += sz; + return true; } else { ptr += QueueDataSize[ev.hdr.idx]; - Process( ev ); + return Process( ev ); } } @@ -1799,6 +1800,9 @@ void Worker::NewZone( ZoneEvent* zone, uint64_t thread ) } td->stack.push_back_non_empty( zone ); } + + td->zoneIdStack.push_back( td->nextZoneId ); + td->nextZoneId = 0; } void Worker::InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread ) @@ -2087,7 +2091,7 @@ StringLocation Worker::StoreString( char* str, size_t sz ) return ret; } -void Worker::Process( const QueueItem& ev ) +bool Worker::Process( const QueueItem& ev ) { switch( ev.hdr.type ) { @@ -2101,7 +2105,7 @@ void Worker::Process( const QueueItem& ev ) ProcessZoneBeginAllocSrcLoc( ev.zoneBegin ); break; case QueueType::ZoneEnd: - ProcessZoneEnd( ev.zoneEnd ); + if( !ProcessZoneEnd( ev.zoneEnd ) ) return false; break; case QueueType::ZoneValidation: ProcessZoneValidation( ev.zoneValidation ); @@ -2211,6 +2215,8 @@ void Worker::Process( const QueueItem& ev ) assert( false ); break; } + + return true; } void Worker::ProcessZoneBeginImpl( ZoneEvent* zone, const QueueZoneBegin& ev ) @@ -2268,12 +2274,17 @@ void Worker::ProcessZoneBeginAllocSrcLoc( const QueueZoneBegin& ev ) m_pendingSourceLocationPayload.erase( it ); } -void Worker::ProcessZoneEnd( const QueueZoneEnd& ev ) +bool Worker::ProcessZoneEnd( const QueueZoneEnd& ev ) { auto tit = m_threadMap.find( ev.thread ); assert( tit != m_threadMap.end() ); auto td = tit->second; + assert( !td->zoneIdStack.empty() ); + auto zoneId = td->zoneIdStack.back_and_pop(); + if( zoneId != td->nextZoneId ) return false; + td->nextZoneId = 0; + auto& stack = td->stack; assert( !stack.empty() ); auto zone = stack.back_and_pop(); @@ -2305,6 +2316,8 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev ) it->second.selfTotal += timeSpan; } #endif + + return true; } void Worker::ProcessZoneValidation( const QueueZoneValidation& ev ) diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 77c48d2e..4434a993 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -273,12 +273,12 @@ private: void Exec(); void ServerQuery( uint8_t type, uint64_t data ); - tracy_force_inline void DispatchProcess( const QueueItem& ev, char*& ptr ); - tracy_force_inline void Process( const QueueItem& ev ); + tracy_force_inline bool DispatchProcess( const QueueItem& ev, char*& ptr ); + tracy_force_inline bool Process( const QueueItem& ev ); tracy_force_inline void ProcessZoneBegin( const QueueZoneBegin& ev ); tracy_force_inline void ProcessZoneBeginCallstack( const QueueZoneBegin& ev ); tracy_force_inline void ProcessZoneBeginAllocSrcLoc( const QueueZoneBegin& ev ); - tracy_force_inline void ProcessZoneEnd( const QueueZoneEnd& ev ); + tracy_force_inline bool ProcessZoneEnd( const QueueZoneEnd& ev ); tracy_force_inline void ProcessZoneValidation( const QueueZoneValidation& ev ); tracy_force_inline void ProcessFrameMark( const QueueFrameMark& ev ); tracy_force_inline void ProcessFrameMarkStart( const QueueFrameMark& ev );