Debugger: Avoid unaligned reads in expressions.

Potentially, a watch or break condition could crash if it was unaligned
between mirrors.  This might happen if it's not the condition you wanted,
especially.  Play it safe.
This commit is contained in:
Unknown W. Brackets committed 2023-04-12 01:14:30 -07:00
1 parent 956d80b93e
commit 9cebfc31b3
6 files changed
+39 -25

No files matched your search

+11 -7
View File
@@ -162,17 +162,20 @@ public:
bool getMemoryValue(uint32_t address, int size, uint32_t& dest, char* error) override {
// We allow, but ignore, bad access.
// If we didn't, log/condition statements that reference registers couldn't be configured.
bool valid = Memory::IsValidRange(address, size);
uint32_t valid = Memory::ValidSize(address, size);
uint8_t buf[4]{};
if (valid != 0)
memcpy(buf, Memory::GetPointerUnchecked(address), valid);
switch (size) {
case 1:
dest = valid ? Memory::Read_U8(address) : 0;
dest = buf[0];
return true;
case 2:
dest = valid ? Memory::Read_U16(address) : 0;
dest = (buf[1] << 8) | buf[0];
return true;
case 4:
dest = valid ? Memory::Read_U32(address) : 0;
dest = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
return true;
}
@@ -196,9 +199,10 @@ const char *MIPSDebugInterface::disasm(unsigned int address, unsigned int align)
return mojs;
}
unsigned int MIPSDebugInterface::readMemory(unsigned int address)
{
return Memory::Read_Instruction(address).encoding;
unsigned int MIPSDebugInterface::readMemory(unsigned int address) {
if (Memory::IsValidRange(address, 4))
return Memory::ReadUnchecked_Instruction(address).encoding;
return 0;
}
bool MIPSDebugInterface::isAlive()