mirror of
https://github.com/libretro/Mesen.git
synced 2024-12-16 22:06:34 +00:00
Debugger: Fixed disassembly of unverified code causing real code to not be shown properly + prevented out-of-bound memory accesses
This commit is contained in:
parent
8c9f32419c
commit
bb053a2c2b
@ -325,7 +325,7 @@ string Disassembler::GetCode(uint32_t startAddr, uint32_t endAddr, uint16_t memo
|
||||
}
|
||||
}
|
||||
|
||||
if(info) {
|
||||
if(info && addr + info->GetSize() <= endAddr) {
|
||||
if(byteCount > 0) {
|
||||
output += GetLine(dbBuffer, "", dbRelativeAddr, dbAbsoluteAddr);
|
||||
byteCount = 0;
|
||||
@ -347,8 +347,21 @@ string Disassembler::GetCode(uint32_t startAddr, uint32_t endAddr, uint16_t memo
|
||||
output += GetLine("__sub end__") + GetLine();
|
||||
}
|
||||
|
||||
addr += info->GetSize();
|
||||
memoryAddr += info->GetSize();
|
||||
if(speculativeCode) {
|
||||
//For unverified code, check if a verified instruction starts between the start of this instruction and its end.
|
||||
//If so, we need to realign the disassembler to the start of the next verified instruction
|
||||
for(uint32_t i = 0; i < info->GetSize(); i++) {
|
||||
addr++;
|
||||
memoryAddr++;
|
||||
if(addr > endAddr || (*cache)[addr&mask]) {
|
||||
//Verified code found, stop incrementing address counters
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
addr += info->GetSize();
|
||||
memoryAddr += info->GetSize();
|
||||
}
|
||||
} else {
|
||||
if((!label.empty() || !commentString.empty()) && skippingCode) {
|
||||
output += GetLine(unknownBlockHeader, "", (uint16_t)(memoryAddr - 1), addr - 1);
|
||||
|
@ -98,21 +98,6 @@ DisassemblyInfo::DisassemblyInfo(uint8_t* opPointer, bool isSubEntryPoint)
|
||||
_opSize = DisassemblyInfo::OPSize[opCode];
|
||||
_opMode = DisassemblyInfo::OPMode[opCode];
|
||||
_isSubExitPoint = opCode == 0x40 || opCode == 0x60;
|
||||
|
||||
//Raw byte code
|
||||
string byteCodeOutput;
|
||||
byteCodeOutput.reserve(10);
|
||||
for(uint32_t i = 0; i < 3; i++) {
|
||||
if(i < _opSize) {
|
||||
byteCodeOutput += "$" + HexUtilities::ToHex((uint8_t)*(_opPointer + i));
|
||||
} else {
|
||||
byteCodeOutput += " ";
|
||||
}
|
||||
if(i != 2) {
|
||||
byteCodeOutput += " ";
|
||||
}
|
||||
}
|
||||
_byteCode = byteCodeOutput;
|
||||
}
|
||||
|
||||
void DisassemblyInfo::SetSubEntryPoint()
|
||||
@ -185,6 +170,19 @@ int32_t DisassemblyInfo::GetEffectiveAddress(State& cpuState, shared_ptr<MemoryM
|
||||
|
||||
string DisassemblyInfo::GetByteCode()
|
||||
{
|
||||
if(_byteCode.empty()) {
|
||||
//Raw byte code
|
||||
string byteCodeOutput;
|
||||
byteCodeOutput.reserve(10);
|
||||
for(uint32_t i = 0; i < _opSize; i++) {
|
||||
if(!byteCodeOutput.empty()) {
|
||||
byteCodeOutput += " ";
|
||||
}
|
||||
byteCodeOutput += "$" + HexUtilities::ToHex((uint8_t)*(_opPointer + i));
|
||||
}
|
||||
_byteCode = byteCodeOutput;
|
||||
}
|
||||
|
||||
return _byteCode;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user