diff options
Diffstat (limited to 'Source/Core/Common/SymbolDB.cpp')
| -rw-r--r-- | Source/Core/Common/SymbolDB.cpp | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/Source/Core/Common/SymbolDB.cpp b/Source/Core/Common/SymbolDB.cpp index 88f281e497..2fa514ba86 100644 --- a/Source/Core/Common/SymbolDB.cpp +++ b/Source/Core/Common/SymbolDB.cpp @@ -5,6 +5,7 @@ #include <cstring> #include <map> +#include <mutex> #include <string> #include <utility> @@ -34,6 +35,7 @@ void Symbol::Rename(const std::string& symbol_name) void SymbolDB::List() { + std::lock_guard lock(m_mutex); for (const auto& func : m_functions) { DEBUG_LOG_FMT(OSHLE, "{} @ {:08x}: {} bytes (hash {:08x}) : {} calls", func.second.name, @@ -44,11 +46,14 @@ void SymbolDB::List() bool SymbolDB::IsEmpty() const { + std::lock_guard lock(m_mutex); return m_functions.empty() && m_notes.empty(); } bool SymbolDB::Clear(const char* prefix) { + std::lock_guard lock(m_mutex); + // TODO: honor prefix m_map_name.clear(); if (IsEmpty()) @@ -62,15 +67,23 @@ bool SymbolDB::Clear(const char* prefix) void SymbolDB::Index() { + std::lock_guard lock(m_mutex); + Index(&m_functions); +} + +void SymbolDB::Index(XFuncMap* functions) +{ int i = 0; - for (auto& func : m_functions) + for (auto& func : *functions) { func.second.index = i++; } } -Symbol* SymbolDB::GetSymbolFromName(std::string_view name) +const Symbol* SymbolDB::GetSymbolFromName(std::string_view name) const { + std::lock_guard lock(m_mutex); + for (auto& func : m_functions) { if (func.second.function_name == name) @@ -80,9 +93,10 @@ Symbol* SymbolDB::GetSymbolFromName(std::string_view name) return nullptr; } -std::vector<Symbol*> SymbolDB::GetSymbolsFromName(std::string_view name) +std::vector<const Symbol*> SymbolDB::GetSymbolsFromName(std::string_view name) const { - std::vector<Symbol*> symbols; + std::lock_guard lock(m_mutex); + std::vector<const Symbol*> symbols; for (auto& func : m_functions) { @@ -93,8 +107,10 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromName(std::string_view name) return symbols; } -Symbol* SymbolDB::GetSymbolFromHash(u32 hash) +const Symbol* SymbolDB::GetSymbolFromHash(u32 hash) const { + std::lock_guard lock(m_mutex); + auto iter = m_checksum_to_function.find(hash); if (iter == m_checksum_to_function.end()) return nullptr; @@ -102,8 +118,10 @@ Symbol* SymbolDB::GetSymbolFromHash(u32 hash) return *iter->second.begin(); } -std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash) +std::vector<const Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash) const { + std::lock_guard lock(m_mutex); + const auto iter = m_checksum_to_function.find(hash); if (iter == m_checksum_to_function.cend()) @@ -114,6 +132,34 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash) void SymbolDB::AddCompleteSymbol(const Symbol& symbol) { - m_functions.emplace(symbol.address, symbol); + std::lock_guard lock(m_mutex); + m_functions[symbol.address] = symbol; } + +bool SymbolDB::RenameSymbol(const Symbol& symbol, const std::string& symbol_name) +{ + std::lock_guard lock(m_mutex); + + auto it = m_functions.find(symbol.address); + if (it == m_functions.end()) + return false; + + it->second.Rename(symbol_name); + return true; +} + +bool SymbolDB::RenameSymbol(const Symbol& symbol, const std::string& symbol_name, + const std::string& object_name) +{ + std::lock_guard lock(m_mutex); + + auto it = m_functions.find(symbol.address); + if (it == m_functions.end()) + return false; + + it->second.Rename(symbol_name); + it->second.object_name = object_name; + return true; +} + } // namespace Common |
