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) ...@@ -537,7 +537,11 @@ void Adapter::handleGdbResponse(const QByteArray &response)
#endif #endif
bool ok = false; bool ok = false;
uint registerNumber = response.mid(1).toInt(&ok, 16); 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; QByteArray ba;
appendInt(&ba, m_snapshot.registers[registerNumber]); appendInt(&ba, m_snapshot.registers[registerNumber]);
sendGdbMessage(ba.toHex(), "read single known register"); sendGdbMessage(ba.toHex(), "read single known register");
...@@ -1059,8 +1063,10 @@ void Adapter::handleAndReportReadRegisters(const TrkResult &result) ...@@ -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 // [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...] // 60 00 00 00 00 00 00 78 67 79 70 00 00 00 00 00...]
const char *data = result.data.data(); 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); m_snapshot.registers[i] = extractInt(data + 4 * i);
//qDebug() << i << hexNumber(m_snapshot.registers[i], 8);
}
//QByteArray ba = result.data.toHex(); //QByteArray ba = result.data.toHex();
QByteArray ba; QByteArray ba;
......
...@@ -94,7 +94,7 @@ Inferior::Inferior() ...@@ -94,7 +94,7 @@ Inferior::Inferior()
registers[13] = 0x00403ED0; registers[13] = 0x00403ED0;
registers[14] = 0x786A6BD8; registers[14] = 0x786A6BD8;
registers[15] = 0x786A4CC8; registers[15] = 0x786A4CC8;
//registers[25] = 0x68000010; registers[16] = 0x68000010; // that's reg 25 on chip?
} }
class TrkServer : public QObject class TrkServer : public QObject
...@@ -238,9 +238,7 @@ void TrkServer::handleAdapterMessage(const TrkResult &result) ...@@ -238,9 +238,7 @@ void TrkServer::handleAdapterMessage(const TrkResult &result)
break; break;
} }
case 0x12: { // Read Registers case 0x12: { // Read Registers
appendByte(&data, 0x00); data.clear();
appendByte(&data, 0x00);
appendByte(&data, 0x00);
for (int i = 0; i < RegisterCount; ++i) for (int i = 0; i < RegisterCount; ++i)
appendInt(&data, m_inferior.registers[i], BigEndian); appendInt(&data, m_inferior.registers[i], BigEndian);
writeToAdapter(0x80, result.token, data); writeToAdapter(0x80, result.token, data);
......
...@@ -72,8 +72,11 @@ enum CodeMode ...@@ -72,8 +72,11 @@ enum CodeMode
enum TargetConstants enum TargetConstants
{ {
RegisterCount = 16, RegisterCount = 17,
RegisterPC = 15, // Program counter RegisterPC = 15, // Program counter
RegisterPSGdb = 25, // gdb's view of the world
RegisterPSTrk = 16, // gdb's view of the world
MemoryChunkSize = 256 MemoryChunkSize = 256
}; };
......
Supports Markdown
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