PPCSymbolDB: Add missing locking
9395238
added locking in some PPCSymbolDB functions that access member
variables, but far from all. To ensure thread safety, this commit adds
the missing locking.
This commit is contained in:
parent
803e6b017b
commit
fef77a5f20
|
@ -35,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,
|
||||
|
@ -45,6 +46,7 @@ void SymbolDB::List()
|
|||
|
||||
bool SymbolDB::IsEmpty() const
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
return m_functions.empty() && m_notes.empty();
|
||||
}
|
||||
|
||||
|
@ -65,6 +67,7 @@ bool SymbolDB::Clear(const char* prefix)
|
|||
|
||||
void SymbolDB::Index()
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
Index(&m_functions);
|
||||
}
|
||||
|
||||
|
@ -79,6 +82,8 @@ void SymbolDB::Index(XFuncMap* functions)
|
|||
|
||||
Symbol* SymbolDB::GetSymbolFromName(std::string_view name)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
for (auto& func : m_functions)
|
||||
{
|
||||
if (func.second.function_name == name)
|
||||
|
@ -90,6 +95,7 @@ Symbol* SymbolDB::GetSymbolFromName(std::string_view name)
|
|||
|
||||
std::vector<Symbol*> SymbolDB::GetSymbolsFromName(std::string_view name)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
std::vector<Symbol*> symbols;
|
||||
|
||||
for (auto& func : m_functions)
|
||||
|
@ -103,6 +109,8 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromName(std::string_view name)
|
|||
|
||||
Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
auto iter = m_checksum_to_function.find(hash);
|
||||
if (iter == m_checksum_to_function.end())
|
||||
return nullptr;
|
||||
|
@ -112,6 +120,8 @@ Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
|
|||
|
||||
std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
const auto iter = m_checksum_to_function.find(hash);
|
||||
|
||||
if (iter == m_checksum_to_function.cend())
|
||||
|
@ -122,6 +132,7 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
|
|||
|
||||
void SymbolDB::AddCompleteSymbol(const Symbol& symbol)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
m_functions.emplace(symbol.address, symbol);
|
||||
}
|
||||
} // namespace Common
|
||||
|
|
|
@ -112,6 +112,6 @@ protected:
|
|||
XNoteMap m_notes;
|
||||
XFuncPtrMap m_checksum_to_function;
|
||||
std::string m_map_name;
|
||||
std::mutex m_mutex;
|
||||
std::recursive_mutex m_mutex;
|
||||
};
|
||||
} // namespace Common
|
||||
|
|
|
@ -37,6 +37,8 @@ PPCSymbolDB::~PPCSymbolDB() = default;
|
|||
// Adds the function to the list, unless it's already there
|
||||
Common::Symbol* PPCSymbolDB::AddFunction(const Core::CPUThreadGuard& guard, u32 start_addr)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
// It's already in the list
|
||||
if (m_functions.contains(start_addr))
|
||||
return nullptr;
|
||||
|
@ -56,6 +58,7 @@ void PPCSymbolDB::AddKnownSymbol(const Core::CPUThreadGuard& guard, u32 startAdd
|
|||
const std::string& name, const std::string& object_name,
|
||||
Common::Symbol::Type type)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
AddKnownSymbol(guard, startAddr, size, name, object_name, type, &m_functions,
|
||||
&m_checksum_to_function);
|
||||
}
|
||||
|
@ -105,6 +108,7 @@ void PPCSymbolDB::AddKnownSymbol(const Core::CPUThreadGuard& guard, u32 startAdd
|
|||
|
||||
void PPCSymbolDB::AddKnownNote(u32 start_addr, u32 size, const std::string& name)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
AddKnownNote(start_addr, size, name, &m_notes);
|
||||
}
|
||||
|
||||
|
@ -132,6 +136,7 @@ void PPCSymbolDB::AddKnownNote(u32 start_addr, u32 size, const std::string& name
|
|||
|
||||
void PPCSymbolDB::DetermineNoteLayers()
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
DetermineNoteLayers(&m_notes);
|
||||
}
|
||||
|
||||
|
@ -211,11 +216,13 @@ Common::Note* PPCSymbolDB::GetNoteFromAddr(u32 addr)
|
|||
|
||||
void PPCSymbolDB::DeleteFunction(u32 start_address)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
m_functions.erase(start_address);
|
||||
}
|
||||
|
||||
void PPCSymbolDB::DeleteNote(u32 start_address)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
m_notes.erase(start_address);
|
||||
}
|
||||
|
||||
|
@ -261,6 +268,8 @@ void PPCSymbolDB::FillInCallers()
|
|||
|
||||
void PPCSymbolDB::PrintCalls(u32 funcAddr) const
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
const auto iter = m_functions.find(funcAddr);
|
||||
if (iter == m_functions.end())
|
||||
{
|
||||
|
@ -282,6 +291,8 @@ void PPCSymbolDB::PrintCalls(u32 funcAddr) const
|
|||
|
||||
void PPCSymbolDB::PrintCallers(u32 funcAddr) const
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
const auto iter = m_functions.find(funcAddr);
|
||||
if (iter == m_functions.end())
|
||||
return;
|
||||
|
@ -300,6 +311,8 @@ void PPCSymbolDB::PrintCallers(u32 funcAddr) const
|
|||
|
||||
void PPCSymbolDB::LogFunctionCall(u32 addr)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
auto iter = m_functions.find(addr);
|
||||
if (iter == m_functions.end())
|
||||
return;
|
||||
|
@ -627,6 +640,8 @@ bool PPCSymbolDB::SaveSymbolMap(const std::string& filename) const
|
|||
if (!file)
|
||||
return false;
|
||||
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
// Write .text section
|
||||
auto function_symbols =
|
||||
m_functions |
|
||||
|
@ -677,7 +692,7 @@ bool PPCSymbolDB::SaveSymbolMap(const std::string& filename) const
|
|||
return true;
|
||||
}
|
||||
|
||||
// Save code map (won't work if Core is running)
|
||||
// Save code map
|
||||
//
|
||||
// Notes:
|
||||
// - Dolphin doesn't load back code maps
|
||||
|
@ -692,6 +707,8 @@ bool PPCSymbolDB::SaveCodeMap(const Core::CPUThreadGuard& guard, const std::stri
|
|||
// Write ".text" at the top
|
||||
f.WriteString(".text\n");
|
||||
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
const auto& ppc_debug_interface = guard.GetSystem().GetPowerPC().GetDebugInterface();
|
||||
|
||||
u32 next_address = 0;
|
||||
|
|
Loading…
Reference in New Issue