// MIT License // // Copyright (c) 2022-2025 Advanced Micro Devices, Inc. All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #include "internal_libs.hpp" #include "binary/analysis.hpp" #include "binary/binary_info.hpp" #include "binary/link_map.hpp" #include "binary/scope_filter.hpp" #include "binary/symbol.hpp" #include "common/defines.h" #include "core/demangler.hpp" #include "core/utility.hpp" #include "fwd.hpp" #include "log.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace { namespace filepath = ::tim::filepath; using ::tim::delimit; using ::tim::get_env; using ::timemory::join::join; using strview_init_t = std::initializer_list; using strview_set_t = std::set; using open_modes_vec_t = std::vector; auto get_exe_realpath() { return filepath::realpath("/proc/self/exe", nullptr, false); } auto& get_symtab_file_cache() { static auto _cache = std::unordered_map>{}; return _cache; } symtab_t* get_symtab_file(const std::string& _name) { auto& _cache = get_symtab_file_cache(); auto itr = _cache.find(_name); if(itr == _cache.end()) { symtab_t* _v = SymTab::Symtab::findOpenSymtab(_name); bool _closable = (_v == nullptr); if(!_v) SymTab::Symtab::openFile(_v, _name); TIMEMORY_PREFER(_v != nullptr) << "Warning! Dyninst could not open a Symtab instance for file '" << _name << "'\n"; _cache.emplace(_name, std::make_pair(_v, _closable)); } return _cache.at(_name).first; } bool close_symtab_file(const std::string& _name) { auto& _cache = get_symtab_file_cache(); auto itr = _cache.find(_name); if(itr != _cache.end()) { symtab_t* _symtab = itr->second.first; bool _closable = itr->second.second; if(_symtab && _closable) SymTab::Symtab::closeSymtab(_symtab); _cache.erase(itr); return true; } return false; } template