Commit c2ea5e7b authored by hjk's avatar hjk
Browse files

debugger: fix off-by-one error when accessing registers via trk

parent 9412b138
......@@ -537,7 +537,11 @@ void Adapter::handleGdbResponse(const QByteArray &response)
#endif
bool ok = false;
uint registerNumber = response.mid(1).toInt(&ok, 16);
if (registerNumber < RegisterCount) {
if (registerNumber == RegisterPSGdb) {
QByteArray ba;
appendInt(&ba, m_snapshot.registers[RegisterPSTrk]);
sendGdbMessage(ba.toHex(), "read processor status register");
} else if (registerNumber < RegisterCount) {
QByteArray ba;
appendInt(&ba, m_snapshot.registers[registerNumber]);
sendGdbMessage(ba.toHex(), "read single known register");
......@@ -1059,8 +1063,10 @@ void Adapter::handleAndReportReadRegisters(const TrkResult &result)
// [80 0B 00 00 00 00 00 C9 24 FF BC 00 00 00 00 00
// 60 00 00 00 00 00 00 78 67 79 70 00 00 00 00 00...]
const char *data = result.data.data();
for (int i = 0; i < RegisterCount; ++i)
for (int i = 0; i < RegisterCount; ++i) {
m_snapshot.registers[i] = extractInt(data + 4 * i);
//qDebug() << i << hexNumber(m_snapshot.registers[i], 8);
}
//QByteArray ba = result.data.toHex();
QByteArray ba;
......
......@@ -94,7 +94,7 @@ Inferior::Inferior()
registers[13] = 0x00403ED0;
registers[14] = 0x786A6BD8;
registers[15] = 0x786A4CC8;
//registers[25] = 0x68000010;
registers[16] = 0x68000010; // that's reg 25 on chip?
}
class TrkServer : public QObject
......@@ -238,9 +238,7 @@ void TrkServer::handleAdapterMessage(const TrkResult &result)
break;
}
case 0x12: { // Read Registers
appendByte(&data, 0x00);
appendByte(&data, 0x00);
appendByte(&data, 0x00);
data.clear();
for (int i = 0; i < RegisterCount; ++i)
appendInt(&data, m_inferior.registers[i], BigEndian);
writeToAdapter(0x80, result.token, data);
......
......@@ -72,8 +72,11 @@ enum CodeMode
enum TargetConstants
{
RegisterCount = 16,
RegisterCount = 17,
RegisterPC = 15, // Program counter
RegisterPSGdb = 25, // gdb's view of the world
RegisterPSTrk = 16, // gdb's view of the world
MemoryChunkSize = 256
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment