diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj
index 5872e15d63..f2bc31111c 100644
--- a/Core/Core.vcxproj
+++ b/Core/Core.vcxproj
@@ -171,6 +171,7 @@
+
@@ -423,6 +424,7 @@
+
diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters
index 60b06084b5..c1aa390215 100644
--- a/Core/Core.vcxproj.filters
+++ b/Core/Core.vcxproj.filters
@@ -496,6 +496,9 @@
Dialog
+
+ Debugger
+
@@ -918,7 +921,9 @@
MIPS\ARM
-
+
+ Debugger
+
diff --git a/Core/Debugger/DisassemblyManager.cpp b/Core/Debugger/DisassemblyManager.cpp
new file mode 100644
index 0000000000..dc7a12cb30
--- /dev/null
+++ b/Core/Debugger/DisassemblyManager.cpp
@@ -0,0 +1,522 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#include "DisassemblyManager.h"
+#include "DebugInterface.h"
+#include "Core/Debugger/SymbolMap.h"
+#include "Core/MIPS/MIPSCodeUtils.h"
+#include "Core/MIPS/MIPSTables.h"
+#include "Common/Common.h"
+#include "ext/xxhash.h"
+
+#include
+
+std::map DisassemblyManager::entries;
+DebugInterface* DisassemblyManager::cpu;
+
+
+void parseDisasm(const char* disasm, char* opcode, char* arguments, bool insertSymbols)
+{
+ // copy opcode
+ while (*disasm != 0 && *disasm != '\t')
+ {
+ *opcode++ = *disasm++;
+ }
+ *opcode = 0;
+
+ if (*disasm++ == 0)
+ {
+ *arguments = 0;
+ return;
+ }
+
+ const char* jumpAddress = strstr(disasm,"->$");
+ const char* jumpRegister = strstr(disasm,"->");
+ while (*disasm != 0)
+ {
+ // parse symbol
+ if (disasm == jumpAddress)
+ {
+ u32 branchTarget;
+ sscanf(disasm+3,"%08x",&branchTarget);
+
+ const char* addressSymbol = DisassemblyManager::getCpu()->findSymbolForAddress(branchTarget);
+ if (addressSymbol != NULL && insertSymbols)
+ {
+ arguments += sprintf(arguments,"%s",addressSymbol);
+ } else {
+ arguments += sprintf(arguments,"0x%08X",branchTarget);
+ }
+
+ disasm += 3+8;
+ continue;
+ }
+
+ if (disasm == jumpRegister)
+ disasm += 2;
+
+ if (*disasm == ' ')
+ {
+ disasm++;
+ continue;
+ }
+ *arguments++ = *disasm++;
+ }
+
+ *arguments = 0;
+}
+
+void DisassemblyManager::analyze(u32 address, u32 size)
+{
+ u32 end = address+size;
+ u32 start = address;
+
+ while (address < end && start <= address)
+ {
+ auto it = entries.lower_bound(address);
+ if (it != entries.end())
+ {
+ DisassemblyEntry* entry = it->second;
+ u32 entryStart = entry->getLineAddress(0);
+ u32 entryEnd = entryStart+entry->getTotalSize();
+
+ if (entryStart <= address && entryEnd > address)
+ {
+ entry->recheck();
+ address = entryEnd;
+ continue;
+ }
+ }
+
+ SymbolInfo info;
+ if (symbolMap.GetSymbolInfo(&info,address))
+ {
+ DisassemblyFunction* function = new DisassemblyFunction(info.address,info.size);
+ entries[info.address] = function;
+ address = info.address+info.size;
+ } else {
+ // let's just assume anything otuside a function is a normal opcode
+ DisassemblyOpcode* opcode = new DisassemblyOpcode(address);
+ entries[address] = opcode;
+ address += 4;
+ }
+ }
+
+}
+
+// TODO: use a faster search (and probably a different data structure)
+std::map::iterator findDisassemblyEntry(std::map& entries, u32 address, bool exact)
+{
+ if (exact)
+ return entries.find(address);
+
+ for (auto it = entries.begin(); it != entries.end(); it++)
+ {
+ DisassemblyEntry* entry = it->second;
+ u32 entryStart = entry->getLineAddress(0);
+ u32 entryEnd = entryStart+entry->getTotalSize();
+
+ if (entryStart <= address && entryEnd > address)
+ {
+ return it;
+ }
+ }
+
+ return entries.end();
+}
+
+DisassemblyLineInfo DisassemblyManager::getLine(u32 address, bool insertSymbols)
+{
+ DisassemblyLineInfo result;
+
+ auto it = findDisassemblyEntry(entries,address,false);
+ if (it == entries.end())
+ {
+ analyze(address,1);
+ it = findDisassemblyEntry(entries,address,false);
+
+ if (it == entries.end())
+ {
+ result.totalSize = 4;
+ result.name = "ERROR";
+ result.params = "Disassembly failure";
+ return result;
+ }
+ }
+
+ DisassemblyEntry* entry = it->second;
+
+ result.info = MIPSAnalyst::GetOpcodeInfo(cpu,address);
+ if (entry->disassemble(address,result))
+ return result;
+
+ result.totalSize = 4;
+ result.name = "ERROR";
+ result.params = "Disassembly failure";
+ return result;
+}
+
+
+u32 DisassemblyManager::getNthPreviousAddress(u32 address, int n)
+{
+ while (Memory::IsValidAddress(address))
+ {
+ auto it = findDisassemblyEntry(entries,address,false);
+
+ while (it != entries.end())
+ {
+ DisassemblyEntry* entry = it->second;
+ int oldLineNum = entry->getLineNum(address,true);
+ int oldNumLines = entry->getNumLines();
+ if (n <= oldLineNum)
+ {
+ return entry->getLineAddress(oldLineNum-n);
+ }
+
+ address = entry->getLineAddress(0)-1;
+ n -= oldLineNum+1;
+ it = findDisassemblyEntry(entries,address,false);
+ }
+
+ analyze(address,1);
+ }
+
+ return address-n*4;
+}
+
+u32 DisassemblyManager::getNthNextAddress(u32 address, int n)
+{
+ while (Memory::IsValidAddress(address))
+ {
+ auto it = findDisassemblyEntry(entries,address,false);
+
+ while (it != entries.end())
+ {
+ DisassemblyEntry* entry = it->second;
+ int oldLineNum = entry->getLineNum(address,true);
+ int oldNumLines = entry->getNumLines();
+ if (oldLineNum+n < oldNumLines)
+ {
+ return entry->getLineAddress(oldLineNum+n);
+ }
+
+ address = entry->getLineAddress(0)+entry->getTotalSize();
+ n -= (oldNumLines-oldLineNum);
+ it = findDisassemblyEntry(entries,address,false);
+ }
+
+ analyze(address,1);
+ }
+
+ return address+n*4;
+}
+
+DisassemblyFunction::DisassemblyFunction(u32 _address, u32 _size): address(_address), size(_size)
+{
+ hash = computeHash();
+ load();
+}
+
+u32 DisassemblyFunction::computeHash()
+{
+ return XXH32(Memory::GetPointer(address),size,0xBACD7814);
+}
+
+void DisassemblyFunction::recheck()
+{
+ u32 newHash = computeHash();
+ if (hash != newHash)
+ {
+ hash = newHash;
+ clear();
+ load();
+ }
+}
+
+int DisassemblyFunction::getNumLines()
+{
+ int lines = 0;
+ for (auto it = entries.begin(); it != entries.end(); it++)
+ {
+ lines += it->second->getNumLines();
+ }
+
+ return lines;
+}
+
+int DisassemblyFunction::getLineNum(u32 address, bool findStart)
+{
+ for (int i = 0; i < lineAddresses.size(); i++)
+ {
+ if (lineAddresses[i] == address)
+ return i;
+ if (findStart && lineAddresses[i] <= address && lineAddresses[i]+4 > address)
+ return i;
+ }
+
+ return 0;
+}
+
+u32 DisassemblyFunction::getLineAddress(int line)
+{
+ return lineAddresses[line];
+}
+
+bool DisassemblyFunction::disassemble(u32 address, DisassemblyLineInfo& dest)
+{
+ auto it = findDisassemblyEntry(entries,address,true);
+ if (it == entries.end())
+ return false;
+
+ return it->second->disassemble(address,dest);
+}
+
+
+#define NUM_LANES 16
+
+void DisassemblyFunction::generateBranchLines()
+{
+ struct LaneInfo
+ {
+ bool used;
+ u32 end;
+ };
+
+ LaneInfo lanes[NUM_LANES];
+ for (int i = 0; i < NUM_LANES; i++)
+ lanes[i].used = false;
+
+ u32 end = address+size;
+
+ DebugInterface* cpu = DisassemblyManager::getCpu();
+ for (u32 funcPos = address; funcPos < end; funcPos += 4)
+ {
+ MIPSAnalyst::MipsOpcodeInfo opInfo = MIPSAnalyst::GetOpcodeInfo(cpu,funcPos);
+
+ bool inFunction = (opInfo.branchTarget >= address && opInfo.branchTarget < end);
+ if (opInfo.isBranch && !opInfo.isBranchToRegister && !opInfo.isLinkedBranch && inFunction)
+ {
+ BranchLine line;
+ if (opInfo.branchTarget < funcPos)
+ {
+ line.first = opInfo.branchTarget;
+ line.second = funcPos;
+ line.type = LINE_UP;
+ } else {
+ line.first = funcPos;
+ line.second = opInfo.branchTarget;
+ line.type = LINE_DOWN;
+ }
+
+ lines.push_back(line);
+ }
+ }
+
+ std::sort(lines.begin(),lines.end());
+ for (size_t i = 0; i < lines.size(); i++)
+ {
+ for (int l = 0; l < NUM_LANES; l++)
+ {
+ if (lines[i].first > lanes[l].end)
+ lanes[l].used = false;
+ }
+
+ int lane = -1;
+ for (int l = 0; l < NUM_LANES; l++)
+ {
+ if (lanes[l].used == false)
+ {
+ lane = l;
+ break;
+ }
+ }
+
+ if (lane == -1)
+ {
+ // error
+ continue;
+ }
+
+ lanes[lane].end = lines[i].second;
+ lanes[lane].used = true;
+ lines[i].laneIndex = lane;
+ }
+}
+
+
+void DisassemblyFunction::load()
+{
+ generateBranchLines();
+
+ // gather all branch targets
+ std::set branchTargets;
+ for (size_t i = 0; i < lines.size(); i++)
+ {
+ switch (lines[i].type)
+ {
+ case LINE_DOWN:
+ branchTargets.insert(lines[i].second);
+ break;
+ case LINE_UP:
+ branchTargets.insert(lines[i].first);
+ break;
+ }
+ }
+
+ DebugInterface* cpu = DisassemblyManager::getCpu();
+ u32 funcPos = address;
+ u32 funcEnd = address+size;
+
+ while (funcPos < funcEnd)
+ {
+ MIPSAnalyst::MipsOpcodeInfo opInfo = MIPSAnalyst::GetOpcodeInfo(cpu,funcPos);
+ u32 opAddress = funcPos;
+ funcPos += 4;
+
+ // skip branches and their delay slots
+ if (opInfo.isBranch)
+ {
+ DisassemblyOpcode* opcode = new DisassemblyOpcode(opAddress);
+ entries[opAddress] = opcode;
+ lineAddresses.push_back(opAddress);
+
+ DisassemblyOpcode* delaySlot = new DisassemblyOpcode(funcPos);
+ entries[funcPos] = delaySlot;
+ lineAddresses.push_back(funcPos);
+
+ funcPos += 4;
+ continue;
+ }
+
+ // lui
+ if (MIPS_GET_OP(opInfo.encodedOpcode) == 0x0F && funcPos < funcEnd)
+ {
+ MIPSOpcode next = Memory::Read_Instruction(funcPos);
+
+ u32 immediate = ((opInfo.encodedOpcode & 0xFFFF) << 16) + (s16)(next.encoding & 0xFFFF);
+ int rt = MIPS_GET_RT(opInfo.encodedOpcode);
+
+ int nextRs = MIPS_GET_RS(next.encoding);
+ int nextRt = MIPS_GET_RT(next.encoding);
+
+ // both rs and rt of the second op have to match rt of the first,
+ // otherwise there may be hidden consequences if the macro is displayed.
+ // also, don't create a macro if something branches into the middle of it
+ if (nextRs == rt && nextRt == rt && branchTargets.find(funcPos) == branchTargets.end())
+ {
+ DisassemblyMacro* macro = NULL;
+ switch (MIPS_GET_OP(next.encoding))
+ {
+ case 0x09: // addiu
+ macro = new DisassemblyMacro(opAddress);
+ macro->setMacroLi(immediate,rt);
+ funcPos += 4;
+ break;
+ case 0x20: // lb
+ case 0x21: // lh
+ case 0x23: // lw
+ case 0x24: // lbu
+ case 0x25: // lhu
+ case 0x28: // sb
+ case 0x29: // sh
+ case 0x2B: // sw
+ macro = new DisassemblyMacro(opAddress);
+ macro->setMacroMemory(MIPSGetName(next),immediate,rt);
+ funcPos += 4;
+ break;
+ }
+
+ if (macro != NULL)
+ {
+ entries[opAddress] = macro;
+ for (int i = 0; i < macro->getNumLines(); i++)
+ {
+ lineAddresses.push_back(macro->getLineAddress(i));
+ }
+ continue;
+ }
+ }
+ }
+
+ // just a normal opcode
+ DisassemblyOpcode* opcode = new DisassemblyOpcode(opAddress);
+ entries[opAddress] = opcode;
+ lineAddresses.push_back(opAddress);
+ }
+}
+
+void DisassemblyFunction::clear()
+{
+ for (auto it = entries.begin(); it != entries.end(); it++)
+ {
+ delete it->second;
+ }
+
+ entries.clear();
+ lines.clear();
+ hash = 0;
+}
+
+bool DisassemblyOpcode::disassemble(u32 address, DisassemblyLineInfo& dest)
+{
+ char opcode[64],arguments[256];
+ const char *dizz = DisassemblyManager::getCpu()->disasm(address,4);
+ parseDisasm(dizz,opcode,arguments,true);
+ dest.name = opcode;
+ dest.params = arguments;
+ dest.totalSize = 4;
+ return true;
+}
+
+
+void DisassemblyMacro::setMacroLi(u32 _immediate, u8 _rt)
+{
+ type = MACRO_LI;
+ name = "li";
+ immediate = _immediate;
+ rt = _rt;
+ numOpcodes = 2;
+}
+
+void DisassemblyMacro::setMacroMemory(std::string _name, u32 _immediate, u8 _rt)
+{
+ type = MACRO_MEMORYIMM;
+ name = _name;
+ immediate = _immediate;
+ rt = _rt;
+ numOpcodes = 2;
+}
+
+bool DisassemblyMacro::disassemble(u32 address, DisassemblyLineInfo& dest)
+{
+ char buffer[64];
+
+ switch (type)
+ {
+ case MACRO_LI:
+ case MACRO_MEMORYIMM:
+ dest.name = name;
+ sprintf(buffer,"%s,%08X",DisassemblyManager::getCpu()->GetRegName(0,rt),immediate);
+ dest.params = buffer;
+ break;
+ default:
+ return false;
+ }
+
+ dest.totalSize = getTotalSize();
+ return true;
+}
diff --git a/Core/Debugger/DisassemblyManager.h b/Core/Debugger/DisassemblyManager.h
new file mode 100644
index 0000000000..0655966dfd
--- /dev/null
+++ b/Core/Debugger/DisassemblyManager.h
@@ -0,0 +1,146 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#pragma once
+#include "Globals.h"
+#include "Core/MIPS/MIPSAnalyst.h"
+
+enum DisassemblyLineType { DISTYPE_OPCODE, DISTYPE_DATA };
+
+struct DisassemblyLineInfo
+{
+ DisassemblyLineType type;
+ MIPSAnalyst::MipsOpcodeInfo info;
+ std::string name;
+ std::string params;
+ u32 totalSize;
+};
+
+enum LineType { LINE_UP, LINE_DOWN, LINE_RIGHT };
+
+struct BranchLine
+{
+ u32 first;
+ u32 second;
+ LineType type;
+ int laneIndex;
+
+ bool operator<(const BranchLine& other) const
+ {
+ return first < other.first;
+ }
+};
+
+class DisassemblyEntry
+{
+public:
+ virtual ~DisassemblyEntry() { };
+ virtual void recheck() = 0;
+ virtual int getNumLines() = 0;
+ virtual int getLineNum(u32 address, bool findStart) = 0;
+ virtual u32 getLineAddress(int line) = 0;
+ virtual u32 getTotalSize() = 0;
+ virtual bool disassemble(u32 address, DisassemblyLineInfo& dest) = 0;
+};
+
+class DisassemblyFunction: public DisassemblyEntry
+{
+public:
+ DisassemblyFunction(u32 _address, u32 _size);
+ virtual void recheck();
+ virtual int getNumLines();
+ virtual int getLineNum(u32 address, bool findStart);
+ virtual u32 getLineAddress(int line);
+ virtual u32 getTotalSize() { return size; };
+ virtual bool disassemble(u32 address, DisassemblyLineInfo& dest);
+private:
+ u32 computeHash();
+ void generateBranchLines();
+ void load();
+ void clear();
+
+ u32 address;
+ u32 size;
+ u32 hash;
+ std::vector lines;
+ std::map entries;
+ std::vector lineAddresses;
+};
+
+class DisassemblyOpcode: public DisassemblyEntry
+{
+public:
+ DisassemblyOpcode(u32 _address): address(_address) { };
+ virtual ~DisassemblyOpcode() { };
+ virtual void recheck() { };
+ virtual int getNumLines() { return 1; };
+ virtual int getLineNum(u32 address, bool findStart) { return 0; };
+ virtual u32 getLineAddress(int line) { return address; };
+ virtual u32 getTotalSize() { return 4; };
+ virtual bool disassemble(u32 address, DisassemblyLineInfo& dest);
+private:
+ u32 address;
+};
+
+
+class DisassemblyMacro: public DisassemblyEntry
+{
+public:
+ DisassemblyMacro(u32 _address): address(_address) { };
+ virtual ~DisassemblyMacro() { };
+
+ void setMacroLi(u32 _immediate, u8 _rt);
+ void setMacroMemory(std::string _name, u32 _immediate, u8 _rt);
+
+ virtual void recheck() { };
+ virtual int getNumLines() { return 1; };
+ virtual int getLineNum(u32 address, bool findStart) { return 0; };
+ virtual u32 getLineAddress(int line) { return address; };
+ virtual u32 getTotalSize() { return numOpcodes*4; };
+ virtual bool disassemble(u32 address, DisassemblyLineInfo& dest) ;
+private:
+ enum MacroType { MACRO_LI, MACRO_MEMORYIMM };
+
+ MacroType type;
+ std::string name;
+ u32 immediate;
+ u32 address;
+ u32 numOpcodes;
+ u8 rt;
+};
+
+
+class DebugInterface;
+
+class DisassemblyManager
+{
+public:
+
+ void setCpu(DebugInterface* _cpu) { cpu = _cpu; };
+ DisassemblyLineInfo getLine(u32 address, bool insertSymbols);
+ void analyze(u32 address, u32 size);
+
+ u32 getStartAddress(u32 address);
+ u32 getNthPreviousAddress(u32 address, int n = 1);
+ u32 getNthNextAddress(u32 address, int n = 1);
+
+ static DebugInterface* getCpu() { return cpu; };
+private:
+ DisassemblyEntry* getEntry(u32 address);
+ static std::map entries;
+ static DebugInterface* cpu;
+};
\ No newline at end of file
diff --git a/Windows/Debugger/CtrlDisAsmView.cpp b/Windows/Debugger/CtrlDisAsmView.cpp
index 41f2be19c2..bdbf4f4850 100644
--- a/Windows/Debugger/CtrlDisAsmView.cpp
+++ b/Windows/Debugger/CtrlDisAsmView.cpp
@@ -54,165 +54,8 @@ void CtrlDisAsmView::deinit()
//UnregisterClass(szClassName, hInst)
}
-#define NUM_LANES 16
-
-bool compareBranchLines(BranchLine& a,BranchLine& b)
-{
- return a.first < b.first;
-}
-
void CtrlDisAsmView::scanFunctions()
{
- struct LaneInfo
- {
- bool used;
- u32 end;
- };
-
- u32 pos = windowStart;
- u32 windowEnd = windowStart+visibleRows*instructionSize;
-
- visibleFunctionAddresses.clear();
- strayLines.clear();
-
- while (pos < windowEnd)
- {
- SymbolInfo info;
- if (symbolMap.GetSymbolInfo(&info,pos))
- {
- u32 hash = XXH32(Memory::GetPointer(info.address),info.size,0xBACD7814);
- u32 funcEnd = info.address+info.size;
-
- visibleFunctionAddresses.push_back(info.address);
-
- auto it = functions.find(info.address);
- if (it != functions.end() && it->second.hash == hash)
- {
- // function is unchaged
- pos = funcEnd;
- continue;
- }
-
- DisassemblyFunction func;
- func.hash = hash;
-
- LaneInfo lanes[NUM_LANES];
- for (int i = 0; i < NUM_LANES; i++)
- lanes[i].used = false;
-
-
- for (u32 funcPos = info.address; funcPos < funcEnd; funcPos += instructionSize)
- {
- MIPSAnalyst::MipsOpcodeInfo opInfo = MIPSAnalyst::GetOpcodeInfo(debugger,funcPos);
-
- bool inFunction = (opInfo.branchTarget >= info.address && opInfo.branchTarget < funcEnd);
- if (opInfo.isBranch && !opInfo.isBranchToRegister && !opInfo.isLinkedBranch && inFunction)
- {
- BranchLine line;
- if (opInfo.branchTarget < funcPos)
- {
- line.first = opInfo.branchTarget;
- line.second = funcPos;
- line.type = LINE_UP;
- } else {
- line.first = funcPos;
- line.second = opInfo.branchTarget;
- line.type = LINE_DOWN;
- }
-
- func.lines.push_back(line);
- }
- }
-
- std::sort(func.lines.begin(),func.lines.end(),compareBranchLines);
- for (size_t i = 0; i < func.lines.size(); i++)
- {
- for (int l = 0; l < NUM_LANES; l++)
- {
- if (func.lines[i].first > lanes[l].end)
- lanes[l].used = false;
- }
-
- int lane = -1;
- for (int l = 0; l < NUM_LANES; l++)
- {
- if (lanes[l].used == false)
- {
- lane = l;
- break;
- }
- }
-
- if (lane == -1)
- {
- // error
- continue;
- }
-
- lanes[lane].end = func.lines[i].second;
- lanes[lane].used = true;
- func.lines[i].laneIndex = lane;
- }
-
- functions[info.address] = func;
- pos = funcEnd;
- } else {
- MIPSAnalyst::MipsOpcodeInfo opInfo = MIPSAnalyst::GetOpcodeInfo(debugger,pos);
- if (opInfo.isBranch && !opInfo.isBranchToRegister && !opInfo.isLinkedBranch)
- {
- BranchLine line;
- if (opInfo.branchTarget < pos)
- {
- line.first = opInfo.branchTarget;
- line.second = pos;
- line.type = LINE_UP;
- } else {
- line.first = pos;
- line.second = opInfo.branchTarget;
- line.type = LINE_DOWN;
- }
-
- strayLines.push_back(line);
- }
-
- pos += instructionSize;
- }
- }
-
- // calculate lanes for strayBranches
- LaneInfo lanes[NUM_LANES];
- for (int i = 0; i < NUM_LANES; i++)
- lanes[i].used = false;
-
- std::sort(strayLines.begin(),strayLines.end(),compareBranchLines);
- for (size_t i = 0; i < strayLines.size(); i++)
- {
- for (int l = 0; l < NUM_LANES; l++)
- {
- if (strayLines[i].first > lanes[l].end)
- lanes[l].used = false;
- }
-
- int lane = -1;
- for (int l = 0; l < NUM_LANES; l++)
- {
- if (lanes[l].used == false)
- {
- lane = l;
- break;
- }
- }
-
- if (lane == -1)
- {
- // error
- continue;
- }
-
- lanes[lane].end = strayLines[i].second;
- lanes[lane].used = true;
- strayLines[i].laneIndex = lane;
- }
}
@@ -648,10 +491,10 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
HICON breakPoint = (HICON)LoadIcon(GetModuleHandle(0),(LPCWSTR)IDI_STOP);
HICON breakPointDisable = (HICON)LoadIcon(GetModuleHandle(0),(LPCWSTR)IDI_STOPDISABLE);
+ unsigned int address = windowStart;
for (int i = 0; i < visibleRows; i++)
{
- unsigned int address=windowStart + i*instructionSize;
- MIPSAnalyst::MipsOpcodeInfo info = MIPSAnalyst::GetOpcodeInfo(debugger,address);
+ DisassemblyLineInfo line = manager.getLine(address,true);
int rowY1 = rowHeight*i;
int rowY2 = rowHeight*(i+1);
@@ -708,30 +551,27 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
TextOut(hdc,pixelPositions.opcodeStart-8,rowY1,L"■",1);
}
- // display opcode
- char opcode[64],arguments[256];
- const char *dizz = debugger->disasm(address, instructionSize);
- parseDisasm(dizz,opcode,arguments);
-
// display whether the condition of a branch is met
- if (info.isConditional && address == debugger->getPC())
+ if (line.info.isConditional && address == debugger->getPC())
{
- strcat(arguments,info.conditionMet ? " ; true" : " ; false");
+ line.params += line.info.conditionMet ? " ; true" : " ; false";
}
- int length = (int) strlen(arguments);
- if (length != 0) TextOutA(hdc,pixelPositions.argumentsStart,rowY1+2,arguments,length);
+ if (line.params.size() != 0)
+ TextOutA(hdc,pixelPositions.argumentsStart,rowY1+2,line.params.c_str(),line.params.size());
SelectObject(hdc,boldfont);
- TextOutA(hdc,pixelPositions.opcodeStart,rowY1+2,opcode,(int)strlen(opcode));
+ TextOutA(hdc,pixelPositions.opcodeStart,rowY1+2,line.name.c_str(),line.name.size());
SelectObject(hdc,font);
+
+ address += line.totalSize;
}
- for (size_t i = 0; i < visibleFunctionAddresses.size(); i++)
+/* for (size_t i = 0; i < visibleFunctionAddresses.size(); i++)
{
auto it = functions.find(visibleFunctionAddresses[i]);
if (it == functions.end()) continue;
- DisassemblyFunction& func = it->second;
+ DisassemblyFunc& func = it->second;
for (size_t l = 0; l < func.lines.size(); l++)
{
@@ -742,7 +582,7 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
for (size_t i = 0; i < strayLines.size(); i++)
{
drawBranchLine(hdc,strayLines[i]);
- }
+ }*/
SelectObject(hdc,oldFont);
SelectObject(hdc,oldPen);
@@ -771,16 +611,16 @@ void CtrlDisAsmView::onVScroll(WPARAM wParam, LPARAM lParam)
switch (wParam & 0xFFFF)
{
case SB_LINEDOWN:
- windowStart += instructionSize;
+ windowStart = manager.getNthNextAddress(windowStart,1);
break;
case SB_LINEUP:
- windowStart -= instructionSize;
+ windowStart = manager.getNthPreviousAddress(windowStart,1);
break;
case SB_PAGEDOWN:
- windowStart += visibleRows*instructionSize;
+ windowStart = manager.getNthNextAddress(windowStart,visibleRows);
break;
case SB_PAGEUP:
- windowStart -= visibleRows*instructionSize;
+ windowStart = manager.getNthPreviousAddress(windowStart,visibleRows);
break;
default:
return;
@@ -850,7 +690,7 @@ void CtrlDisAsmView::editBreakpoint()
void CtrlDisAsmView::onKeyDown(WPARAM wParam, LPARAM lParam)
{
dontRedraw = false;
- u32 windowEnd = windowStart+visibleRows*instructionSize;
+ u32 windowEnd = manager.getNthNextAddress(windowStart,visibleRows);
keyTaken = true;
if (KeyDownAsync(VK_CONTROL))
@@ -893,7 +733,7 @@ void CtrlDisAsmView::onKeyDown(WPARAM wParam, LPARAM lParam)
scanFunctions();
break;
case VK_NEXT:
- setCurAddress(windowEnd-instructionSize,KeyDownAsync(VK_SHIFT));
+ setCurAddress(manager.getNthPreviousAddress(windowEnd,1),KeyDownAsync(VK_SHIFT));
break;
case VK_PRIOR:
setCurAddress(windowStart,KeyDownAsync(VK_SHIFT));
@@ -903,19 +743,19 @@ void CtrlDisAsmView::onKeyDown(WPARAM wParam, LPARAM lParam)
switch (wParam & 0xFFFF)
{
case VK_DOWN:
- setCurAddress(curAddress + instructionSize, KeyDownAsync(VK_SHIFT));
+ setCurAddress(manager.getNthNextAddress(curAddress,1), KeyDownAsync(VK_SHIFT));
scrollAddressIntoView();
break;
case VK_UP:
- setCurAddress(curAddress - instructionSize, KeyDownAsync(VK_SHIFT));
+ setCurAddress(manager.getNthPreviousAddress(curAddress,1), KeyDownAsync(VK_SHIFT));
scrollAddressIntoView();
break;
case VK_NEXT:
- if (curAddress != windowEnd - instructionSize && curAddressIsVisible()) {
- setCurAddress(windowEnd - instructionSize, KeyDownAsync(VK_SHIFT));
+ if (manager.getNthNextAddress(curAddress,1) != windowEnd && curAddressIsVisible()) {
+ setCurAddress(manager.getNthPreviousAddress(windowEnd,1), KeyDownAsync(VK_SHIFT));
scrollAddressIntoView();
} else {
- setCurAddress(curAddress + visibleRows * instructionSize, KeyDownAsync(VK_SHIFT));
+ setCurAddress(manager.getNthNextAddress(windowEnd,visibleRows-1), KeyDownAsync(VK_SHIFT));
scrollAddressIntoView();
}
break;
@@ -924,7 +764,7 @@ void CtrlDisAsmView::onKeyDown(WPARAM wParam, LPARAM lParam)
setCurAddress(windowStart, KeyDownAsync(VK_SHIFT));
scrollAddressIntoView();
} else {
- setCurAddress(curAddress - visibleRows * instructionSize, KeyDownAsync(VK_SHIFT));
+ setCurAddress(manager.getNthPreviousAddress(windowStart,visibleRows), KeyDownAsync(VK_SHIFT));
scrollAddressIntoView();
}
break;
@@ -965,19 +805,19 @@ void CtrlDisAsmView::onKeyUp(WPARAM wParam, LPARAM lParam)
void CtrlDisAsmView::scrollAddressIntoView()
{
- u32 windowEnd = windowStart + visibleRows * instructionSize;
+ u32 windowEnd = manager.getNthNextAddress(windowStart,visibleRows);
if (curAddress < windowStart)
windowStart = curAddress;
else if (curAddress >= windowEnd)
- windowStart = curAddress - visibleRows * instructionSize + instructionSize;
+ windowStart = manager.getNthPreviousAddress(curAddress,visibleRows-1);
scanFunctions();
}
bool CtrlDisAsmView::curAddressIsVisible()
{
- u32 windowEnd = windowStart + visibleRows * instructionSize;
+ u32 windowEnd = manager.getNthNextAddress(windowStart,visibleRows);
return curAddress >= windowStart && curAddress < windowEnd;
}
@@ -1285,7 +1125,7 @@ void CtrlDisAsmView::updateStatusBarText()
u32 CtrlDisAsmView::yToAddress(int y)
{
int line = y/rowHeight;
- return windowStart + line*instructionSize;
+ return manager.getNthNextAddress(windowStart,line);
}
void CtrlDisAsmView::calculatePixelPositions()
@@ -1314,9 +1154,9 @@ void CtrlDisAsmView::search(bool continueSearch)
searchQuery[i] = tolower(searchQuery[i]);
}
SetFocus(wnd);
- searchAddress = curAddress+instructionSize;
+ searchAddress = manager.getNthNextAddress(curAddress,1);
} else {
- searchAddress = matchAddress+instructionSize;
+ searchAddress = manager.getNthNextAddress(matchAddress,1);
}
// limit address to sensible ranges
@@ -1331,11 +1171,14 @@ void CtrlDisAsmView::search(bool continueSearch)
redraw(); // so the cursor is disabled
while (searchAddress < 0x0A000000)
{
- char addressText[64],opcode[64],arguments[256];
- const char *dis = debugger->disasm(searchAddress, instructionSize);
- parseDisasm(dis,opcode,arguments);
+ DisassemblyLineInfo lineInfo = manager.getLine(searchAddress,displaySymbols);
+
+ char addressText[64];
getDisasmAddressText(searchAddress,addressText,true);
+ const char* opcode = lineInfo.name.c_str();
+ const char* arguments = lineInfo.params.c_str();
+
char merged[512];
int mergePos = 0;
@@ -1363,7 +1206,7 @@ void CtrlDisAsmView::search(bool continueSearch)
return;
}
- searchAddress += instructionSize;
+ searchAddress = manager.getNthNextAddress(searchAddress,1);
if (searchAddress >= 0x04200000 && searchAddress < 0x08000000) searchAddress = 0x08000000;
}
diff --git a/Windows/Debugger/CtrlDisAsmView.h b/Windows/Debugger/CtrlDisAsmView.h
index aeacdc1a54..edfe640d9c 100644
--- a/Windows/Debugger/CtrlDisAsmView.h
+++ b/Windows/Debugger/CtrlDisAsmView.h
@@ -19,6 +19,8 @@
// CtrlDisAsmView::getFrom(GetDlgItem(yourdialog, IDC_yourid)).
#include "../../Core/Debugger/DebugInterface.h"
+#include "../../Core/Debugger/DisassemblyManager.h"
+
#include "Common/CommonWindows.h"
#include
@@ -27,23 +29,6 @@
using std::min;
using std::max;
-
-enum LineType { LINE_UP, LINE_DOWN, LINE_RIGHT };
-
-struct BranchLine
-{
- u32 first;
- u32 second;
- LineType type;
- int laneIndex;
-};
-
-struct DisassemblyFunction
-{
- u32 hash;
- std::vector lines;
-};
-
class CtrlDisAsmView
{
HWND wnd;
@@ -51,10 +36,11 @@ class CtrlDisAsmView
HFONT boldfont;
RECT rect;
- std::map functions;
+// std::map functions;
std::vector visibleFunctionAddresses;
std::vector strayLines;
+ DisassemblyManager manager;
u32 curAddress;
u32 selectRangeStart;
u32 selectRangeEnd;
@@ -122,7 +108,7 @@ public:
void scanFunctions();
void clearFunctions()
{
- functions.clear();
+ // functions.clear();
visibleFunctionAddresses.clear();
strayLines.clear();
};
@@ -137,6 +123,7 @@ public:
debugger=deb;
curAddress=debugger->getPC();
instructionSize=debugger->getInstructionSize(0);
+ manager.setCpu(deb);
}
DebugInterface *getDebugger()
{
@@ -177,14 +164,18 @@ public:
void scrollWindow(int lines)
{
- windowStart += lines*instructionSize;
+ if (lines < 0)
+ windowStart = manager.getNthPreviousAddress(windowStart,abs(lines));
+ else
+ windowStart = manager.getNthNextAddress(windowStart,lines);
+
scanFunctions();
redraw();
}
void setCurAddress(u32 newAddress, bool extend = false)
{
- u32 after = newAddress + instructionSize;
+ u32 after = manager.getNthNextAddress(newAddress,1);
curAddress = newAddress;
selectRangeStart = extend ? std::min(selectRangeStart, newAddress) : newAddress;
selectRangeEnd = extend ? std::max(selectRangeEnd, after) : after;