From 4549671caa51a5c20eca7cdc5ed63e7c83ed94a0 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 30 Apr 2022 21:35:14 +0200 Subject: [PATCH] Collect and issue debuginfod requests. Build identifiers stored in vectors are searched linearly. While not optimal, this is enough for a basic implementation. In the future binary search option may be explored, to see if it is worthwhile. Possible gains wouldn't be significant, due to relatively small amount of debug info modules to handle. Debug info descriptor requests that have not yet been checked for (i.e. not in the s_di_known vector) are stored in the s_di_pending vector. When a check is performed from within a libbacktrace callback handler, there are some unknown problems with downloading data. Hence, the download process is delayed to be performed at a later time. The debug info descriptors retrieval can be then repeated. --- client/TracyCallstack.cpp | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/client/TracyCallstack.cpp b/client/TracyCallstack.cpp index 19eef2f4..6086c6d6 100644 --- a/client/TracyCallstack.cpp +++ b/client/TracyCallstack.cpp @@ -695,6 +695,48 @@ void ClearDebugInfoVector( FastVector& vec ) } vec.clear(); } + +DebugInfo* FindDebugInfo( FastVector& vec, const uint8_t* buildid_data, size_t buildid_size ) +{ + for( auto& v : vec ) + { + if( v.buildid_size == buildid_size && memcmp( v.buildid, buildid_data, buildid_size ) == 0 ) + { + return &v; + } + } + return nullptr; +} + +int GetDebugInfoDescriptor( const char* buildid_data, size_t buildid_size ) +{ + auto buildid = (uint8_t*)buildid_data; + auto it = FindDebugInfo( s_di_known, buildid, buildid_size ); + if( it ) return it->fd >= 0 ? dup( it->fd ) : -1; + it = FindDebugInfo( s_di_pending, buildid, buildid_size ); + if( !it ) + { + it = s_di_pending.push_next(); + it->buildid_size = buildid_size; + it->buildid = (uint8_t*)tracy_malloc( buildid_size ); + memcpy( it->buildid, buildid, buildid_size ); + } + return -1; +} + +void DownloadDebugInfo() +{ + assert( !s_di_pending.empty() ); + for( auto& v : s_di_pending ) + { + int fd = debuginfod_find_debuginfo( s_debuginfod, (const unsigned char*)v.buildid, v.buildid_size, nullptr ); + auto it = s_di_known.push_next(); + it->buildid = v.buildid; + it->buildid_size = v.buildid_size; + it->fd = fd >= 0 ? fd : -1; + } + s_di_pending.clear(); +} #endif void EndCallstack()