mirror of
https://github.com/libretro/ppsspp.git
synced 2024-12-11 18:33:41 +00:00
Fix follow branch, display symbols
This commit is contained in:
parent
9ea00b2761
commit
0672458a33
@ -87,6 +87,8 @@ void parseDisasm(const char* disasm, char* opcode, char* arguments, bool insertS
|
||||
void DisassemblyManager::analyze(u32 address, u32 size)
|
||||
{
|
||||
u32 end = address+size;
|
||||
|
||||
address &= ~3;
|
||||
u32 start = address;
|
||||
|
||||
while (address < end && start <= address)
|
||||
@ -165,7 +167,7 @@ DisassemblyLineInfo DisassemblyManager::getLine(u32 address, bool insertSymbols)
|
||||
DisassemblyEntry* entry = it->second;
|
||||
|
||||
result.info = MIPSAnalyst::GetOpcodeInfo(cpu,address);
|
||||
if (entry->disassemble(address,result))
|
||||
if (entry->disassemble(address,result,insertSymbols))
|
||||
return result;
|
||||
|
||||
result.totalSize = 4;
|
||||
@ -295,13 +297,13 @@ u32 DisassemblyFunction::getLineAddress(int line)
|
||||
return lineAddresses[line];
|
||||
}
|
||||
|
||||
bool DisassemblyFunction::disassemble(u32 address, DisassemblyLineInfo& dest)
|
||||
bool DisassemblyFunction::disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols)
|
||||
{
|
||||
auto it = findDisassemblyEntry(entries,address,true);
|
||||
if (it == entries.end())
|
||||
return false;
|
||||
|
||||
return it->second->disassemble(address,dest);
|
||||
return it->second->disassemble(address,dest,insertSymbols);
|
||||
}
|
||||
|
||||
|
||||
@ -425,6 +427,7 @@ void DisassemblyFunction::load()
|
||||
if (MIPS_GET_OP(opInfo.encodedOpcode) == 0x0F && funcPos < funcEnd)
|
||||
{
|
||||
MIPSOpcode next = Memory::Read_Instruction(funcPos);
|
||||
MIPSInfo nextInfo = MIPSGetInfo(next);
|
||||
|
||||
u32 immediate = ((opInfo.encodedOpcode & 0xFFFF) << 16) + (s16)(next.encoding & 0xFFFF);
|
||||
int rt = MIPS_GET_RT(opInfo.encodedOpcode);
|
||||
@ -454,7 +457,25 @@ void DisassemblyFunction::load()
|
||||
case 0x29: // sh
|
||||
case 0x2B: // sw
|
||||
macro = new DisassemblyMacro(opAddress);
|
||||
macro->setMacroMemory(MIPSGetName(next),immediate,rt);
|
||||
|
||||
int dataSize;
|
||||
switch (nextInfo & MEMTYPE_MASK) {
|
||||
case MEMTYPE_BYTE:
|
||||
dataSize = 1;
|
||||
break;
|
||||
case MEMTYPE_HWORD:
|
||||
dataSize = 2;
|
||||
break;
|
||||
case MEMTYPE_WORD:
|
||||
case MEMTYPE_FLOAT:
|
||||
dataSize = 4;
|
||||
break;
|
||||
case MEMTYPE_VQUAD:
|
||||
dataSize = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
macro->setMacroMemory(MIPSGetName(next),immediate,rt,dataSize);
|
||||
funcPos += 4;
|
||||
break;
|
||||
}
|
||||
@ -490,11 +511,11 @@ void DisassemblyFunction::clear()
|
||||
hash = 0;
|
||||
}
|
||||
|
||||
bool DisassemblyOpcode::disassemble(u32 address, DisassemblyLineInfo& dest)
|
||||
bool DisassemblyOpcode::disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols)
|
||||
{
|
||||
char opcode[64],arguments[256];
|
||||
const char *dizz = DisassemblyManager::getCpu()->disasm(address,4);
|
||||
parseDisasm(dizz,opcode,arguments,true);
|
||||
parseDisasm(dizz,opcode,arguments,insertSymbols);
|
||||
dest.name = opcode;
|
||||
dest.params = arguments;
|
||||
dest.totalSize = 4;
|
||||
@ -511,26 +532,58 @@ void DisassemblyMacro::setMacroLi(u32 _immediate, u8 _rt)
|
||||
numOpcodes = 2;
|
||||
}
|
||||
|
||||
void DisassemblyMacro::setMacroMemory(std::string _name, u32 _immediate, u8 _rt)
|
||||
void DisassemblyMacro::setMacroMemory(std::string _name, u32 _immediate, u8 _rt, int _dataSize)
|
||||
{
|
||||
type = MACRO_MEMORYIMM;
|
||||
name = _name;
|
||||
immediate = _immediate;
|
||||
rt = _rt;
|
||||
dataSize = _dataSize;
|
||||
numOpcodes = 2;
|
||||
}
|
||||
|
||||
bool DisassemblyMacro::disassemble(u32 address, DisassemblyLineInfo& dest)
|
||||
bool DisassemblyMacro::disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols)
|
||||
{
|
||||
char buffer[64];
|
||||
|
||||
const char* addressSymbol;
|
||||
switch (type)
|
||||
{
|
||||
case MACRO_LI:
|
||||
dest.name = name;
|
||||
|
||||
addressSymbol = DisassemblyManager::getCpu()->findSymbolForAddress(immediate);
|
||||
if (addressSymbol != NULL && insertSymbols)
|
||||
{
|
||||
sprintf(buffer,"%s,%s",DisassemblyManager::getCpu()->GetRegName(0,rt),addressSymbol);
|
||||
} else {
|
||||
sprintf(buffer,"%s,0x%08X",DisassemblyManager::getCpu()->GetRegName(0,rt),immediate);
|
||||
}
|
||||
|
||||
dest.params = buffer;
|
||||
|
||||
dest.info.hasRelevantAddress = true;
|
||||
dest.info.releventAddress = immediate;
|
||||
break;
|
||||
case MACRO_MEMORYIMM:
|
||||
dest.name = name;
|
||||
sprintf(buffer,"%s,0x%08X",DisassemblyManager::getCpu()->GetRegName(0,rt),immediate);
|
||||
|
||||
addressSymbol = DisassemblyManager::getCpu()->findSymbolForAddress(immediate);
|
||||
if (addressSymbol != NULL && insertSymbols)
|
||||
{
|
||||
sprintf(buffer,"%s,%s",DisassemblyManager::getCpu()->GetRegName(0,rt),addressSymbol);
|
||||
} else {
|
||||
sprintf(buffer,"%s,0x%08X",DisassemblyManager::getCpu()->GetRegName(0,rt),immediate);
|
||||
}
|
||||
|
||||
dest.params = buffer;
|
||||
|
||||
dest.info.isDataAccess = true;
|
||||
dest.info.dataAddress = immediate;
|
||||
dest.info.dataSize = dataSize;
|
||||
|
||||
dest.info.hasRelevantAddress = true;
|
||||
dest.info.releventAddress = immediate;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
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;
|
||||
virtual bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols) = 0;
|
||||
};
|
||||
|
||||
class DisassemblyFunction: public DisassemblyEntry
|
||||
@ -66,7 +66,7 @@ public:
|
||||
virtual int getLineNum(u32 address, bool findStart);
|
||||
virtual u32 getLineAddress(int line);
|
||||
virtual u32 getTotalSize() { return size; };
|
||||
virtual bool disassemble(u32 address, DisassemblyLineInfo& dest);
|
||||
virtual bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols);
|
||||
private:
|
||||
u32 computeHash();
|
||||
void generateBranchLines();
|
||||
@ -91,7 +91,7 @@ public:
|
||||
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);
|
||||
virtual bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols);
|
||||
private:
|
||||
u32 address;
|
||||
};
|
||||
@ -104,14 +104,14 @@ public:
|
||||
virtual ~DisassemblyMacro() { };
|
||||
|
||||
void setMacroLi(u32 _immediate, u8 _rt);
|
||||
void setMacroMemory(std::string _name, u32 _immediate, u8 _rt);
|
||||
void setMacroMemory(std::string _name, u32 _immediate, u8 _rt, int _dataSize);
|
||||
|
||||
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) ;
|
||||
virtual bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols) ;
|
||||
private:
|
||||
enum MacroType { MACRO_LI, MACRO_MEMORYIMM };
|
||||
|
||||
@ -121,6 +121,7 @@ private:
|
||||
u32 address;
|
||||
u32 numOpcodes;
|
||||
u8 rt;
|
||||
int dataSize;
|
||||
};
|
||||
|
||||
|
||||
|
@ -431,7 +431,7 @@ void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
|
||||
unsigned int address = windowStart;
|
||||
for (int i = 0; i < visibleRows; i++)
|
||||
{
|
||||
DisassemblyLineInfo line = manager.getLine(address,true);
|
||||
DisassemblyLineInfo line = manager.getLine(address,displaySymbols);
|
||||
|
||||
int rowY1 = rowHeight*i;
|
||||
int rowY2 = rowHeight*(i+1);
|
||||
@ -569,16 +569,16 @@ void CtrlDisAsmView::onVScroll(WPARAM wParam, LPARAM lParam)
|
||||
|
||||
void CtrlDisAsmView::followBranch()
|
||||
{
|
||||
MIPSAnalyst::MipsOpcodeInfo info = MIPSAnalyst::GetOpcodeInfo(debugger,curAddress);
|
||||
DisassemblyLineInfo line = manager.getLine(curAddress,true);
|
||||
|
||||
if (info.isBranch)
|
||||
if (line.info.isBranch)
|
||||
{
|
||||
jumpStack.push_back(curAddress);
|
||||
gotoAddr(info.branchTarget);
|
||||
} else if (info.hasRelevantAddress)
|
||||
gotoAddr(line.info.branchTarget);
|
||||
} else if (line.info.hasRelevantAddress)
|
||||
{
|
||||
// well, not exactly a branch, but we can do something anyway
|
||||
SendMessage(GetParent(wnd),WM_DEB_GOTOHEXEDIT,info.releventAddress,0);
|
||||
SendMessage(GetParent(wnd),WM_DEB_GOTOHEXEDIT,line.info.releventAddress,0);
|
||||
SetFocus(wnd);
|
||||
}
|
||||
}
|
||||
@ -1008,33 +1008,33 @@ void CtrlDisAsmView::onMouseMove(WPARAM wParam, LPARAM lParam, int button)
|
||||
void CtrlDisAsmView::updateStatusBarText()
|
||||
{
|
||||
char text[512];
|
||||
MIPSAnalyst::MipsOpcodeInfo info = MIPSAnalyst::GetOpcodeInfo(debugger,curAddress);
|
||||
DisassemblyLineInfo line = manager.getLine(curAddress,true);
|
||||
|
||||
text[0] = 0;
|
||||
if (info.isDataAccess)
|
||||
if (line.info.isDataAccess)
|
||||
{
|
||||
if (!Memory::IsValidAddress(info.dataAddress))
|
||||
if (!Memory::IsValidAddress(line.info.dataAddress))
|
||||
{
|
||||
sprintf(text,"Invalid address %08X",info.dataAddress);
|
||||
sprintf(text,"Invalid address %08X",line.info.dataAddress);
|
||||
} else {
|
||||
switch (info.dataSize)
|
||||
switch (line.info.dataSize)
|
||||
{
|
||||
case 1:
|
||||
sprintf(text,"[%08X] = %02X",info.dataAddress,Memory::Read_U8(info.dataAddress));
|
||||
sprintf(text,"[%08X] = %02X",line.info.dataAddress,Memory::Read_U8(line.info.dataAddress));
|
||||
break;
|
||||
case 2:
|
||||
sprintf(text,"[%08X] = %04X",info.dataAddress,Memory::Read_U16(info.dataAddress));
|
||||
sprintf(text,"[%08X] = %04X",line.info.dataAddress,Memory::Read_U16(line.info.dataAddress));
|
||||
break;
|
||||
case 4:
|
||||
// TODO: Could also be a float...
|
||||
{
|
||||
u32 data = Memory::Read_U32(info.dataAddress);
|
||||
u32 data = Memory::Read_U32(line.info.dataAddress);
|
||||
const char* addressSymbol = debugger->findSymbolForAddress(data);
|
||||
if (addressSymbol)
|
||||
{
|
||||
sprintf(text,"[%08X] = %s (%08X)",info.dataAddress,addressSymbol,data);
|
||||
sprintf(text,"[%08X] = %s (%08X)",line.info.dataAddress,addressSymbol,data);
|
||||
} else {
|
||||
sprintf(text,"[%08X] = %08X",info.dataAddress,data);
|
||||
sprintf(text,"[%08X] = %08X",line.info.dataAddress,data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1045,14 +1045,14 @@ void CtrlDisAsmView::updateStatusBarText()
|
||||
}
|
||||
}
|
||||
|
||||
if (info.isBranch)
|
||||
if (line.info.isBranch)
|
||||
{
|
||||
const char* addressSymbol = debugger->findSymbolForAddress(info.branchTarget);
|
||||
const char* addressSymbol = debugger->findSymbolForAddress(line.info.branchTarget);
|
||||
if (addressSymbol == NULL)
|
||||
{
|
||||
sprintf(text,"%08X",info.branchTarget);
|
||||
sprintf(text,"%08X",line.info.branchTarget);
|
||||
} else {
|
||||
sprintf(text,"%08X = %s",info.branchTarget,addressSymbol);
|
||||
sprintf(text,"%08X = %s",line.info.branchTarget,addressSymbol);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user