Merge pull request #4299 from sepalani/hle_symbols

SymbolDB: Multiple symbols detection allowed
This commit is contained in:
Matthew Parlane 2017-01-13 10:05:32 +13:00 committed by GitHub
commit 5790f15be8
5 changed files with 46 additions and 20 deletions

View File

@ -48,6 +48,40 @@ Symbol* SymbolDB::GetSymbolFromName(const std::string& name)
return nullptr;
}
std::vector<Symbol*> SymbolDB::GetSymbolsFromName(const std::string& name)
{
std::vector<Symbol*> symbols;
for (auto& func : functions)
{
if (func.second.function_name == name)
symbols.push_back(&func.second);
}
return symbols;
}
Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
{
XFuncPtrMap::iterator iter = checksumToFunction.find(hash);
if (iter != checksumToFunction.end())
return *iter->second.begin();
else
return nullptr;
}
std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
{
std::vector<Symbol*> symbols;
for (const auto& iter : checksumToFunction)
if (iter.first == hash)
for (const auto& symbol : iter.second)
symbols.push_back(symbol);
return symbols;
}
void SymbolDB::AddCompleteSymbol(const Symbol& symbol)
{
functions.emplace(symbol.address, symbol);

View File

@ -8,6 +8,7 @@
#pragma once
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
@ -57,7 +58,7 @@ class SymbolDB
{
public:
typedef std::map<u32, Symbol> XFuncMap;
typedef std::map<u32, Symbol*> XFuncPtrMap;
typedef std::map<u32, std::set<Symbol*>> XFuncPtrMap;
protected:
XFuncMap functions;
@ -71,14 +72,9 @@ public:
void AddCompleteSymbol(const Symbol& symbol);
Symbol* GetSymbolFromName(const std::string& name);
Symbol* GetSymbolFromHash(u32 hash)
{
XFuncPtrMap::iterator iter = checksumToFunction.find(hash);
if (iter != checksumToFunction.end())
return iter->second;
else
return nullptr;
}
std::vector<Symbol*> GetSymbolsFromName(const std::string& name);
Symbol* GetSymbolFromHash(u32 hash);
std::vector<Symbol*> GetSymbolsFromHash(u32 hash);
const XFuncMap& Symbols() const { return functions; }
XFuncMap& AccessSymbols() { return functions; }

View File

@ -110,8 +110,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)
{
@ -126,8 +125,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);
@ -212,7 +210,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)
{

View File

@ -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;

View File

@ -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<unsigned int>(function->size))
{
function->name = entry.second.name;
INFO_LOG(OSHLE, "Found %s at %08x (size: %08x)!", entry.second.name.c_str(),