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