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()
{
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++;
}
@ -54,7 +54,7 @@ void SymbolDB::Index()
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 +67,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,18 +78,18 @@ 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()};
@ -97,5 +97,5 @@ std::vector<Symbol*> SymbolDB::GetSymbolsFromHash(u32 hash)
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
{
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 +40,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;
@ -62,15 +62,10 @@ public:
typedef std::map<u32, Symbol> XFuncMap;
typedef std::map<u32, std::set<Symbol*>> XFuncPtrMap;
protected:
XFuncMap functions;
XFuncPtrMap checksumToFunction;
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);
@ -78,9 +73,13 @@ public:
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;
};

View File

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

View File

@ -31,25 +31,25 @@ PPCSymbolDB::~PPCSymbolDB() = default;
Symbol* PPCSymbolDB::AddFunction(u32 start_addr)
{
// It's already in the list
if (functions.find(start_addr) != functions.end())
if (m_functions.find(start_addr) != m_functions.end())
return nullptr;
Symbol symbol;
if (!PPCAnalyst::AnalyzeFunction(start_addr, symbol))
return nullptr;
functions[start_addr] = std::move(symbol);
Symbol* ptr = &functions[start_addr];
m_functions[start_addr] = std::move(symbol);
Symbol* ptr = &m_functions[start_addr];
ptr->type = Symbol::Type::Function;
checksumToFunction[ptr->hash].insert(ptr);
m_checksum_to_function[ptr->hash].insert(ptr);
return ptr;
}
void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& name,
Symbol::Type type)
{
auto iter = functions.find(startAddr);
if (iter != functions.end())
auto iter = m_functions.find(startAddr);
if (iter != m_functions.end())
{
// already got it, let's just update name, checksum & size to be sure.
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);
tf.size = size;
}
checksumToFunction[tf.hash].insert(&functions[startAddr]);
m_checksum_to_function[tf.hash].insert(&m_functions[startAddr]);
}
else
{
tf.size = size;
}
functions[startAddr] = tf;
m_functions[startAddr] = tf;
}
}
Symbol* PPCSymbolDB::GetSymbolFromAddr(u32 addr)
{
auto it = functions.lower_bound(addr);
if (it == functions.end())
auto it = m_functions.lower_bound(addr);
if (it == m_functions.end())
return nullptr;
// 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;
// Otherwise, check whether the address is within the bounds of a symbol.
if (it != functions.begin())
if (it != m_functions.begin())
--it;
if (addr >= it->second.address && addr < it->second.address + it->second.size)
return &it->second;
@ -115,21 +115,21 @@ std::string PPCSymbolDB::GetDescription(u32 addr)
void PPCSymbolDB::FillInCallers()
{
for (auto& p : functions)
for (auto& p : m_functions)
{
p.second.callers.clear();
}
for (auto& entry : functions)
for (auto& entry : m_functions)
{
Symbol& f = entry.second;
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;
auto func_iter = functions.find(function_address);
if (func_iter != functions.end())
auto func_iter = m_functions.find(function_address);
if (func_iter != m_functions.end())
{
Symbol& called_function = func_iter->second;
called_function.callers.push_back(new_call);
@ -146,8 +146,8 @@ void PPCSymbolDB::FillInCallers()
void PPCSymbolDB::PrintCalls(u32 funcAddr) const
{
const auto iter = functions.find(funcAddr);
if (iter == functions.end())
const auto iter = m_functions.find(funcAddr);
if (iter == m_functions.end())
{
WARN_LOG(SYMBOLS, "Symbol does not exist");
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);
for (const SCall& call : f.calls)
{
const auto n = functions.find(call.function);
if (n != functions.end())
const auto n = m_functions.find(call.function);
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
{
const auto iter = functions.find(funcAddr);
if (iter == functions.end())
const auto iter = m_functions.find(funcAddr);
if (iter == m_functions.end())
return;
const Symbol& f = iter->second;
DEBUG_LOG(SYMBOLS, "The function %s at %08x is called by:", f.name.c_str(), f.address);
for (const SCall& caller : f.callers)
{
const auto n = functions.find(caller.function);
if (n != functions.end())
const auto n = m_functions.find(caller.function);
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)
{
auto iter = functions.find(addr);
if (iter == functions.end())
auto iter = m_functions.find(addr);
if (iter == m_functions.end())
return;
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,
@ -426,7 +426,7 @@ bool PPCSymbolDB::SaveSymbolMap(const std::string& filename) const
std::vector<const Symbol*> function_symbols;
std::vector<const Symbol*> data_symbols;
for (const auto& function : functions)
for (const auto& function : m_functions)
{
const Symbol& symbol = function.second;
if (symbol.type == Symbol::Type::Function)
@ -472,7 +472,7 @@ bool PPCSymbolDB::SaveCodeMap(const std::string& filename) const
fprintf(f.GetHandle(), ".text\n");
u32 next_address = 0;
for (const auto& function : functions)
for (const auto& function : m_functions)
{
const Symbol& symbol = function.second;

View File

@ -347,7 +347,7 @@ void CodeWidget::UpdateFunctionCallers(const Symbol* symbol)
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);
if (caller_symbol)

View File

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