From 9a29e8b0bff6c5e512c7ea281d6f588b2db18def Mon Sep 17 00:00:00 2001 From: Kingcom Date: Mon, 25 Nov 2013 16:18:29 +0100 Subject: [PATCH] More efficient "loose" opcode detection, clear entries when symbols were loaded --- Core/Debugger/DisassemblyManager.cpp | 20 ++++++++++++++------ Core/Debugger/DisassemblyManager.h | 1 + Core/Debugger/SymbolMap.cpp | 11 +++++++++++ Core/Debugger/SymbolMap.h | 1 + Windows/Debugger/CtrlDisAsmView.h | 2 +- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Core/Debugger/DisassemblyManager.cpp b/Core/Debugger/DisassemblyManager.cpp index f2dead5606..d4ced467ed 100644 --- a/Core/Debugger/DisassemblyManager.cpp +++ b/Core/Debugger/DisassemblyManager.cpp @@ -115,14 +115,13 @@ void DisassemblyManager::analyze(u32 address, u32 size = 1024) entries[info.address] = function; address = info.address+info.size; } else { - u32 startAddress = address; - address += 4; - while (!symbolMap.GetSymbolInfo(&info,address) && address < end) - address += 4; + u32 next = symbolMap.GetNextSymbolAddress(address); // let's just assume anything otuside a function is a normal opcode - DisassemblyOpcode* opcode = new DisassemblyOpcode(startAddress,(address-startAddress)/4); - entries[startAddress] = opcode; + DisassemblyOpcode* opcode = new DisassemblyOpcode(address,(next-address)/4); + entries[address] = opcode; + + address = next; } } @@ -280,6 +279,15 @@ u32 DisassemblyManager::getNthNextAddress(u32 address, int n) return address+n*4; } +void DisassemblyManager::clear() +{ + for (auto it = entries.begin(); it != entries.end(); it++) + { + delete it->second; + } + entries.clear(); +} + DisassemblyFunction::DisassemblyFunction(u32 _address, u32 _size): address(_address), size(_size) { hash = computeHash(); diff --git a/Core/Debugger/DisassemblyManager.h b/Core/Debugger/DisassemblyManager.h index 849b2f0a81..8eeefa5712 100644 --- a/Core/Debugger/DisassemblyManager.h +++ b/Core/Debugger/DisassemblyManager.h @@ -133,6 +133,7 @@ class DebugInterface; class DisassemblyManager { public: + void clear(); void setCpu(DebugInterface* _cpu) { cpu = _cpu; }; void getLine(u32 address, bool insertSymbols, DisassemblyLineInfo& dest); diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index 3c3c7940f7..1662e9af97 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -318,6 +318,17 @@ bool SymbolMap::GetSymbolInfo(SymbolInfo *info, u32 address, SymbolType symmask) return false; } +u32 SymbolMap::GetNextSymbolAddress(u32 address) +{ + lock_guard guard(lock_); + + const auto containingEntry = entryRanges.upper_bound(address); + if (containingEntry == entryRanges.end()) + return -1; + + return containingEntry->second; +} + const char* SymbolMap::getDirectSymbol(u32 address) { lock_guard guard(lock_); diff --git a/Core/Debugger/SymbolMap.h b/Core/Debugger/SymbolMap.h index 97263a9112..5486e6f1e8 100644 --- a/Core/Debugger/SymbolMap.h +++ b/Core/Debugger/SymbolMap.h @@ -50,6 +50,7 @@ public: void AnalyzeBackwards(); int GetSymbolNum(unsigned int address, SymbolType symmask=ST_FUNCTION) const; bool GetSymbolInfo(SymbolInfo *info, u32 address, SymbolType symmask = ST_FUNCTION) const; + u32 GetNextSymbolAddress(u32 address); const char *GetDescription(unsigned int address) const; #ifdef _WIN32 void FillSymbolListBox(HWND listbox, SymbolType symmask=ST_FUNCTION) const; diff --git a/Windows/Debugger/CtrlDisAsmView.h b/Windows/Debugger/CtrlDisAsmView.h index a486841bea..7bc5f70208 100644 --- a/Windows/Debugger/CtrlDisAsmView.h +++ b/Windows/Debugger/CtrlDisAsmView.h @@ -99,7 +99,7 @@ public: bool curAddressIsVisible(); void redraw(); void scanFunctions(); - void clearFunctions() { }; + void clearFunctions() { manager.clear(); }; void getOpcodeText(u32 address, char* dest); int getRowHeight() { return rowHeight; };