mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-09-11 10:40:58 +02:00
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:
@@ -35,6 +35,7 @@ void Symbol::Rename(const std::string& symbol_name)
|
|||||||
|
|
||||||
void SymbolDB::List()
|
void SymbolDB::List()
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
for (const auto& func : m_functions)
|
for (const auto& func : m_functions)
|
||||||
{
|
{
|
||||||
DEBUG_LOG_FMT(OSHLE, "{} @ {:08x}: {} bytes (hash {:08x}) : {} calls", func.second.name,
|
DEBUG_LOG_FMT(OSHLE, "{} @ {:08x}: {} bytes (hash {:08x}) : {} calls", func.second.name,
|
||||||
@@ -45,6 +46,7 @@ void SymbolDB::List()
|
|||||||
|
|
||||||
bool SymbolDB::IsEmpty() const
|
bool SymbolDB::IsEmpty() const
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
return m_functions.empty() && m_notes.empty();
|
return m_functions.empty() && m_notes.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +67,7 @@ bool SymbolDB::Clear(const char* prefix)
|
|||||||
|
|
||||||
void SymbolDB::Index()
|
void SymbolDB::Index()
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
Index(&m_functions);
|
Index(&m_functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +82,8 @@ void SymbolDB::Index(XFuncMap* functions)
|
|||||||
|
|
||||||
Symbol* SymbolDB::GetSymbolFromName(std::string_view name)
|
Symbol* SymbolDB::GetSymbolFromName(std::string_view name)
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
|
|
||||||
for (auto& func : m_functions)
|
for (auto& func : m_functions)
|
||||||
{
|
{
|
||||||
if (func.second.function_name == name)
|
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::vector<Symbol*> SymbolDB::GetSymbolsFromName(std::string_view name)
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
std::vector<Symbol*> symbols;
|
std::vector<Symbol*> symbols;
|
||||||
|
|
||||||
for (auto& func : m_functions)
|
for (auto& func : m_functions)
|
||||||
@@ -103,6 +109,8 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromName(std::string_view name)
|
|||||||
|
|
||||||
Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
|
Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
|
|
||||||
auto iter = m_checksum_to_function.find(hash);
|
auto iter = m_checksum_to_function.find(hash);
|
||||||
if (iter == m_checksum_to_function.end())
|
if (iter == m_checksum_to_function.end())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -112,6 +120,8 @@ Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
|
|||||||
|
|
||||||
std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
|
std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
|
|
||||||
const auto iter = m_checksum_to_function.find(hash);
|
const auto iter = m_checksum_to_function.find(hash);
|
||||||
|
|
||||||
if (iter == m_checksum_to_function.cend())
|
if (iter == m_checksum_to_function.cend())
|
||||||
@@ -122,6 +132,7 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
|
|||||||
|
|
||||||
void SymbolDB::AddCompleteSymbol(const Symbol& symbol)
|
void SymbolDB::AddCompleteSymbol(const Symbol& symbol)
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
m_functions.emplace(symbol.address, symbol);
|
m_functions.emplace(symbol.address, symbol);
|
||||||
}
|
}
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
@@ -112,6 +112,6 @@ protected:
|
|||||||
XNoteMap m_notes;
|
XNoteMap m_notes;
|
||||||
XFuncPtrMap m_checksum_to_function;
|
XFuncPtrMap m_checksum_to_function;
|
||||||
std::string m_map_name;
|
std::string m_map_name;
|
||||||
std::mutex m_mutex;
|
std::recursive_mutex m_mutex;
|
||||||
};
|
};
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
@@ -37,6 +37,8 @@ PPCSymbolDB::~PPCSymbolDB() = default;
|
|||||||
// Adds the function to the list, unless it's already there
|
// Adds the function to the list, unless it's already there
|
||||||
Common::Symbol* PPCSymbolDB::AddFunction(const Core::CPUThreadGuard& guard, u32 start_addr)
|
Common::Symbol* PPCSymbolDB::AddFunction(const Core::CPUThreadGuard& guard, u32 start_addr)
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
|
|
||||||
// It's already in the list
|
// It's already in the list
|
||||||
if (m_functions.contains(start_addr))
|
if (m_functions.contains(start_addr))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -56,6 +58,7 @@ void PPCSymbolDB::AddKnownSymbol(const Core::CPUThreadGuard& guard, u32 startAdd
|
|||||||
const std::string& name, const std::string& object_name,
|
const std::string& name, const std::string& object_name,
|
||||||
Common::Symbol::Type type)
|
Common::Symbol::Type type)
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
AddKnownSymbol(guard, startAddr, size, name, object_name, type, &m_functions,
|
AddKnownSymbol(guard, startAddr, size, name, object_name, type, &m_functions,
|
||||||
&m_checksum_to_function);
|
&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)
|
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);
|
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()
|
void PPCSymbolDB::DetermineNoteLayers()
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
DetermineNoteLayers(&m_notes);
|
DetermineNoteLayers(&m_notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,11 +216,13 @@ Common::Note* PPCSymbolDB::GetNoteFromAddr(u32 addr)
|
|||||||
|
|
||||||
void PPCSymbolDB::DeleteFunction(u32 start_address)
|
void PPCSymbolDB::DeleteFunction(u32 start_address)
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
m_functions.erase(start_address);
|
m_functions.erase(start_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PPCSymbolDB::DeleteNote(u32 start_address)
|
void PPCSymbolDB::DeleteNote(u32 start_address)
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
m_notes.erase(start_address);
|
m_notes.erase(start_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,6 +268,8 @@ void PPCSymbolDB::FillInCallers()
|
|||||||
|
|
||||||
void PPCSymbolDB::PrintCalls(u32 funcAddr) const
|
void PPCSymbolDB::PrintCalls(u32 funcAddr) const
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
|
|
||||||
const auto iter = m_functions.find(funcAddr);
|
const auto iter = m_functions.find(funcAddr);
|
||||||
if (iter == m_functions.end())
|
if (iter == m_functions.end())
|
||||||
{
|
{
|
||||||
@@ -282,6 +291,8 @@ void PPCSymbolDB::PrintCalls(u32 funcAddr) const
|
|||||||
|
|
||||||
void PPCSymbolDB::PrintCallers(u32 funcAddr) const
|
void PPCSymbolDB::PrintCallers(u32 funcAddr) const
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
|
|
||||||
const auto iter = m_functions.find(funcAddr);
|
const auto iter = m_functions.find(funcAddr);
|
||||||
if (iter == m_functions.end())
|
if (iter == m_functions.end())
|
||||||
return;
|
return;
|
||||||
@@ -300,6 +311,8 @@ void PPCSymbolDB::PrintCallers(u32 funcAddr) const
|
|||||||
|
|
||||||
void PPCSymbolDB::LogFunctionCall(u32 addr)
|
void PPCSymbolDB::LogFunctionCall(u32 addr)
|
||||||
{
|
{
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
|
|
||||||
auto iter = m_functions.find(addr);
|
auto iter = m_functions.find(addr);
|
||||||
if (iter == m_functions.end())
|
if (iter == m_functions.end())
|
||||||
return;
|
return;
|
||||||
@@ -627,6 +640,8 @@ bool PPCSymbolDB::SaveSymbolMap(const std::string& filename) const
|
|||||||
if (!file)
|
if (!file)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
|
|
||||||
// Write .text section
|
// Write .text section
|
||||||
auto function_symbols =
|
auto function_symbols =
|
||||||
m_functions |
|
m_functions |
|
||||||
@@ -677,7 +692,7 @@ bool PPCSymbolDB::SaveSymbolMap(const std::string& filename) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save code map (won't work if Core is running)
|
// Save code map
|
||||||
//
|
//
|
||||||
// Notes:
|
// Notes:
|
||||||
// - Dolphin doesn't load back code maps
|
// - 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
|
// Write ".text" at the top
|
||||||
f.WriteString(".text\n");
|
f.WriteString(".text\n");
|
||||||
|
|
||||||
|
std::lock_guard lock(m_mutex);
|
||||||
|
|
||||||
const auto& ppc_debug_interface = guard.GetSystem().GetPowerPC().GetDebugInterface();
|
const auto& ppc_debug_interface = guard.GetSystem().GetPowerPC().GetDebugInterface();
|
||||||
|
|
||||||
u32 next_address = 0;
|
u32 next_address = 0;
|
||||||
|
Reference in New Issue
Block a user