Permalink
Browse files

Merge pull request #6994 from lioncash/symbol

SymbolDB: Minor changes
  • Loading branch information...
leoetlino committed May 27, 2018
2 parents 31045f3 + f4ec419 commit 5fdf171967ddb63d12f9f410178d6b7bc7115ee4
@@ -11,6 +11,8 @@
#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('('));
@@ -20,6 +22,10 @@ static std::string GetStrippedFunctionName(const std::string& symbol_name)
return name;
}
SymbolDB::SymbolDB() = default;
SymbolDB::~SymbolDB() = default;
void Symbol::Rename(const std::string& symbol_name)
{
this->name = symbol_name;
@@ -28,33 +34,33 @@ void Symbol::Rename(const std::string& symbol_name)
void SymbolDB::List()
{
for (const auto& func : functions)
for (const auto& func : m_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);
func.second.address, func.second.size, func.second.hash, func.second.num_calls);
}
INFO_LOG(OSHLE, "%zu functions known in this program above.", functions.size());
INFO_LOG(OSHLE, "%zu functions known in this program above.", m_functions.size());
}
void SymbolDB::Clear(const char* prefix)
{
// TODO: honor prefix
functions.clear();
checksumToFunction.clear();
m_functions.clear();
m_checksum_to_function.clear();
}
void SymbolDB::Index()
{
int i = 0;
for (auto& func : functions)
for (auto& func : m_functions)
{
func.second.index = i++;
}
}
Symbol* SymbolDB::GetSymbolFromName(const std::string& name)
{
for (auto& func : functions)
for (auto& func : m_functions)
{
if (func.second.function_name == name)
return &func.second;
@@ -67,7 +73,7 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromName(const std::string& name)
{
std::vector<Symbol*> symbols;
for (auto& func : functions)
for (auto& func : m_functions)
{
if (func.second.function_name == name)
symbols.push_back(&func.second);
@@ -78,24 +84,25 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromName(const std::string& name)
Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
{
XFuncPtrMap::iterator iter = checksumToFunction.find(hash);
if (iter != checksumToFunction.end())
return *iter->second.begin();
else
auto iter = m_checksum_to_function.find(hash);
if (iter == m_checksum_to_function.end())
return nullptr;
return *iter->second.begin();
}
std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
{
const auto iter = checksumToFunction.find(hash);
const auto iter = m_checksum_to_function.find(hash);
if (iter == checksumToFunction.cend())
if (iter == m_checksum_to_function.cend())
return {};
return {iter->second.cbegin(), iter->second.cend()};
}
void SymbolDB::AddCompleteSymbol(const Symbol& symbol)
{
functions.emplace(symbol.address, symbol);
m_functions.emplace(symbol.address, symbol);
}
} // namespace Common
@@ -15,11 +15,13 @@
#include "Common/CommonTypes.h"
namespace Common
{
struct SCall
{
SCall(u32 a, u32 b) : function(a), callAddress(b) {}
SCall(u32 a, u32 b) : function(a), call_address(b) {}
u32 function;
u32 callAddress;
u32 call_address;
};
struct Symbol
@@ -40,7 +42,7 @@ struct Symbol
u32 address = 0;
u32 flags = 0;
u32 size = 0;
int numCalls = 0;
int num_calls = 0;
Type type = Type::Function;
int index = 0; // only used for coloring the disasm view
bool analyzed = false;
@@ -59,28 +61,29 @@ enum
class SymbolDB
{
public:
typedef std::map<u32, Symbol> XFuncMap;
typedef std::map<u32, std::set<Symbol*>> XFuncPtrMap;
using XFuncMap = std::map<u32, Symbol>;
using XFuncPtrMap = std::map<u32, std::set<Symbol*>>;
protected:
XFuncMap functions;
XFuncPtrMap checksumToFunction;
SymbolDB();
virtual ~SymbolDB();
public:
SymbolDB() {}
virtual ~SymbolDB() {}
virtual Symbol* GetSymbolFromAddr(u32 addr) { return nullptr; }
virtual Symbol* AddFunction(u32 startAddr) { return nullptr; }
virtual Symbol* AddFunction(u32 start_addr) { return nullptr; }
void AddCompleteSymbol(const Symbol& symbol);
Symbol* GetSymbolFromName(const std::string& name);
std::vector<Symbol*> GetSymbolsFromName(const std::string& name);
Symbol* GetSymbolFromHash(u32 hash);
std::vector<Symbol*> GetSymbolsFromHash(u32 hash);
const XFuncMap& Symbols() const { return functions; }
XFuncMap& AccessSymbols() { return functions; }
const XFuncMap& Symbols() const { return m_functions; }
XFuncMap& AccessSymbols() { return m_functions; }
void Clear(const char* prefix = "");
void List();
void Index();
protected:
XFuncMap m_functions;
XFuncPtrMap m_checksum_to_function;
};
} // namespace Common
@@ -204,14 +204,14 @@ bool ElfReader::LoadSymbols() const
if (bRelocate)
value += sectionAddrs[sectionIndex];
auto symtype = Symbol::Type::Data;
auto symtype = Common::Symbol::Type::Data;
switch (type)
{
case STT_OBJECT:
symtype = Symbol::Type::Data;
symtype = Common::Symbol::Type::Data;
break;
case STT_FUNC:
symtype = Symbol::Type::Function;
symtype = Common::Symbol::Type::Function;
break;
default:
continue;
@@ -29,7 +29,7 @@ void AddAutoBreakpoints()
for (const char* bp : bps)
{
Symbol* symbol = g_symbolDB.GetSymbolFromName(bp);
Common::Symbol* symbol = g_symbolDB.GetSymbolFromName(bp);
if (symbol)
PowerPC::breakpoints.Add(symbol->address, false);
}
@@ -310,10 +310,10 @@ int PPCDebugInterface::GetColor(unsigned int address)
0xd0FFd0, // light green
0xFFFFd0, // light yellow
};
Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address);
Common::Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address);
if (!symbol)
return 0xFFFFFF;
if (symbol->type != Symbol::Type::Function)
if (symbol->type != Common::Symbol::Type::Function)
return 0xEEEEFF;
return colors[symbol->index % 6];
}
@@ -376,7 +376,7 @@ void RSOView::Apply(PPCSymbolDB* symbol_db) const
u32 address = GetExportAddress(rso_export);
if (address != 0)
{
Symbol* symbol = symbol_db->AddFunction(address);
Common::Symbol* symbol = symbol_db->AddFunction(address);
if (!symbol)
symbol = symbol_db->GetSymbolFromAddr(address);
@@ -389,7 +389,7 @@ void RSOView::Apply(PPCSymbolDB* symbol_db) const
else
{
// Data symbol
symbol_db->AddKnownSymbol(address, 0, export_name, Symbol::Type::Data);
symbol_db->AddKnownSymbol(address, 0, export_name, Common::Symbol::Type::Data);
}
}
}
@@ -277,10 +277,10 @@ int DSPDebugInterface::GetColor(unsigned int address)
if (addr == -1)
return 0xFFFFFF;
Symbol* symbol = Symbols::g_dsp_symbol_db.GetSymbolFromAddr(addr);
Common::Symbol* symbol = Symbols::g_dsp_symbol_db.GetSymbolFromAddr(addr);
if (!symbol)
return 0xFFFFFF;
if (symbol->type != Symbol::Type::Function)
if (symbol->type != Common::Symbol::Type::Function)
return 0xEEEEFF;
return colors[symbol->index % 6];
}
@@ -59,22 +59,19 @@ const char* GetLineText(int line)
}
}
Symbol* DSPSymbolDB::GetSymbolFromAddr(u32 addr)
Common::Symbol* DSPSymbolDB::GetSymbolFromAddr(u32 addr)
{
XFuncMap::iterator it = functions.find(addr);
auto it = m_functions.find(addr);
if (it != functions.end())
{
if (it != m_functions.end())
return &it->second;
}
else
for (auto& func : m_functions)
{
for (auto& func : functions)
{
if (addr >= func.second.address && addr < func.second.address + func.second.size)
return &func.second;
}
if (addr >= func.second.address && addr < func.second.address + func.second.size)
return &func.second;
}
return nullptr;
}
@@ -13,12 +13,12 @@ namespace DSP
{
namespace Symbols
{
class DSPSymbolDB : public SymbolDB
class DSPSymbolDB : public Common::SymbolDB
{
public:
DSPSymbolDB() {}
~DSPSymbolDB() {}
Symbol* GetSymbolFromAddr(u32 addr) override;
Common::Symbol* GetSymbolFromAddr(u32 addr) override;
};
extern DSPSymbolDB g_dsp_symbol_db;
@@ -133,7 +133,7 @@ void JitBaseBlockCache::FinalizeBlock(JitBlock& block, bool block_link,
LinkBlock(block);
}
Symbol* symbol = nullptr;
Common::Symbol* symbol = nullptr;
if (JitRegister::IsEnabled() &&
(symbol = g_symbolDB.GetSymbolFromAddr(block.effectiveAddress)) != nullptr)
{
Oops, something went wrong.

0 comments on commit 5fdf171

Please sign in to comment.