Commit bf501dca authored by hjk's avatar hjk
Browse files

debugger: implement writing to registers using trk

parent 724cc50e
......@@ -200,7 +200,7 @@ QByteArray TrkGdbAdapter::trkContinueMessage()
return ba;
}
QByteArray TrkGdbAdapter::trkReadRegisterMessage()
QByteArray TrkGdbAdapter::trkReadRegistersMessage()
{
QByteArray ba;
appendByte(&ba, 0); // Register set, only 0 supported
......@@ -211,6 +211,18 @@ QByteArray TrkGdbAdapter::trkReadRegisterMessage()
return ba;
}
QByteArray TrkGdbAdapter::trkWriteRegisterMessage(byte reg, uint value)
{
QByteArray ba;
appendByte(&ba, 0); // ?
appendShort(&ba, reg);
appendShort(&ba, reg);
appendInt(&ba, m_session.pid);
appendInt(&ba, m_session.tid);
appendInt(&ba, value);
return ba;
}
QByteArray TrkGdbAdapter::trkReadMemoryMessage(uint addr, uint len)
{
QByteArray ba;
......@@ -575,6 +587,7 @@ void TrkGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
sendGdbServerMessage("E20", "Error " + cmd);
}
}
else if (cmd.startsWith("p")) {
logMessage(msgGdbPacket(QLatin1String("read register")));
// 0xf == current instruction pointer?
......@@ -600,6 +613,21 @@ void TrkGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
}
}
else if (cmd.startsWith("P")) {
logMessage(msgGdbPacket(QLatin1String("write register")));
// $Pe=70f96678#d3
sendGdbServerAck();
int pos = cmd.indexOf('=');
QByteArray regName = cmd.mid(1, pos - 1);
QByteArray valueName = cmd.mid(pos + 1);
bool ok = false;
const uint registerNumber = regName.toInt(&ok, 16);
const uint value = swapEndian(valueName.toInt(&ok, 16));
QByteArray ba = trkWriteRegisterMessage(registerNumber, value);
sendTrkMessage(0x13, TrkCB(handleWriteRegister), ba, "Write register");
// Note that App TRK refuses to write registers 13 and 14
}
else if (cmd == "qAttached") {
//$qAttached#8f
// 1: attached to an existing process
......@@ -862,7 +890,7 @@ void TrkGdbAdapter::handleTrkResult(const TrkResult &result)
//sendGdbServerMessage("S05", "Target stopped");
sendTrkMessage(0x12,
TrkCB(handleAndReportReadRegistersAfterStop),
trkReadRegisterMessage());
trkReadRegistersMessage());
break;
}
case 0x91: { // Notify Exception (obsolete)
......@@ -1021,6 +1049,17 @@ void TrkGdbAdapter::handleReadRegisters(const TrkResult &result)
m_snapshot.registers[i] = extractInt(data + 4 * i);
}
void TrkGdbAdapter::handleWriteRegister(const TrkResult &result)
{
logMessage(" RESULT: " + result.toString() + result.cookie.toString());
if (result.errorCode()) {
logMessage("ERROR: " + result.errorString());
sendGdbServerMessage("E01");
return;
}
sendGdbServerMessage("OK");
}
void TrkGdbAdapter::reportRegisters()
{
QByteArray ba;
......
......@@ -156,7 +156,8 @@ public:
void reportRegisters();
QByteArray memoryReadLogMessage(uint addr, uint len, const QByteArray &ba) const;
QByteArray trkContinueMessage();
QByteArray trkReadRegisterMessage();
QByteArray trkReadRegistersMessage();
QByteArray trkWriteRegisterMessage(byte reg, uint value);
QByteArray trkReadMemoryMessage(uint addr, uint len);
QByteArray trkBreakpointMessage(uint addr, uint len, bool armMode = true);
QByteArray trkStepRangeMessage(byte option);
......@@ -169,6 +170,7 @@ public:
void handleStepOver2(const TrkResult &result);
void handleReadRegisters(const TrkResult &result);
void reportReadMemoryBuffered(const TrkResult &result);
void handleWriteRegister(const TrkResult &result);
void reportToGdb(const TrkResult &result);
void readMemory(uint addr, uint len);
......
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