2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2014-02-20 03:11:52 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-09-19 04:17:41 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Common/SymbolDB.h"
|
2009-07-06 02:10:26 +00:00
|
|
|
|
2017-08-16 01:40:24 +00:00
|
|
|
static std::string GetStrippedFunctionName(const std::string& symbol_name)
|
|
|
|
{
|
|
|
|
std::string name = symbol_name.substr(0, symbol_name.find('('));
|
|
|
|
size_t position = name.find(' ');
|
|
|
|
if (position != std::string::npos)
|
|
|
|
name.erase(position);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Symbol::Rename(const std::string& symbol_name)
|
|
|
|
{
|
|
|
|
this->name = symbol_name;
|
|
|
|
this->function_name = GetStrippedFunctionName(symbol_name);
|
|
|
|
}
|
|
|
|
|
2009-07-06 02:10:26 +00:00
|
|
|
void SymbolDB::List()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (const auto& func : functions)
|
|
|
|
{
|
|
|
|
DEBUG_LOG(OSHLE, "%s @ %08x: %i bytes (hash %08x) : %i calls", func.second.name.c_str(),
|
|
|
|
func.second.address, func.second.size, func.second.hash, func.second.numCalls);
|
|
|
|
}
|
|
|
|
INFO_LOG(OSHLE, "%zu functions known in this program above.", functions.size());
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-21 19:46:25 +00:00
|
|
|
void SymbolDB::Clear(const char* prefix)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// TODO: honor prefix
|
|
|
|
functions.clear();
|
|
|
|
checksumToFunction.clear();
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SymbolDB::Index()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
int i = 0;
|
|
|
|
for (auto& func : functions)
|
|
|
|
{
|
|
|
|
func.second.index = i++;
|
|
|
|
}
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
Symbol* SymbolDB::GetSymbolFromName(const std::string& name)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (auto& func : functions)
|
|
|
|
{
|
2016-09-26 13:41:57 +00:00
|
|
|
if (func.second.function_name == name)
|
2016-06-24 08:43:46 +00:00
|
|
|
return &func.second;
|
|
|
|
}
|
2014-03-12 19:33:41 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return nullptr;
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 16:33:25 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:51:12 +00:00
|
|
|
Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
|
|
|
|
{
|
|
|
|
XFuncPtrMap::iterator iter = checksumToFunction.find(hash);
|
|
|
|
if (iter != checksumToFunction.end())
|
2016-10-10 22:35:33 +00:00
|
|
|
return *iter->second.begin();
|
2016-10-05 14:51:12 +00:00
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
|
|
|
|
{
|
2017-02-18 10:26:49 +00:00
|
|
|
const auto iter = checksumToFunction.find(hash);
|
2016-10-05 14:51:12 +00:00
|
|
|
|
2017-02-18 10:26:49 +00:00
|
|
|
if (iter == checksumToFunction.cend())
|
|
|
|
return {};
|
2016-10-05 14:51:12 +00:00
|
|
|
|
2017-02-18 10:26:49 +00:00
|
|
|
return {iter->second.cbegin(), iter->second.cend()};
|
2016-10-05 14:51:12 +00:00
|
|
|
}
|
|
|
|
|
2016-01-21 20:27:56 +00:00
|
|
|
void SymbolDB::AddCompleteSymbol(const Symbol& symbol)
|
2009-07-06 02:10:26 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
functions.emplace(symbol.address, symbol);
|
2009-07-06 02:10:26 +00:00
|
|
|
}
|