From d778b8a82055f7f7a93cceabfd9367e63401a4df Mon Sep 17 00:00:00 2001 From: Sepalani Date: Tue, 4 Oct 2016 17:33:25 +0100 Subject: [PATCH 1/3] SymbolDB: GetSymbolsFromName added --- Source/Core/Common/SymbolDB.cpp | 13 +++++++++++++ Source/Core/Common/SymbolDB.h | 1 + Source/Core/Core/HLE/HLE.cpp | 8 +++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Source/Core/Common/SymbolDB.cpp b/Source/Core/Common/SymbolDB.cpp index 9e91b64457..564ac55eb3 100644 --- a/Source/Core/Common/SymbolDB.cpp +++ b/Source/Core/Common/SymbolDB.cpp @@ -48,6 +48,19 @@ Symbol* SymbolDB::GetSymbolFromName(const std::string& name) return nullptr; } +std::vector SymbolDB::GetSymbolsFromName(const std::string& name) +{ + std::vector symbols; + + for (auto& func : functions) + { + if (func.second.function_name == name) + symbols.push_back(&func.second); + } + + return symbols; +} + void SymbolDB::AddCompleteSymbol(const Symbol& symbol) { functions.emplace(symbol.address, symbol); diff --git a/Source/Core/Common/SymbolDB.h b/Source/Core/Common/SymbolDB.h index 8d2ae11614..453e37fe76 100644 --- a/Source/Core/Common/SymbolDB.h +++ b/Source/Core/Common/SymbolDB.h @@ -71,6 +71,7 @@ public: void AddCompleteSymbol(const Symbol& symbol); Symbol* GetSymbolFromName(const std::string& name); + std::vector GetSymbolsFromName(const std::string& name); Symbol* GetSymbolFromHash(u32 hash) { XFuncPtrMap::iterator iter = checksumToFunction.find(hash); diff --git a/Source/Core/Core/HLE/HLE.cpp b/Source/Core/Core/HLE/HLE.cpp index 024e984e1c..f95275a6f6 100644 --- a/Source/Core/Core/HLE/HLE.cpp +++ b/Source/Core/Core/HLE/HLE.cpp @@ -109,8 +109,7 @@ void PatchFunctions() if (OSPatches[i].flags == HLE_TYPE_FIXED) continue; - Symbol* symbol = g_symbolDB.GetSymbolFromName(OSPatches[i].m_szPatchName); - if (symbol) + for (const auto& symbol : g_symbolDB.GetSymbolsFromName(OSPatches[i].m_szPatchName)) { for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4) { @@ -125,8 +124,7 @@ void PatchFunctions() { for (size_t i = 1; i < ArraySize(OSBreakPoints); ++i) { - Symbol* symbol = g_symbolDB.GetSymbolFromName(OSBreakPoints[i].m_szPatchName); - if (symbol) + for (const auto& symbol : g_symbolDB.GetSymbolsFromName(OSBreakPoints[i].m_szPatchName)) { PowerPC::breakpoints.Add(symbol->address, false); INFO_LOG(OSHLE, "Adding BP to %s %08x", OSBreakPoints[i].m_szPatchName, symbol->address); @@ -211,7 +209,7 @@ u32 UnPatch(const std::string& patch_name) return addr; } - if (Symbol* symbol = g_symbolDB.GetSymbolFromName(patch_name)) + for (const auto& symbol : g_symbolDB.GetSymbolsFromName(patch_name)) { for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4) { From 7e974f10644101fbcacdd1131bd3af8395f2505d Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 5 Oct 2016 15:51:12 +0100 Subject: [PATCH 2/3] SymbolDB: GetSymbolsFromHash added --- Source/Core/Common/SymbolDB.cpp | 20 +++++++++++++++++++ Source/Core/Common/SymbolDB.h | 10 ++-------- .../Core/PowerPC/SignatureDB/SignatureDB.cpp | 6 ++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Source/Core/Common/SymbolDB.cpp b/Source/Core/Common/SymbolDB.cpp index 564ac55eb3..b4c64b4d91 100644 --- a/Source/Core/Common/SymbolDB.cpp +++ b/Source/Core/Common/SymbolDB.cpp @@ -61,6 +61,26 @@ std::vector SymbolDB::GetSymbolsFromName(const std::string& name) return symbols; } +Symbol* SymbolDB::GetSymbolFromHash(u32 hash) +{ + XFuncPtrMap::iterator iter = checksumToFunction.find(hash); + if (iter != checksumToFunction.end()) + return iter->second; + else + return nullptr; +} + +std::vector SymbolDB::GetSymbolsFromHash(u32 hash) +{ + std::vector symbols; + + for (const auto& iter : checksumToFunction) + if (iter.first == hash) + symbols.push_back(iter.second); + + return symbols; +} + void SymbolDB::AddCompleteSymbol(const Symbol& symbol) { functions.emplace(symbol.address, symbol); diff --git a/Source/Core/Common/SymbolDB.h b/Source/Core/Common/SymbolDB.h index 453e37fe76..ef7f4664ee 100644 --- a/Source/Core/Common/SymbolDB.h +++ b/Source/Core/Common/SymbolDB.h @@ -72,14 +72,8 @@ public: Symbol* GetSymbolFromName(const std::string& name); std::vector GetSymbolsFromName(const std::string& name); - Symbol* GetSymbolFromHash(u32 hash) - { - XFuncPtrMap::iterator iter = checksumToFunction.find(hash); - if (iter != checksumToFunction.end()) - return iter->second; - else - return nullptr; - } + Symbol* GetSymbolFromHash(u32 hash); + std::vector GetSymbolsFromHash(u32 hash); const XFuncMap& Symbols() const { return functions; } XFuncMap& AccessSymbols() { return functions; } diff --git a/Source/Core/Core/PowerPC/SignatureDB/SignatureDB.cpp b/Source/Core/Core/PowerPC/SignatureDB/SignatureDB.cpp index 93485c43d0..5581f490fd 100644 --- a/Source/Core/Core/PowerPC/SignatureDB/SignatureDB.cpp +++ b/Source/Core/Core/PowerPC/SignatureDB/SignatureDB.cpp @@ -72,12 +72,10 @@ void SignatureDB::Apply(PPCSymbolDB* symbol_db) { for (const auto& entry : m_database) { - u32 hash = entry.first; - Symbol* function = symbol_db->GetSymbolFromHash(hash); - if (function) + for (const auto& function : symbol_db->GetSymbolsFromHash(entry.first)) { // Found the function. Let's rename it according to the symbol file. - if (entry.second.size == (unsigned int)function->size) + if (entry.second.size == static_cast(function->size)) { function->name = entry.second.name; INFO_LOG(OSHLE, "Found %s at %08x (size: %08x)!", entry.second.name.c_str(), From 8d812db9ad31c7104760612375e43e2fe79428ca Mon Sep 17 00:00:00 2001 From: Sepalani Date: Mon, 10 Oct 2016 23:35:33 +0100 Subject: [PATCH 3/3] SymbolDB: Use set to map hash with symbols --- Source/Core/Common/SymbolDB.cpp | 5 +++-- Source/Core/Common/SymbolDB.h | 3 ++- Source/Core/Core/PowerPC/PPCSymbolDB.cpp | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/Core/Common/SymbolDB.cpp b/Source/Core/Common/SymbolDB.cpp index b4c64b4d91..f558b54ebb 100644 --- a/Source/Core/Common/SymbolDB.cpp +++ b/Source/Core/Common/SymbolDB.cpp @@ -65,7 +65,7 @@ Symbol* SymbolDB::GetSymbolFromHash(u32 hash) { XFuncPtrMap::iterator iter = checksumToFunction.find(hash); if (iter != checksumToFunction.end()) - return iter->second; + return *iter->second.begin(); else return nullptr; } @@ -76,7 +76,8 @@ std::vector SymbolDB::GetSymbolsFromHash(u32 hash) for (const auto& iter : checksumToFunction) if (iter.first == hash) - symbols.push_back(iter.second); + for (const auto& symbol : iter.second) + symbols.push_back(symbol); return symbols; } diff --git a/Source/Core/Common/SymbolDB.h b/Source/Core/Common/SymbolDB.h index ef7f4664ee..e1aab41f94 100644 --- a/Source/Core/Common/SymbolDB.h +++ b/Source/Core/Common/SymbolDB.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include @@ -57,7 +58,7 @@ class SymbolDB { public: typedef std::map XFuncMap; - typedef std::map XFuncPtrMap; + typedef std::map> XFuncPtrMap; protected: XFuncMap functions; diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp index e20a1bfb0c..adc7e56416 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp @@ -57,7 +57,7 @@ Symbol* PPCSymbolDB::AddFunction(u32 startAddr) // LOG(OSHLE, "Symbol found at %08x", startAddr); functions[startAddr] = tempFunc; tempFunc.type = Symbol::Type::Function; - checksumToFunction[tempFunc.hash] = &(functions[startAddr]); + checksumToFunction[tempFunc.hash].insert(&functions[startAddr]); return &functions[startAddr]; } } @@ -86,7 +86,7 @@ void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& nam if (tf.type == Symbol::Type::Function) { PPCAnalyst::AnalyzeFunction(startAddr, tf, size); - checksumToFunction[tf.hash] = &(functions[startAddr]); + checksumToFunction[tf.hash].insert(&functions[startAddr]); tf.function_name = GetStrippedFunctionName(name); } tf.size = size;