dolphin/Source/Core/Common/SymbolDB.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
2.4 KiB
C++
Raw Normal View History

// Copyright 2009 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <cstring>
#include <map>
#include <string>
#include <utility>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/SymbolDB.h"
namespace Common
{
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;
}
SymbolDB::SymbolDB() = default;
SymbolDB::~SymbolDB() = default;
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 : m_functions)
{
DEBUG_LOG_FMT(OSHLE, "{} @ {:08x}: {} bytes (hash {:08x}) : {} calls", func.second.name,
func.second.address, func.second.size, func.second.hash, func.second.num_calls);
}
INFO_LOG_FMT(OSHLE, "{} functions known in this program above.", m_functions.size());
}
bool SymbolDB::IsEmpty() const
{
return m_functions.empty();
}
void SymbolDB::Clear(const char* prefix)
{
// TODO: honor prefix
m_functions.clear();
m_checksum_to_function.clear();
}
void SymbolDB::Index()
{
int i = 0;
for (auto& func : m_functions)
{
func.second.index = i++;
}
}
Symbol* SymbolDB::GetSymbolFromName(std::string_view name)
{
for (auto& func : m_functions)
{
if (func.second.function_name == name)
return &func.second;
}
return nullptr;
}
std::vector<Symbol*> SymbolDB::GetSymbolsFromName(std::string_view name)
2016-10-04 16:33:25 +00:00
{
std::vector<Symbol*> symbols;
for (auto& func : m_functions)
2016-10-04 16:33:25 +00:00
{
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)
{
auto iter = m_checksum_to_function.find(hash);
if (iter == m_checksum_to_function.end())
2016-10-05 14:51:12 +00:00
return nullptr;
return *iter->second.begin();
2016-10-05 14:51:12 +00:00
}
std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
{
const auto iter = m_checksum_to_function.find(hash);
2016-10-05 14:51:12 +00:00
if (iter == m_checksum_to_function.cend())
return {};
2016-10-05 14:51:12 +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)
{
m_functions.emplace(symbol.address, symbol);
}
} // namespace Common