From 7c585485bb30193877d0353ccad5a20f49b271af Mon Sep 17 00:00:00 2001 From: Kingcom Date: Tue, 26 Nov 2013 00:23:17 +0100 Subject: [PATCH 1/5] Save labels separately from symbols --- Core/Debugger/DebugInterface.h | 1 - Core/Debugger/DisassemblyManager.cpp | 6 +++--- Core/Debugger/SymbolMap.cpp | 28 +++++++++++++++++++++++++++- Core/Debugger/SymbolMap.h | 10 +++++++++- Core/MIPS/MIPSDebugInterface.cpp | 5 ----- Core/MIPS/MIPSDebugInterface.h | 1 - Windows/Debugger/CtrlDisAsmView.cpp | 10 +++++----- Windows/Debugger/Debugger_Lists.cpp | 4 ++-- 8 files changed, 46 insertions(+), 19 deletions(-) diff --git a/Core/Debugger/DebugInterface.h b/Core/Debugger/DebugInterface.h index 7a000d4df9..321f3f0a65 100644 --- a/Core/Debugger/DebugInterface.h +++ b/Core/Debugger/DebugInterface.h @@ -41,7 +41,6 @@ public: virtual void runToBreakpoint() {} virtual int getColor(unsigned int address){return 0xFFFFFFFF;} virtual const char *getDescription(unsigned int address) {return "";} - virtual const char *findSymbolForAddress(unsigned int address) { return NULL; }; virtual bool getSymbolValue(char* symbol, u32& dest) { return false; }; virtual bool initExpression(const char* exp, PostfixExpression& dest) { return false; }; virtual bool parseExpression(PostfixExpression& exp, u32& dest) { return false; }; diff --git a/Core/Debugger/DisassemblyManager.cpp b/Core/Debugger/DisassemblyManager.cpp index 16242c2f1f..4216e0f734 100644 --- a/Core/Debugger/DisassemblyManager.cpp +++ b/Core/Debugger/DisassemblyManager.cpp @@ -58,7 +58,7 @@ void parseDisasm(const char* disasm, char* opcode, char* arguments, bool insertS u32 branchTarget; sscanf(disasm+3,"%08x",&branchTarget); - const char* addressSymbol = DisassemblyManager::getCpu()->findSymbolForAddress(branchTarget); + const char* addressSymbol = symbolMap.GetLabelName(branchTarget); if (addressSymbol != NULL && insertSymbols) { arguments += sprintf(arguments,"%s",addressSymbol); @@ -615,7 +615,7 @@ bool DisassemblyMacro::disassemble(u32 address, DisassemblyLineInfo& dest, bool case MACRO_LI: dest.name = name; - addressSymbol = DisassemblyManager::getCpu()->findSymbolForAddress(immediate); + addressSymbol = symbolMap.GetLabelName(immediate); if (addressSymbol != NULL && insertSymbols) { sprintf(buffer,"%s,%s",DisassemblyManager::getCpu()->GetRegName(0,rt),addressSymbol); @@ -631,7 +631,7 @@ bool DisassemblyMacro::disassemble(u32 address, DisassemblyLineInfo& dest, bool case MACRO_MEMORYIMM: dest.name = name; - addressSymbol = DisassemblyManager::getCpu()->findSymbolForAddress(immediate); + addressSymbol = symbolMap.GetLabelName(immediate); if (addressSymbol != NULL && insertSymbols) { sprintf(buffer,"%s,%s",DisassemblyManager::getCpu()->GetRegName(0,rt),addressSymbol); diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index 1662e9af97..a0e7f2e7a4 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -120,6 +120,8 @@ void SymbolMap::AddSymbol(const char *symbolname, unsigned int vaddress, size_t uniqueEntries.insert((const MapEntryUniqueInfo)e); entryRanges[e.vaddress + e.size] = e.vaddress; } + + AddLabel(symbolname,vaddress); } void SymbolMap::RemoveSymbolNum(int symbolnum){ @@ -250,7 +252,13 @@ bool SymbolMap::LoadNocashSym(const char *filename) *seperator = 0; sscanf(seperator+1,"%08X",&size); } - AddSymbol(value,address,size,ST_FUNCTION); + + if (size != 1) + { + AddSymbol(value,address,size,ST_FUNCTION); + } else { + AddLabel(value,address); + } } } @@ -367,6 +375,24 @@ bool SymbolMap::getSymbolValue(char* symbol, u32& dest) return false; } +void SymbolMap::AddLabel(const char* name, u32 address) +{ + Label label; + strcpy(label.name,name); + label.name[127] = 0; + + labels[address] = label; +} + +const char* SymbolMap::GetLabelName(u32 address) +{ + auto it = labels.find(address); + if (it == labels.end()) + return NULL; + + return it->second.name; +} + static char descriptionTemp[256]; const char *SymbolMap::GetDescription(unsigned int address) const diff --git a/Core/Debugger/SymbolMap.h b/Core/Debugger/SymbolMap.h index 5486e6f1e8..ad39b9e7da 100644 --- a/Core/Debugger/SymbolMap.h +++ b/Core/Debugger/SymbolMap.h @@ -75,6 +75,8 @@ public: void UseFuncSignaturesFile(const char *filename, u32 maxAddress); void CompileFuncSignaturesFile(const char *filename) const; + void AddLabel(const char* name, u32 address); + const char* GetLabelName(u32 address); private: struct MapEntryUniqueInfo { u32 address; @@ -87,6 +89,11 @@ private: } }; + struct Label + { + char name[128]; + }; + struct MapEntry : public MapEntryUniqueInfo { char name[128]; u32 unknown; @@ -99,7 +106,8 @@ private: // TODO } }; - + + std::map labels; std::set uniqueEntries; std::vector entries; std::map entryRanges; diff --git a/Core/MIPS/MIPSDebugInterface.cpp b/Core/MIPS/MIPSDebugInterface.cpp index 156d18bdd4..af3e351588 100644 --- a/Core/MIPS/MIPSDebugInterface.cpp +++ b/Core/MIPS/MIPSDebugInterface.cpp @@ -230,11 +230,6 @@ const char *MIPSDebugInterface::getDescription(unsigned int address) return symbolMap.GetDescription(address); } -const char *MIPSDebugInterface::findSymbolForAddress(unsigned int address) -{ - return symbolMap.getDirectSymbol(address); -} - bool MIPSDebugInterface::getSymbolValue(char* symbol, u32& dest) { return symbolMap.getSymbolValue(symbol,dest); diff --git a/Core/MIPS/MIPSDebugInterface.h b/Core/MIPS/MIPSDebugInterface.h index 39b6bc5eba..f01aa49640 100644 --- a/Core/MIPS/MIPSDebugInterface.h +++ b/Core/MIPS/MIPSDebugInterface.h @@ -40,7 +40,6 @@ public: virtual void runToBreakpoint(); virtual int getColor(unsigned int address); virtual const char *getDescription(unsigned int address); - virtual const char *findSymbolForAddress(unsigned int address); virtual bool getSymbolValue(char* symbol, u32& dest); virtual bool initExpression(const char* exp, PostfixExpression& dest); virtual bool parseExpression(PostfixExpression& exp, u32& dest); diff --git a/Windows/Debugger/CtrlDisAsmView.cpp b/Windows/Debugger/CtrlDisAsmView.cpp index c8e1ae05f3..8d9aee7fff 100644 --- a/Windows/Debugger/CtrlDisAsmView.cpp +++ b/Windows/Debugger/CtrlDisAsmView.cpp @@ -206,7 +206,7 @@ bool CtrlDisAsmView::getDisasmAddressText(u32 address, char* dest, bool abbrevia { if (displaySymbols) { - const char* addressSymbol = debugger->findSymbolForAddress(address); + const char* addressSymbol = symbolMap.GetLabelName(address); if (addressSymbol != NULL) { for (int k = 0; addressSymbol[k] != 0; k++) @@ -1023,7 +1023,7 @@ void CtrlDisAsmView::updateStatusBarText() // TODO: Could also be a float... { u32 data = Memory::Read_U32(line.info.dataAddress); - const char* addressSymbol = debugger->findSymbolForAddress(data); + const char* addressSymbol = symbolMap.GetLabelName(data); if (addressSymbol) { sprintf(text,"[%08X] = %s (%08X)",line.info.dataAddress,addressSymbol,data); @@ -1041,7 +1041,7 @@ void CtrlDisAsmView::updateStatusBarText() if (line.info.isBranch) { - const char* addressSymbol = debugger->findSymbolForAddress(line.info.branchTarget); + const char* addressSymbol = symbolMap.GetLabelName(line.info.branchTarget); if (addressSymbol == NULL) { sprintf(text,"%08X",line.info.branchTarget); @@ -1157,7 +1157,7 @@ std::string CtrlDisAsmView::disassembleRange(u32 start, u32 size) { MIPSAnalyst::MipsOpcodeInfo info = MIPSAnalyst::GetOpcodeInfo(debugger,start+i); - if (info.isBranch && debugger->findSymbolForAddress(info.branchTarget) == NULL) + if (info.isBranch && symbolMap.GetLabelName(info.branchTarget) == NULL) { if (branchAddresses.find(info.branchTarget) == branchAddresses.end()) { @@ -1189,7 +1189,7 @@ std::string CtrlDisAsmView::disassembleRange(u32 start, u32 size) } if (line.info.isBranch && !line.info.isBranchToRegister - && debugger->findSymbolForAddress(line.info.branchTarget) == NULL + && symbolMap.GetLabelName(line.info.branchTarget) == NULL && branchAddresses.find(line.info.branchTarget) != branchAddresses.end()) { sprintf(buffer,"pos_%08X",line.info.branchTarget); diff --git a/Windows/Debugger/Debugger_Lists.cpp b/Windows/Debugger/Debugger_Lists.cpp index 67e436e0fb..5e7a4a8826 100644 --- a/Windows/Debugger/Debugger_Lists.cpp +++ b/Windows/Debugger/Debugger_Lists.cpp @@ -457,7 +457,7 @@ void CtrlBreakpointList::GetColumnText(wchar_t* dest, int row, int col) else wsprintf(dest,L"0x%08X",mc.end-mc.start); } else { - const char* sym = cpu->findSymbolForAddress(displayedBreakPoints_[index].addr); + const char* sym = symbolMap.GetLabelName(displayedBreakPoints_[index].addr); if (sym != NULL) { std::wstring s = ConvertUTF8ToWString(sym); @@ -625,7 +625,7 @@ void CtrlStackTraceView::GetColumnText(wchar_t* dest, int row, int col) break; case SF_ENTRYNAME: { - const char* sym = cpu->findSymbolForAddress(frames[row].entry); + const char* sym = symbolMap.GetLabelName(frames[row].entry); if (sym != NULL) { wcscpy(dest, ConvertUTF8ToWString(sym).c_str()); } else { From 00a801f6a3913ac5435beb597f6b9b4175cdd182 Mon Sep 17 00:00:00 2001 From: Kingcom Date: Tue, 26 Nov 2013 00:43:31 +0100 Subject: [PATCH 2/5] Don't overwrite label name if it already exists, get label value --- Core/Debugger/SymbolMap.cpp | 26 ++++++++++++++++++++++++-- Core/Debugger/SymbolMap.h | 3 ++- Core/MIPS/MIPSDebugInterface.cpp | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index a0e7f2e7a4..f14e7c1bec 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -108,6 +108,8 @@ void SymbolMap::Clear() { void SymbolMap::AddSymbol(const char *symbolname, unsigned int vaddress, size_t size, SymbolType st) { lock_guard guard(lock_); + symbolname = AddLabel(symbolname,vaddress); + MapEntry e; strncpy(e.name, symbolname, 127); e.name[127] = '\0'; @@ -121,7 +123,6 @@ void SymbolMap::AddSymbol(const char *symbolname, unsigned int vaddress, size_t entryRanges[e.vaddress + e.size] = e.vaddress; } - AddLabel(symbolname,vaddress); } void SymbolMap::RemoveSymbolNum(int symbolnum){ @@ -375,13 +376,19 @@ bool SymbolMap::getSymbolValue(char* symbol, u32& dest) return false; } -void SymbolMap::AddLabel(const char* name, u32 address) +const char* SymbolMap::AddLabel(const char* name, u32 address) { + // keep a label if it already exists + auto it = labels.find(address); + if (it != labels.end()) + return it->second.name; + Label label; strcpy(label.name,name); label.name[127] = 0; labels[address] = label; + return name; } const char* SymbolMap::GetLabelName(u32 address) @@ -393,6 +400,21 @@ const char* SymbolMap::GetLabelName(u32 address) return it->second.name; } +bool SymbolMap::GetLabelValue(const char* name, u32& dest) +{ + for (auto it = labels.begin(); it != labels.end(); it++) + { + if (strcasecmp(name,it->second.name) == 0) + { + dest = it->first; + return true; + } + } + + return false; +} + + static char descriptionTemp[256]; const char *SymbolMap::GetDescription(unsigned int address) const diff --git a/Core/Debugger/SymbolMap.h b/Core/Debugger/SymbolMap.h index ad39b9e7da..61157d5fe8 100644 --- a/Core/Debugger/SymbolMap.h +++ b/Core/Debugger/SymbolMap.h @@ -75,8 +75,9 @@ public: void UseFuncSignaturesFile(const char *filename, u32 maxAddress); void CompileFuncSignaturesFile(const char *filename) const; - void AddLabel(const char* name, u32 address); + const char* AddLabel(const char* name, u32 address); const char* GetLabelName(u32 address); + bool GetLabelValue(const char* name, u32& dest); private: struct MapEntryUniqueInfo { u32 address; diff --git a/Core/MIPS/MIPSDebugInterface.cpp b/Core/MIPS/MIPSDebugInterface.cpp index af3e351588..b096d0d716 100644 --- a/Core/MIPS/MIPSDebugInterface.cpp +++ b/Core/MIPS/MIPSDebugInterface.cpp @@ -109,7 +109,7 @@ public: virtual bool parseSymbol(char* str, uint32& symbolValue) { - return cpu->getSymbolValue(str,symbolValue); + return symbolMap.GetLabelValue(str,symbolValue); } virtual uint32 getReferenceValue(uint32 referenceIndex) From 3d4bb3f20b4166cc21268788e0fa1ef1d98e2f6b Mon Sep 17 00:00:00 2001 From: Kingcom Date: Tue, 26 Nov 2013 00:51:04 +0100 Subject: [PATCH 3/5] Remove obsolete functions --- Core/Debugger/DebugInterface.h | 1 - Core/Debugger/DisassemblyManager.cpp | 2 +- Core/Debugger/SymbolMap.cpp | 38 ---------------------------- Core/Debugger/SymbolMap.h | 2 -- Core/MIPS/MIPSDebugInterface.cpp | 5 ---- Core/MIPS/MIPSDebugInterface.h | 1 - 6 files changed, 1 insertion(+), 48 deletions(-) diff --git a/Core/Debugger/DebugInterface.h b/Core/Debugger/DebugInterface.h index 321f3f0a65..12605c86b5 100644 --- a/Core/Debugger/DebugInterface.h +++ b/Core/Debugger/DebugInterface.h @@ -41,7 +41,6 @@ public: virtual void runToBreakpoint() {} virtual int getColor(unsigned int address){return 0xFFFFFFFF;} virtual const char *getDescription(unsigned int address) {return "";} - virtual bool getSymbolValue(char* symbol, u32& dest) { return false; }; virtual bool initExpression(const char* exp, PostfixExpression& dest) { return false; }; virtual bool parseExpression(PostfixExpression& exp, u32& dest) { return false; }; diff --git a/Core/Debugger/DisassemblyManager.cpp b/Core/Debugger/DisassemblyManager.cpp index 4216e0f734..f8a9818157 100644 --- a/Core/Debugger/DisassemblyManager.cpp +++ b/Core/Debugger/DisassemblyManager.cpp @@ -305,7 +305,7 @@ void DisassemblyFunction::recheck() int DisassemblyFunction::getNumLines() { - return lineAddresses.size(); + return (int) lineAddresses.size(); } int DisassemblyFunction::getLineNum(u32 address, bool findStart) diff --git a/Core/Debugger/SymbolMap.cpp b/Core/Debugger/SymbolMap.cpp index f14e7c1bec..d80ce61310 100644 --- a/Core/Debugger/SymbolMap.cpp +++ b/Core/Debugger/SymbolMap.cpp @@ -338,44 +338,6 @@ u32 SymbolMap::GetNextSymbolAddress(u32 address) return containingEntry->second; } -const char* SymbolMap::getDirectSymbol(u32 address) -{ - lock_guard guard(lock_); - SymbolInfo info; - if (GetSymbolInfo(&info,address) == false) return NULL; - if (info.address != address) return NULL; // has to be the START of the function - - // now we need the name... which we can't just get from GetSymbolInfo because of the - // unique entries. But, there are so many less instances where there actually IS a - // label that the speed up is still massive - for (auto it = entries.begin(), end = entries.end(); it != end; ++it) - { - const MapEntry &entry = *it; - unsigned int addr = entry.vaddress; - if (addr == address) return entry.name; - } - return NULL; -} - -bool SymbolMap::getSymbolValue(char* symbol, u32& dest) -{ - lock_guard guard(lock_); - for (auto it = entries.begin(), end = entries.end(); it != end; ++it) - { - const MapEntry &entry = *it; -#ifdef _WIN32 - if (_stricmp(entry.name,symbol) == 0) -#else - if (strcasecmp(entry.name,symbol) == 0) -#endif - { - dest = entry.vaddress; - return true; - } - } - return false; -} - const char* SymbolMap::AddLabel(const char* name, u32 address) { // keep a label if it already exists diff --git a/Core/Debugger/SymbolMap.h b/Core/Debugger/SymbolMap.h index 61157d5fe8..6260932576 100644 --- a/Core/Debugger/SymbolMap.h +++ b/Core/Debugger/SymbolMap.h @@ -69,8 +69,6 @@ public: void IncreaseRunCount(int num); unsigned int GetRunCount(int num) const; void SortSymbols(); - const char* getDirectSymbol(u32 address); - bool getSymbolValue(char* symbol, u32& dest); void UseFuncSignaturesFile(const char *filename, u32 maxAddress); void CompileFuncSignaturesFile(const char *filename) const; diff --git a/Core/MIPS/MIPSDebugInterface.cpp b/Core/MIPS/MIPSDebugInterface.cpp index b096d0d716..4e8f5a7fda 100644 --- a/Core/MIPS/MIPSDebugInterface.cpp +++ b/Core/MIPS/MIPSDebugInterface.cpp @@ -230,11 +230,6 @@ const char *MIPSDebugInterface::getDescription(unsigned int address) return symbolMap.GetDescription(address); } -bool MIPSDebugInterface::getSymbolValue(char* symbol, u32& dest) -{ - return symbolMap.getSymbolValue(symbol,dest); -} - bool MIPSDebugInterface::initExpression(const char* exp, PostfixExpression& dest) { MipsExpressionFunctions funcs(this); diff --git a/Core/MIPS/MIPSDebugInterface.h b/Core/MIPS/MIPSDebugInterface.h index f01aa49640..895454ef43 100644 --- a/Core/MIPS/MIPSDebugInterface.h +++ b/Core/MIPS/MIPSDebugInterface.h @@ -40,7 +40,6 @@ public: virtual void runToBreakpoint(); virtual int getColor(unsigned int address); virtual const char *getDescription(unsigned int address); - virtual bool getSymbolValue(char* symbol, u32& dest); virtual bool initExpression(const char* exp, PostfixExpression& dest); virtual bool parseExpression(PostfixExpression& exp, u32& dest); From 274632f3040e77535b86c26c0df31ff0fa7fb75a Mon Sep 17 00:00:00 2001 From: Kingcom Date: Tue, 26 Nov 2013 11:38:01 +0100 Subject: [PATCH 4/5] Minor disassembly tweaks --- Core/Debugger/DisassemblyManager.cpp | 2 +- Windows/Debugger/CtrlDisAsmView.cpp | 11 +++++------ Windows/Debugger/CtrlDisAsmView.h | 11 ++++------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Core/Debugger/DisassemblyManager.cpp b/Core/Debugger/DisassemblyManager.cpp index f8a9818157..66586d6117 100644 --- a/Core/Debugger/DisassemblyManager.cpp +++ b/Core/Debugger/DisassemblyManager.cpp @@ -30,7 +30,7 @@ DebugInterface* DisassemblyManager::cpu; bool isInInterval(u32 start, u32 size, u32 value) { - return start <= value && value < start+size; + return start <= value && value <= (start+size-1); } void parseDisasm(const char* disasm, char* opcode, char* arguments, bool insertSymbols) diff --git a/Windows/Debugger/CtrlDisAsmView.cpp b/Windows/Debugger/CtrlDisAsmView.cpp index 8d9aee7fff..0f8d10d80d 100644 --- a/Windows/Debugger/CtrlDisAsmView.cpp +++ b/Windows/Debugger/CtrlDisAsmView.cpp @@ -167,7 +167,6 @@ CtrlDisAsmView::CtrlDisAsmView(HWND _wnd) boldfont = CreateFont(rowHeight-2,charWidth,0,0,FW_DEMIBOLD,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH, L"Lucida Console"); curAddress=0; - instructionSize=4; showHex=false; hasFocus = false; dontRedraw = false; @@ -655,11 +654,11 @@ void CtrlDisAsmView::onKeyDown(WPARAM wParam, LPARAM lParam) toggleBreakpoint(true); break; case VK_UP: - windowStart -= instructionSize; + scrollWindow(-1); scanFunctions(); break; case VK_DOWN: - windowStart += instructionSize; + scrollWindow(1); scanFunctions(); break; case VK_NEXT: @@ -819,10 +818,10 @@ void CtrlDisAsmView::onMouseDown(WPARAM wParam, LPARAM lParam, int button) void CtrlDisAsmView::copyInstructions(u32 startAddr, u32 endAddr, bool withDisasm) { - int count = (endAddr - startAddr) / instructionSize; - if (withDisasm == false) { + int instructionSize = debugger->getInstructionSize(0); + int count = (endAddr - startAddr) / instructionSize; int space = count * 32; char *temp = new char[space]; @@ -1153,7 +1152,7 @@ std::string CtrlDisAsmView::disassembleRange(u32 start, u32 size) // gather all branch targets without labels std::set branchAddresses; - for (u32 i = 0; i < size; i += instructionSize) + for (u32 i = 0; i < size; i += debugger->getInstructionSize(0)) { MIPSAnalyst::MipsOpcodeInfo info = MIPSAnalyst::GetOpcodeInfo(debugger,start+i); diff --git a/Windows/Debugger/CtrlDisAsmView.h b/Windows/Debugger/CtrlDisAsmView.h index 95e6b82c6c..ff4ebd2fa3 100644 --- a/Windows/Debugger/CtrlDisAsmView.h +++ b/Windows/Debugger/CtrlDisAsmView.h @@ -50,7 +50,6 @@ class CtrlDisAsmView u32 windowStart; int visibleRows; - int instructionSize; bool whiteBackground; bool displaySymbols; @@ -110,7 +109,6 @@ public: { debugger=deb; curAddress=debugger->getPC(); - instructionSize=debugger->getInstructionSize(0); manager.setCpu(deb); } DebugInterface *getDebugger() @@ -123,13 +121,12 @@ public: void gotoAddr(unsigned int addr) { - addr = manager.getStartAddress(addr); - u32 windowEnd = windowStart+visibleRows*instructionSize; - u32 newAddress = addr&(~(instructionSize-1)); + u32 windowEnd = manager.getNthNextAddress(windowStart,visibleRows); + u32 newAddress = manager.getStartAddress(addr); if (newAddress < windowStart || newAddress >= windowEnd) { - windowStart = newAddress-visibleRows/2*instructionSize; + windowStart = manager.getNthPreviousAddress(newAddress,visibleRows/2); } setCurAddress(newAddress); @@ -138,7 +135,7 @@ public: } void gotoPC() { - gotoAddr(debugger->getPC()&(~(instructionSize-1))); + gotoAddr(debugger->getPC()); } u32 getSelection() { From 33da416a820fe617b9c15a32faff537d4356d80a Mon Sep 17 00:00:00 2001 From: Kingcom Date: Tue, 26 Nov 2013 22:20:12 +0100 Subject: [PATCH 5/5] Reduce disassembler memory usage --- Core/Debugger/DisassemblyManager.cpp | 26 ++++++++++++++++++-------- Core/Debugger/DisassemblyManager.h | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Core/Debugger/DisassemblyManager.cpp b/Core/Debugger/DisassemblyManager.cpp index 66586d6117..a293db71c0 100644 --- a/Core/Debugger/DisassemblyManager.cpp +++ b/Core/Debugger/DisassemblyManager.cpp @@ -416,6 +416,15 @@ void DisassemblyFunction::generateBranchLines() } } +void DisassemblyFunction::addOpcodeSequence(u32 start, u32 end) +{ + DisassemblyOpcode* opcode = new DisassemblyOpcode(start,(end-start)/4); + entries[start] = opcode; + for (u32 pos = start; pos < end; pos += 4) + { + lineAddresses.push_back(pos); + } +} void DisassemblyFunction::load() { @@ -440,6 +449,7 @@ void DisassemblyFunction::load() u32 funcPos = address; u32 funcEnd = address+size; + u32 opcodeSequenceStart = funcPos; while (funcPos < funcEnd) { MIPSAnalyst::MipsOpcodeInfo opInfo = MIPSAnalyst::GetOpcodeInfo(cpu,funcPos); @@ -449,11 +459,6 @@ void DisassemblyFunction::load() // skip branches and their delay slots if (opInfo.isBranch) { - DisassemblyOpcode* opcode = new DisassemblyOpcode(opAddress,2); - entries[opAddress] = opcode; - lineAddresses.push_back(opAddress); - lineAddresses.push_back(opAddress+4); - funcPos += 4; continue; } @@ -517,21 +522,26 @@ void DisassemblyFunction::load() if (macro != NULL) { + if (opcodeSequenceStart != opAddress) + addOpcodeSequence(opcodeSequenceStart,opAddress); + entries[opAddress] = macro; for (int i = 0; i < macro->getNumLines(); i++) { lineAddresses.push_back(macro->getLineAddress(i)); } + + opcodeSequenceStart = funcPos; continue; } } } // just a normal opcode - DisassemblyOpcode* opcode = new DisassemblyOpcode(opAddress,1); - entries[opAddress] = opcode; - lineAddresses.push_back(opAddress); } + + if (opcodeSequenceStart != funcPos) + addOpcodeSequence(opcodeSequenceStart,funcPos); } void DisassemblyFunction::clear() diff --git a/Core/Debugger/DisassemblyManager.h b/Core/Debugger/DisassemblyManager.h index 94b5f97efc..52126ccb19 100644 --- a/Core/Debugger/DisassemblyManager.h +++ b/Core/Debugger/DisassemblyManager.h @@ -74,6 +74,7 @@ private: void generateBranchLines(); void load(); void clear(); + void addOpcodeSequence(u32 start, u32 end); u32 address; u32 size;