From d8d127df25f17e87147b53870531496d3e3825c3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 13 Sep 2016 20:47:00 -0400 Subject: [PATCH 1/3] SymbolDB: In-class initialize Symbol class variables --- Source/Core/Common/SymbolDB.h | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Source/Core/Common/SymbolDB.h b/Source/Core/Common/SymbolDB.h index c80dfcd7a9..dd65f5fe5d 100644 --- a/Source/Core/Common/SymbolDB.h +++ b/Source/Core/Common/SymbolDB.h @@ -29,21 +29,17 @@ struct Symbol SYMBOL_DATA = 1, }; - Symbol() : hash(0), address(0), flags(0), size(0), numCalls(0), type(SYMBOL_FUNCTION), analyzed(0) - { - } - std::string name; std::vector callers; // addresses of functions that call this function std::vector calls; // addresses of functions that are called by this function - u32 hash; // use for HLE function finding - u32 address; - u32 flags; - int size; - int numCalls; - int type; - int index; // only used for coloring the disasm view - int analyzed; + u32 hash = 0; // use for HLE function finding + u32 address = 0; + u32 flags = 0; + int size = 0; + int numCalls = 0; + int type = SYMBOL_FUNCTION; + int index = 0; // only used for coloring the disasm view + int analyzed = 0; }; enum From 0ac77b02882b51fd5c147b716e30ac5f65c57072 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 13 Sep 2016 21:01:35 -0400 Subject: [PATCH 2/3] SymbolDB: Use an enum class for representing symbol type --- Source/Core/Common/SymbolDB.h | 8 ++++---- Source/Core/Core/Boot/ElfReader.cpp | 6 +++--- Source/Core/Core/Debugger/PPCDebugInterface.cpp | 2 +- Source/Core/Core/HW/DSPLLE/DSPDebugInterface.cpp | 2 +- Source/Core/Core/PowerPC/PPCSymbolDB.cpp | 7 ++++--- Source/Core/Core/PowerPC/PPCSymbolDB.h | 2 +- Source/Core/DolphinWX/Debugger/CodeWindowFunctions.cpp | 2 +- Source/Core/DolphinWX/Debugger/DSPDebugWindow.cpp | 2 +- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Source/Core/Common/SymbolDB.h b/Source/Core/Common/SymbolDB.h index dd65f5fe5d..1b75a58b5f 100644 --- a/Source/Core/Common/SymbolDB.h +++ b/Source/Core/Common/SymbolDB.h @@ -23,10 +23,10 @@ struct SCall struct Symbol { - enum + enum class Type { - SYMBOL_FUNCTION = 0, - SYMBOL_DATA = 1, + Function, + Data, }; std::string name; @@ -37,7 +37,7 @@ struct Symbol u32 flags = 0; int size = 0; int numCalls = 0; - int type = SYMBOL_FUNCTION; + Type type = Type::Function; int index = 0; // only used for coloring the disasm view int analyzed = 0; }; diff --git a/Source/Core/Core/Boot/ElfReader.cpp b/Source/Core/Core/Boot/ElfReader.cpp index 6f86130de9..d7ab06eccf 100644 --- a/Source/Core/Core/Boot/ElfReader.cpp +++ b/Source/Core/Core/Boot/ElfReader.cpp @@ -182,14 +182,14 @@ bool ElfReader::LoadSymbols() if (bRelocate) value += sectionAddrs[sectionIndex]; - int symtype = Symbol::SYMBOL_DATA; + auto symtype = Symbol::Type::Data; switch (type) { case STT_OBJECT: - symtype = Symbol::SYMBOL_DATA; + symtype = Symbol::Type::Data; break; case STT_FUNC: - symtype = Symbol::SYMBOL_FUNCTION; + symtype = Symbol::Type::Function; break; default: continue; diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.cpp b/Source/Core/Core/Debugger/PPCDebugInterface.cpp index 1d7fd7343e..e96a44f923 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.cpp +++ b/Source/Core/Core/Debugger/PPCDebugInterface.cpp @@ -186,7 +186,7 @@ int PPCDebugInterface::GetColor(unsigned int address) Symbol* symbol = g_symbolDB.GetSymbolFromAddr(address); if (!symbol) return 0xFFFFFF; - if (symbol->type != Symbol::SYMBOL_FUNCTION) + if (symbol->type != Symbol::Type::Function) return 0xEEEEFF; return colors[symbol->index % 6]; } diff --git a/Source/Core/Core/HW/DSPLLE/DSPDebugInterface.cpp b/Source/Core/Core/HW/DSPLLE/DSPDebugInterface.cpp index 4165581a65..56330dc963 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPDebugInterface.cpp +++ b/Source/Core/Core/HW/DSPLLE/DSPDebugInterface.cpp @@ -170,7 +170,7 @@ int DSPDebugInterface::GetColor(unsigned int address) Symbol* symbol = DSPSymbols::g_dsp_symbol_db.GetSymbolFromAddr(addr); if (!symbol) return 0xFFFFFF; - if (symbol->type != Symbol::SYMBOL_FUNCTION) + if (symbol->type != Symbol::Type::Function) return 0xEEEEFF; return colors[symbol->index % 6]; } diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp index dca7a8f48f..d6a4e5d13c 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp @@ -47,13 +47,14 @@ Symbol* PPCSymbolDB::AddFunction(u32 startAddr) return nullptr; // found a dud :( // LOG(OSHLE, "Symbol found at %08x", startAddr); functions[startAddr] = tempFunc; - tempFunc.type = Symbol::SYMBOL_FUNCTION; + tempFunc.type = Symbol::Type::Function; checksumToFunction[tempFunc.hash] = &(functions[startAddr]); return &functions[startAddr]; } } -void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& name, int type) +void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& name, + Symbol::Type type) { XFuncMap::iterator iter = functions.find(startAddr); if (iter != functions.end()) @@ -72,7 +73,7 @@ void PPCSymbolDB::AddKnownSymbol(u32 startAddr, u32 size, const std::string& nam tf.name = name; tf.type = type; tf.address = startAddr; - if (tf.type == Symbol::SYMBOL_FUNCTION) + if (tf.type == Symbol::Type::Function) { PPCAnalyst::AnalyzeFunction(startAddr, tf, size); checksumToFunction[tf.hash] = &(functions[startAddr]); diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.h b/Source/Core/Core/PowerPC/PPCSymbolDB.h index 80104414f1..25d05678fe 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.h +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.h @@ -27,7 +27,7 @@ public: Symbol* AddFunction(u32 startAddr) override; void AddKnownSymbol(u32 startAddr, u32 size, const std::string& name, - int type = Symbol::SYMBOL_FUNCTION); + Symbol::Type type = Symbol::Type::Function); Symbol* GetSymbolFromAddr(u32 addr) override; diff --git a/Source/Core/DolphinWX/Debugger/CodeWindowFunctions.cpp b/Source/Core/DolphinWX/Debugger/CodeWindowFunctions.cpp index 8a46245f37..0a1300146b 100644 --- a/Source/Core/DolphinWX/Debugger/CodeWindowFunctions.cpp +++ b/Source/Core/DolphinWX/Debugger/CodeWindowFunctions.cpp @@ -485,7 +485,7 @@ void CCodeWindow::OnSymbolListChange(wxCommandEvent& event) Symbol* pSymbol = static_cast(symbols->GetClientData(index)); if (pSymbol != nullptr) { - if (pSymbol->type == Symbol::SYMBOL_DATA) + if (pSymbol->type == Symbol::Type::Data) { if (m_MemoryWindow) // && m_MemoryWindow->IsVisible()) m_MemoryWindow->JumpToAddress(pSymbol->address); diff --git a/Source/Core/DolphinWX/Debugger/DSPDebugWindow.cpp b/Source/Core/DolphinWX/Debugger/DSPDebugWindow.cpp index c3d2aef98c..d4e9907841 100644 --- a/Source/Core/DolphinWX/Debugger/DSPDebugWindow.cpp +++ b/Source/Core/DolphinWX/Debugger/DSPDebugWindow.cpp @@ -224,7 +224,7 @@ void DSPDebuggerLLE::OnSymbolListChange(wxCommandEvent& event) Symbol* pSymbol = static_cast(m_SymbolList->GetClientData(index)); if (pSymbol != nullptr) { - if (pSymbol->type == Symbol::SYMBOL_FUNCTION) + if (pSymbol->type == Symbol::Type::Function) { JumpToAddress(pSymbol->address); } From 00ddbee786f6a2a15c1e19e5ac4b393f6c6f9094 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 13 Sep 2016 21:16:04 -0400 Subject: [PATCH 3/3] SymbolDB: Change Symbol's 'analyzed' member into a boolean It's only ever used as one --- Source/Core/Common/SymbolDB.h | 2 +- Source/Core/Core/PowerPC/PPCAnalyst.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/Common/SymbolDB.h b/Source/Core/Common/SymbolDB.h index 1b75a58b5f..db4f735683 100644 --- a/Source/Core/Common/SymbolDB.h +++ b/Source/Core/Common/SymbolDB.h @@ -39,7 +39,7 @@ struct Symbol int numCalls = 0; Type type = Type::Function; int index = 0; // only used for coloring the disasm view - int analyzed = 0; + bool analyzed = false; }; enum diff --git a/Source/Core/Core/PowerPC/PPCAnalyst.cpp b/Source/Core/Core/PowerPC/PPCAnalyst.cpp index 43a5f041fe..69c95acd0b 100644 --- a/Source/Core/Core/PowerPC/PPCAnalyst.cpp +++ b/Source/Core/Core/PowerPC/PPCAnalyst.cpp @@ -75,7 +75,7 @@ bool AnalyzeFunction(u32 startAddr, Symbol& func, int max_size) { if (!func.name.size()) func.name = StringFromFormat("zz_%07x_", startAddr & 0x0FFFFFF); - if (func.analyzed >= 1) + if (func.analyzed) return true; // No error, just already did it. func.calls.clear(); @@ -96,7 +96,7 @@ bool AnalyzeFunction(u32 startAddr, Symbol& func, int max_size) if (max_size && func.size > max_size) { func.address = startAddr; - func.analyzed = 1; + func.analyzed = true; func.hash = SignatureDB::ComputeCodeChecksum(startAddr, addr); if (numInternalBranches == 0) func.flags |= FFLAG_STRAIGHT; @@ -117,7 +117,7 @@ bool AnalyzeFunction(u32 startAddr, Symbol& func, int max_size) // We're done! Looks like we have a neat valid function. Perfect. // Let's calc the checksum and get outta here func.address = startAddr; - func.analyzed = 1; + func.analyzed = true; func.hash = SignatureDB::ComputeCodeChecksum(startAddr, addr); if (numInternalBranches == 0) func.flags |= FFLAG_STRAIGHT;