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