Files
dolphin/Source/Core/Common/SymbolDB.cpp
T

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

114 lines
2.4 KiB
C++
Raw Normal View History

// Copyright 2009 Dolphin Emulator Project
2015-05-18 01:08:10 +02:00
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <cstring>
#include <map>
#include <string>
#include <utility>
2014-09-07 20:06:58 -05:00
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/SymbolDB.h"
namespace Common
{
2017-08-16 02:40:24 +01: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;
}
SymbolDB::SymbolDB() = default;
SymbolDB::~SymbolDB() = default;
2017-08-16 02:40:24 +01:00
void Symbol::Rename(const std::string& symbol_name)
{
this->name = symbol_name;
this->function_name = GetStrippedFunctionName(symbol_name);
}
void SymbolDB::List()
{
2018-05-27 17:15:20 -04:00
for (const auto& func : m_functions)
{
DEBUG_LOG(OSHLE, "%s @ %08x: %i bytes (hash %08x) : %i calls", func.second.name.c_str(),
2018-05-27 17:15:20 -04:00
func.second.address, func.second.size, func.second.hash, func.second.num_calls);
}
2018-05-27 17:15:20 -04:00
INFO_LOG(OSHLE, "%zu functions known in this program above.", m_functions.size());
}
bool SymbolDB::IsEmpty() const
{
return m_functions.empty();
}
2016-01-21 20:46:25 +01:00
void SymbolDB::Clear(const char* prefix)
{
// TODO: honor prefix
2018-05-27 17:15:20 -04:00
m_functions.clear();
m_checksum_to_function.clear();
}
void SymbolDB::Index()
{
int i = 0;
2018-05-27 17:15:20 -04:00
for (auto& func : m_functions)
{
func.second.index = i++;
}
}
Symbol* SymbolDB::GetSymbolFromName(std::string_view name)
{
2018-05-27 17:15:20 -04:00
for (auto& func : m_functions)
{
if (func.second.function_name == name)
return &func.second;
}
2014-03-12 15:33:41 -04:00
2014-03-09 21:14:26 +01:00
return nullptr;
}
std::vector<Symbol*> SymbolDB::GetSymbolsFromName(std::string_view name)
2016-10-04 17:33:25 +01:00
{
std::vector<Symbol*> symbols;
2018-05-27 17:15:20 -04:00
for (auto& func : m_functions)
2016-10-04 17:33:25 +01:00
{
if (func.second.function_name == name)
symbols.push_back(&func.second);
}
return symbols;
}
2016-10-05 15:51:12 +01:00
Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
{
2018-05-27 17:15:20 -04:00
auto iter = m_checksum_to_function.find(hash);
if (iter == m_checksum_to_function.end())
2016-10-05 15:51:12 +01:00
return nullptr;
2018-05-27 17:15:20 -04:00
return *iter->second.begin();
2016-10-05 15:51:12 +01:00
}
std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
{
2018-05-27 17:15:20 -04:00
const auto iter = m_checksum_to_function.find(hash);
2016-10-05 15:51:12 +01:00
2018-05-27 17:15:20 -04:00
if (iter == m_checksum_to_function.cend())
2017-02-18 05:26:49 -05:00
return {};
2016-10-05 15:51:12 +01:00
2017-02-18 05:26:49 -05:00
return {iter->second.cbegin(), iter->second.cend()};
2016-10-05 15:51:12 +01:00
}
2016-01-21 21:27:56 +01:00
void SymbolDB::AddCompleteSymbol(const Symbol& symbol)
{
2018-05-27 17:15:20 -04:00
m_functions.emplace(symbol.address, symbol);
}
} // namespace Common