Commit 432a98a0 authored by hjk's avatar hjk
Browse files

debugger: progress for the trk adapter

parent 5042515c
......@@ -163,7 +163,7 @@ private:
// Debuggee state
Session m_session; // global-ish data (process id, target information)
SnapShot m_snapshot; // local-ish data (memory and registers)
Snapshot m_snapshot; // local-ish data (memory and registers)
};
Adapter::Adapter()
......@@ -453,7 +453,7 @@ void Adapter::handleGdbResponse(const QByteArray &response)
appendByte(&ba, 0); // first register
// FIXME: off by one?
appendByte(&ba, registerCount - 1); // last register
appendByte(&ba, RegisterCount - 1); // last register
appendInt(&ba, m_session.pid);
appendInt(&ba, m_session.tid);
......@@ -537,7 +537,7 @@ void Adapter::handleGdbResponse(const QByteArray &response)
#endif
bool ok = false;
uint registerNumber = response.mid(1).toInt(&ok, 16);
if (registerNumber < registerCount) {
if (registerNumber < RegisterCount) {
QByteArray ba;
appendInt(&ba, m_snapshot.registers[registerNumber]);
sendGdbMessage(ba.toHex(), "read single known register");
......@@ -565,8 +565,9 @@ void Adapter::handleGdbResponse(const QByteArray &response)
sendGdbMessageAfterSync("QC@TID@");
}
else if (response == "qSupported") {
else if (response.startsWith("qSupported")) {
//$qSupported#37
//$qSupported:multiprocess+#c6
//logMessage("Handling 'qSupported'");
sendGdbAckMessage();
if (0)
......@@ -620,8 +621,8 @@ void Adapter::handleGdbResponse(const QByteArray &response)
sendGdbAckMessage();
QByteArray ba;
appendByte(&ba, 0); // options
appendInt(&ba, m_snapshot.registers[14]); // start address
appendInt(&ba, m_snapshot.registers[14] + 4); // end address
appendInt(&ba, m_snapshot.registers[RegisterPC]); // start address
appendInt(&ba, m_snapshot.registers[RegisterPC] + 4); // end address
appendInt(&ba, m_session.pid);
appendInt(&ba, m_session.tid);
sendTrkMessage(0x19, 0, ba, "Step range");
......@@ -1057,7 +1058,15 @@ void Adapter::handleAndReportReadRegisters(const TrkResult &result)
//logMessage(" RESULT: " + result.toString());
// [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...]
QByteArray ba = result.data.toHex();
const char *data = result.data.data();
for (int i = 0; i < RegisterCount; ++i)
m_snapshot.registers[i] = extractInt(data + 4 * i);
//QByteArray ba = result.data.toHex();
QByteArray ba;
for (int i = 0; i < 16; ++i)
ba += hexNumber(m_snapshot.registers[i], 8);
sendGdbMessage(ba, "register contents");
}
......@@ -1080,14 +1089,14 @@ void Adapter::reportReadMemory(const TrkResult &result)
uint len = uint(cookie);
QByteArray ba;
uint blockaddr = (addr / memoryChunkSize) * memoryChunkSize;
for (; blockaddr < addr + len; blockaddr += memoryChunkSize) {
uint blockaddr = (addr / MemoryChunkSize) * MemoryChunkSize;
for (; blockaddr < addr + len; blockaddr += MemoryChunkSize) {
QByteArray blockdata = m_snapshot.memory[blockaddr];
Q_ASSERT(!blockdata.isEmpty());
ba.append(blockdata);
}
ba = ba.mid(addr % memoryChunkSize, len);
ba = ba.mid(addr % MemoryChunkSize, len);
// qDebug() << "REPORTING MEMORY " << ba.size()
// << " ADDR: " << hexNumber(blockaddr) << " LEN: " << len
// << " BYTES: " << quoteUnprintableLatin1(ba);
......@@ -1252,14 +1261,14 @@ void Adapter::readMemory(uint addr, uint len)
// We try to get medium-sized chunks of data from the device
QList <uint> blocksToFetch;
uint blockaddr = (addr / memoryChunkSize) * memoryChunkSize;
for (; blockaddr < addr + len; blockaddr += memoryChunkSize) {
uint blockaddr = (addr / MemoryChunkSize) * MemoryChunkSize;
for (; blockaddr < addr + len; blockaddr += MemoryChunkSize) {
QByteArray blockdata = m_snapshot.memory[blockaddr];
if (blockdata.isEmpty()) {
// fetch it
QByteArray ba;
appendByte(&ba, 0x08); // Options, FIXME: why?
appendShort(&ba, memoryChunkSize);
appendShort(&ba, MemoryChunkSize);
appendInt(&ba, blockaddr);
appendInt(&ba, m_session.pid);
appendInt(&ba, m_session.tid);
......
......@@ -67,7 +67,7 @@ struct Inferior
uint codeseg;
uint dataseg;
uint registers[16];
uint registers[RegisterCount];
};
Inferior::Inferior()
......@@ -78,22 +78,23 @@ Inferior::Inferior()
codeseg = 0x786A4000;
dataseg = 0x00400000;
registers[0] = 0xC92D7FBC;
registers[1] = 0x00000000;
registers[2] = 0x00600000;
registers[3] = 0x00000000;
registers[4] = 0x786A7970;
registers[5] = 0x00000000;
registers[0] = 0x00000000;
registers[1] = 0xC92D7FBC;
registers[2] = 0x00000000;
registers[3] = 0x00600000;
registers[4] = 0x00000000;
registers[5] = 0x786A7970;
registers[6] = 0x00000000;
registers[7] = 0x00000012;
registers[8] = 0x00000040;
registers[9] = 0xC82AF210;
registers[10] = 0x00000000;
registers[11] = 0xC8000548;
registers[12] = 0x00403ED0;
registers[13] = 0x786A6BD8;
registers[14] = 0x786A4CC8;
registers[15] = 0x68000010;
registers[7] = 0x00000000;
registers[8] = 0x00000012;
registers[9] = 0x00000040;
registers[10] = 0xC82AF210;
registers[11] = 0x00000000;
registers[12] = 0xC8000548;
registers[13] = 0x00403ED0;
registers[14] = 0x786A6BD8;
registers[15] = 0x786A4CC8;
//registers[25] = 0x68000010;
}
class TrkServer : public QObject
......@@ -240,7 +241,7 @@ void TrkServer::handleAdapterMessage(const TrkResult &result)
appendByte(&data, 0x00);
appendByte(&data, 0x00);
appendByte(&data, 0x00);
for (int i = 0; i < 16; ++i)
for (int i = 0; i < RegisterCount; ++i)
appendInt(&data, m_inferior.registers[i], BigEndian);
writeToAdapter(0x80, result.token, data);
break;
......@@ -267,16 +268,16 @@ void TrkServer::handleAdapterMessage(const TrkResult &result)
uint endaddr = extractInt(p + 5);
uint pid = extractInt(p + 9);
//uint tid = extractInt(p + 13);
if (startaddr != m_inferior.registers[14])
if (startaddr != m_inferior.registers[RegisterPC])
logMessage("addr mismatch:" + hexNumber(startaddr) + " " +
hexNumber(m_inferior.registers[14]));
hexNumber(m_inferior.registers[RegisterPC]));
if (pid != m_inferior.pid)
logMessage("pid mismatch:" + hexNumber(pid) + " " +
hexNumber(m_inferior.pid));
writeToAdapter(0x80, result.token, data);
// Fake "step"
m_inferior.registers[14] = endaddr;
m_inferior.registers[RegisterPC] = endaddr;
if (1) { // Fake "Stop"
QByteArray note;
......
......@@ -35,9 +35,12 @@
namespace trk {
QByteArray hexNumber(uint n)
QByteArray hexNumber(uint n, int digits)
{
return QByteArray::number(n, 16);
QByteArray ba = QByteArray::number(n, 16);
if (digits == 0 || ba.size() == digits)
return ba;
return QByteArray(digits - ba.size(), '0') + ba;
}
QString TrkResult::toString() const
......
......@@ -72,8 +72,9 @@ enum CodeMode
enum TargetConstants
{
registerCount = 17,
memoryChunkSize = 256
RegisterCount = 16,
RegisterPC = 15, // Program counter
MemoryChunkSize = 256
};
struct Session
......@@ -112,9 +113,9 @@ struct Session
uint currentThread;
};
struct SnapShot
struct Snapshot
{
uint registers[registerCount];
uint registers[RegisterCount];
typedef QHash<uint, QByteArray> Memory;
Memory memory;
};
......@@ -147,7 +148,7 @@ struct TrkResult
QByteArray frameMessage(byte command, byte token, const QByteArray &data);
TrkResult extractResult(QByteArray *buffer);
QByteArray errorMessage(byte code);
QByteArray hexNumber(uint n);
QByteArray hexNumber(uint n, int digits = 0);
} // namespace trk
......
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