SymbolDB: Normalize variable names

Normalizes variable naming so that it adheres to our coding style

While we're at it do minor cleanup relating to modified lines
This commit is contained in:
Lioncash 2018-05-27 17:15:20 -04:00
parent 512c6fee51
commit e9b9797a86
6 changed files with 65 additions and 69 deletions

View File

@ -28,25 +28,25 @@ void Symbol::Rename(const std::string& symbol_name)
void SymbolDB::List() 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(), 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) void SymbolDB::Clear(const char* prefix)
{ {
// TODO: honor prefix // TODO: honor prefix
functions.clear(); m_functions.clear();
checksumToFunction.clear(); m_checksum_to_function.clear();
} }
void SymbolDB::Index() void SymbolDB::Index()
{ {
int i = 0; int i = 0;
for (auto& func : functions) for (auto& func : m_functions)
{ {
func.second.index = i++; func.second.index = i++;
} }
@ -54,7 +54,7 @@ void SymbolDB::Index()
Symbol* SymbolDB::GetSymbolFromName(const std::string& name) Symbol* SymbolDB::GetSymbolFromName(const std::string& name)
{ {
for (auto& func : functions) for (auto& func : m_functions)
{ {
if (func.second.function_name == name) if (func.second.function_name == name)
return &func.second; return &func.second;
@ -67,7 +67,7 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromName(const std::string& name)
{ {
std::vector<Symbol*> symbols; std::vector<Symbol*> symbols;
for (auto& func : functions) for (auto& func : m_functions)
{ {
if (func.second.function_name == name) if (func.second.function_name == name)
symbols.push_back(&func.second); symbols.push_back(&func.second);
@ -78,18 +78,18 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromName(const std::string& name)
Symbol* SymbolDB::GetSymbolFromHash(u32 hash) Symbol* SymbolDB::GetSymbolFromHash(u32 hash)
{ {
XFuncPtrMap::iterator iter = checksumToFunction.find(hash); auto iter = m_checksum_to_function.find(hash);
if (iter != checksumToFunction.end()) if (iter == m_checksum_to_function.end())
return *iter->second.begin();
else
return nullptr; return nullptr;
return *iter->second.begin();
} }
std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash) 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 {};
return {iter->second.cbegin(), iter->second.cend()}; return {iter->second.cbegin(), iter->second.cend()};
@ -97,5 +97,5 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
void SymbolDB::AddCompleteSymbol(const Symbol& symbol) void SymbolDB::AddCompleteSymbol(const Symbol& symbol)
{ {
functions.emplace(symbol.address, symbol); m_functions.emplace(symbol.address, symbol);
} }

View File

@ -17,9 +17,9 @@
struct SCall struct SCall
{ {
SCall(u32 a, u32 b) : function(a), callAddress(b) {} SCall(u32 a, u32 b) : function(a), call_address(b) {}
u32 function; u32 function;
u32 callAddress; u32 call_address;
}; };
struct Symbol struct Symbol
@ -40,7 +40,7 @@ struct Symbol
u32 address = 0; u32 address = 0;
u32 flags = 0; u32 flags = 0;
u32 size = 0; u32 size = 0;
int numCalls = 0; int num_calls = 0;
Type type = Type::Function; Type type = Type::Function;
int index = 0; // only used for coloring the disasm view int index = 0; // only used for coloring the disasm view
bool analyzed = false; bool analyzed = false;
@ -62,15 +62,10 @@ public:
typedef std::map<u32, Symbol> XFuncMap; typedef std::map<u32, Symbol> XFuncMap;
typedef std::map<u32, std::set<Symbol*>> XFuncPtrMap; typedef std::map<u32, std::set<Symbol*>> XFuncPtrMap;
protected:
XFuncMap functions;
XFuncPtrMap checksumToFunction;
public:
SymbolDB() {} SymbolDB() {}
virtual ~SymbolDB() {} virtual ~SymbolDB() {}
virtual Symbol* GetSymbolFromAddr(u32 addr) { return nullptr; } 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); void AddCompleteSymbol(const Symbol& symbol);
Symbol* GetSymbolFromName(const std::string& name); Symbol* GetSymbolFromName(const std::string& name);
@ -78,9 +73,13 @@ public:
Symbol* GetSymbolFromHash(u32 hash); Symbol* GetSymbolFromHash(u32 hash);
std::vector<Symbol*> GetSymbolsFromHash(u32 hash); std::vector<Symbol*> GetSymbolsFromHash(u32 hash);
const XFuncMap& Symbols() const { return functions; } const XFuncMap& Symbols() const { return m_functions; }
XFuncMap& AccessSymbols() { return functions; } XFuncMap& AccessSymbols() { return m_functions; }
void Clear(const char* prefix = ""); void Clear(const char* prefix = "");
void List(); void List();
void Index(); void Index();
protected:
XFuncMap m_functions;
XFuncPtrMap m_checksum_to_function;
}; };

View File

@ -61,20 +61,17 @@ const char* GetLineText(int line)
Symbol* DSPSymbolDB::GetSymbolFromAddr(u32 addr) 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; 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) if (addr >= func.second.address && addr < func.second.address + func.second.size)
return &func.second; return &func.second;
} }
}
return nullptr; return nullptr;
} }

View File

@ -31,25 +31,25 @@ PPCSymbolDB::~PPCSymbolDB() = default;
Symbol* PPCSymbolDB::AddFunction(u32 start_addr) Symbol* PPCSymbolDB::AddFunction(u32 start_addr)
{ {
// It's already in the list // It's already in the list
if (functions.find(start_addr) != functions.end()) if (m_functions.find(start_addr) != m_functions.end())
return nullptr; return nullptr;
Symbol symbol; Symbol symbol;
if (!PPCAnalyst::AnalyzeFunction(start_addr, symbol)) if (!PPCAnalyst::AnalyzeFunction(start_addr, symbol))
return nullptr; return nullptr;
functions[start_addr] = std::move(symbol); m_functions[start_addr] = std::move(symbol);
Symbol* ptr = &functions[start_addr]; Symbol* ptr = &m_functions[start_addr];
ptr->type = Symbol::Type::Function; ptr->type = Symbol::Type::Function;
checksumToFunction[ptr->hash].insert(ptr); m_checksum_to_function[ptr->hash].insert(ptr);
return ptr; return ptr;
} }
void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& name, void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& name,
Symbol::Type type) Symbol::Type type)
{ {
auto iter = functions.find(startAddr); auto iter = m_functions.find(startAddr);
if (iter != functions.end()) if (iter != m_functions.end())
{ {
// already got it, let's just update name, checksum & size to be sure. // already got it, let's just update name, checksum & size to be sure.
Symbol* tempfunc = &iter->second; Symbol* tempfunc = &iter->second;
@ -75,20 +75,20 @@ void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& nam
name.c_str(), size, tf.size); name.c_str(), size, tf.size);
tf.size = size; tf.size = size;
} }
checksumToFunction[tf.hash].insert(&functions[startAddr]); m_checksum_to_function[tf.hash].insert(&m_functions[startAddr]);
} }
else else
{ {
tf.size = size; tf.size = size;
} }
functions[startAddr] = tf; m_functions[startAddr] = tf;
} }
} }
Symbol* PPCSymbolDB::GetSymbolFromAddr(u32 addr) Symbol* PPCSymbolDB::GetSymbolFromAddr(u32 addr)
{ {
auto it = functions.lower_bound(addr); auto it = m_functions.lower_bound(addr);
if (it == functions.end()) if (it == m_functions.end())
return nullptr; return nullptr;
// If the address is exactly the start address of a symbol, we're done. // If the address is exactly the start address of a symbol, we're done.
@ -96,7 +96,7 @@ Symbol* PPCSymbolDB::GetSymbolFromAddr(u32 addr)
return &it->second; return &it->second;
// Otherwise, check whether the address is within the bounds of a symbol. // Otherwise, check whether the address is within the bounds of a symbol.
if (it != functions.begin()) if (it != m_functions.begin())
--it; --it;
if (addr >= it->second.address && addr < it->second.address + it->second.size) if (addr >= it->second.address && addr < it->second.address + it->second.size)
return &it->second; return &it->second;
@ -115,21 +115,21 @@ std::string PPCSymbolDB::GetDescription(u32 addr)
void PPCSymbolDB::FillInCallers() void PPCSymbolDB::FillInCallers()
{ {
for (auto& p : functions) for (auto& p : m_functions)
{ {
p.second.callers.clear(); p.second.callers.clear();
} }
for (auto& entry : functions) for (auto& entry : m_functions)
{ {
Symbol& f = entry.second; Symbol& f = entry.second;
for (const SCall& call : f.calls) for (const SCall& call : f.calls)
{ {
const SCall new_call(entry.first, call.callAddress); const SCall new_call(entry.first, call.call_address);
const u32 function_address = call.function; const u32 function_address = call.function;
auto func_iter = functions.find(function_address); auto func_iter = m_functions.find(function_address);
if (func_iter != functions.end()) if (func_iter != m_functions.end())
{ {
Symbol& called_function = func_iter->second; Symbol& called_function = func_iter->second;
called_function.callers.push_back(new_call); called_function.callers.push_back(new_call);
@ -146,8 +146,8 @@ void PPCSymbolDB::FillInCallers()
void PPCSymbolDB::PrintCalls(u32 funcAddr) const void PPCSymbolDB::PrintCalls(u32 funcAddr) const
{ {
const auto iter = functions.find(funcAddr); const auto iter = m_functions.find(funcAddr);
if (iter == functions.end()) if (iter == m_functions.end())
{ {
WARN_LOG(SYMBOLS, "Symbol does not exist"); WARN_LOG(SYMBOLS, "Symbol does not exist");
return; return;
@ -157,40 +157,40 @@ void PPCSymbolDB::PrintCalls(u32 funcAddr) const
DEBUG_LOG(SYMBOLS, "The function %s at %08x calls:", f.name.c_str(), f.address); DEBUG_LOG(SYMBOLS, "The function %s at %08x calls:", f.name.c_str(), f.address);
for (const SCall& call : f.calls) for (const SCall& call : f.calls)
{ {
const auto n = functions.find(call.function); const auto n = m_functions.find(call.function);
if (n != functions.end()) if (n != m_functions.end())
{ {
DEBUG_LOG(SYMBOLS, "* %08x : %s", call.callAddress, n->second.name.c_str()); DEBUG_LOG(SYMBOLS, "* %08x : %s", call.call_address, n->second.name.c_str());
} }
} }
} }
void PPCSymbolDB::PrintCallers(u32 funcAddr) const void PPCSymbolDB::PrintCallers(u32 funcAddr) const
{ {
const auto iter = functions.find(funcAddr); const auto iter = m_functions.find(funcAddr);
if (iter == functions.end()) if (iter == m_functions.end())
return; return;
const Symbol& f = iter->second; const Symbol& f = iter->second;
DEBUG_LOG(SYMBOLS, "The function %s at %08x is called by:", f.name.c_str(), f.address); DEBUG_LOG(SYMBOLS, "The function %s at %08x is called by:", f.name.c_str(), f.address);
for (const SCall& caller : f.callers) for (const SCall& caller : f.callers)
{ {
const auto n = functions.find(caller.function); const auto n = m_functions.find(caller.function);
if (n != functions.end()) if (n != m_functions.end())
{ {
DEBUG_LOG(SYMBOLS, "* %08x : %s", caller.callAddress, n->second.name.c_str()); DEBUG_LOG(SYMBOLS, "* %08x : %s", caller.call_address, n->second.name.c_str());
} }
} }
} }
void PPCSymbolDB::LogFunctionCall(u32 addr) void PPCSymbolDB::LogFunctionCall(u32 addr)
{ {
auto iter = functions.find(addr); auto iter = m_functions.find(addr);
if (iter == functions.end()) if (iter == m_functions.end())
return; return;
Symbol& f = iter->second; Symbol& f = iter->second;
f.numCalls++; f.num_calls++;
} }
// The use case for handling bad map files is when you have a game with a map file on the disc, // The use case for handling bad map files is when you have a game with a map file on the disc,
@ -426,7 +426,7 @@ bool PPCSymbolDB::SaveSymbolMap(const std::string& filename) const
std::vector<const Symbol*> function_symbols; std::vector<const Symbol*> function_symbols;
std::vector<const Symbol*> data_symbols; std::vector<const Symbol*> data_symbols;
for (const auto& function : functions) for (const auto& function : m_functions)
{ {
const Symbol& symbol = function.second; const Symbol& symbol = function.second;
if (symbol.type == Symbol::Type::Function) if (symbol.type == Symbol::Type::Function)
@ -472,7 +472,7 @@ bool PPCSymbolDB::SaveCodeMap(const std::string& filename) const
fprintf(f.GetHandle(), ".text\n"); fprintf(f.GetHandle(), ".text\n");
u32 next_address = 0; u32 next_address = 0;
for (const auto& function : functions) for (const auto& function : m_functions)
{ {
const Symbol& symbol = function.second; const Symbol& symbol = function.second;

View File

@ -347,7 +347,7 @@ void CodeWidget::UpdateFunctionCallers(const Symbol* symbol)
for (const auto& caller : symbol->callers) for (const auto& caller : symbol->callers)
{ {
const u32 addr = caller.callAddress; const u32 addr = caller.call_address;
const Symbol* caller_symbol = g_symbolDB.GetSymbolFromAddr(addr); const Symbol* caller_symbol = g_symbolDB.GetSymbolFromAddr(addr);
if (caller_symbol) if (caller_symbol)

View File

@ -440,7 +440,7 @@ void CCodeWindow::UpdateLists()
for (auto& call : symbol->callers) for (auto& call : symbol->callers)
{ {
u32 caller_addr = call.callAddress; u32 caller_addr = call.call_address;
Symbol* caller_symbol = g_symbolDB.GetSymbolFromAddr(caller_addr); Symbol* caller_symbol = g_symbolDB.GetSymbolFromAddr(caller_addr);
if (caller_symbol) if (caller_symbol)
{ {