From 2e566513ddd1c419e35fc41c30fb9787028da7e5 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 30 Aug 2026 16:15:01 +0200 Subject: [PATCH] Create external backtrace states from openable paths only. backtrace_create_state_for_file opens the file lazily on first use and, on a failed open, silently falls back to /proc/self/exe - so a state created from a path the monitor cannot open would symbolize the target's addresses against the monitor's own binary. Probe the target's root path (and, for unlinked images, the mapping's map_files entry), and only create a state for a path that actually opens. --- public/client/TracyCallstack.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/public/client/TracyCallstack.cpp b/public/client/TracyCallstack.cpp index 994ad943..831118a9 100644 --- a/public/client/TracyCallstack.cpp +++ b/public/client/TracyCallstack.cpp @@ -587,7 +587,34 @@ static backtrace_state* GetExternalBtState( const ExternalImageEntry* entry ) auto* e = const_cast( entry ); if( e->btAttempted ) return e->btState; e->btAttempted = true; - e->btState = backtrace_create_state_for_file( e->path, 0, ExternalBacktraceErrorCb, nullptr ); + const size_t rootPathSize = strlen( e->path ) + 32; + char* rootPath = (char*)tracy_malloc( rootPathSize ); + const char* statePath = nullptr; + char mfPath[80]; + if( MakeExternalTargetPath( rootPath, rootPathSize, e->path ) >= 0 ) + { + const int probe = open( rootPath, O_RDONLY ); + if( probe >= 0 ) + { + close( probe ); + statePath = rootPath; + } + } + if( !statePath ) + { + snprintf( mfPath, sizeof( mfPath ), "/proc/%d/map_files/%lx-%lx", (int)s_externalTargetPid, (unsigned long)e->startAddress, (unsigned long)e->endAddress ); + const int probe = open( mfPath, O_RDONLY ); + if( probe >= 0 ) + { + close( probe ); + statePath = mfPath; + } + } + if( statePath ) + { + e->btState = backtrace_create_state_for_file( statePath, 0, ExternalBacktraceErrorCb, nullptr ); + } + tracy_free( rootPath ); return e->btState; }