dolphin/Source/Core/Common/SymbolDB.cpp

102 lines
2.2 KiB
C++
Raw Normal View History

// Copyright 2009 Dolphin Emulator Project
2015-05-17 17:08:10 -06:00
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <cstring>
#include <map>
#include <string>
#include <utility>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/SymbolDB.h"
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);
}
void SymbolDB::List()
{
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());
}
void SymbolDB::Clear(const char* prefix)
{
// TODO: honor prefix
functions.clear();
checksumToFunction.clear();
}
void SymbolDB::Index()
{
int i = 0;
for (auto& func : functions)
{
func.second.index = i++;
}
}
Symbol* SymbolDB::GetSymbolFromName(const std::string& name)
{
for (auto& func : functions)
{
if (func.second.function_name == name)
return &func.second;
}
return nullptr;
}
2016-10-04 10:33:25 -06: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 08:51:12 -06:00
Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
{
XFuncPtrMap::iterator iter = checksumToFunction.find(hash);
if (iter != checksumToFunction.end())
return *iter->second.begin();
2016-10-05 08:51:12 -06:00
else
return nullptr;
}
std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
{
const auto iter = checksumToFunction.find(hash);
2016-10-05 08:51:12 -06:00
if (iter == checksumToFunction.cend())
return {};
2016-10-05 08:51:12 -06:00
return {iter->second.cbegin(), iter->second.cend()};
2016-10-05 08:51:12 -06:00
}
2016-01-21 13:27:56 -07:00
void SymbolDB::AddCompleteSymbol(const Symbol& symbol)
{
functions.emplace(symbol.address, symbol);
}