debugger: work on trk exit/restart

This commit is contained in:
hjk
2009-09-16 13:43:03 +02:00
parent 33271f0be7
commit daf4c32f32
4 changed files with 57 additions and 14 deletions

View File

@@ -687,6 +687,7 @@ void GdbEngine::readGdbStandardOutput()
void GdbEngine::interruptInferior() void GdbEngine::interruptInferior()
{ {
debugMessage(_("GDBENGINE INTERRUPT INFERIOR: %1").arg(m_gdbAdapter->state()));
qq->notifyInferiorStopRequested(); qq->notifyInferiorStopRequested();
if (m_gdbAdapter->state() == QProcess::NotRunning) { if (m_gdbAdapter->state() == QProcess::NotRunning) {
@@ -1478,6 +1479,7 @@ void GdbEngine::shutdown()
void GdbEngine::detachDebugger() void GdbEngine::detachDebugger()
{ {
postCommand(_("detach")); postCommand(_("detach"));
// FIXME: use postCommand(_("detach"), CB(handleExitHelper)) ?
postCommand(_("-gdb-exit"), CB(handleExit)); postCommand(_("-gdb-exit"), CB(handleExit));
} }
@@ -1500,18 +1502,30 @@ void GdbEngine::exitDebugger()
interruptInferior(); interruptInferior();
} }
if (startMode() == AttachExternal || startMode() == AttachCrashedExternal) if (startMode() == AttachExternal || startMode() == AttachCrashedExternal)
postCommand(_("detach")); postCommand(_("detach"), CB(handleExitHelper));
else else
postCommand(_("kill")); postCommand(_("kill"), CB(handleExitHelper));
postCommand(_("-gdb-exit"), CB(handleExit)); } else {
// 20s can easily happen when loading webkit debug information exitDebugger2();
if (!m_gdbAdapter->waitForFinished(20000)) {
debugMessage(_("FORCING TERMINATION: %1")
.arg(m_gdbAdapter->state()));
m_gdbAdapter->terminate();
m_gdbAdapter->waitForFinished(20000);
}
} }
}
void GdbEngine::handleExitHelper(const GdbResultRecord &, const QVariant &)
{
exitDebugger2();
}
void GdbEngine::exitDebugger2()
{
postCommand(_("-gdb-exit"), CB(handleExit));
// 20s can easily happen when loading webkit debug information
if (!m_gdbAdapter->waitForFinished(20000)) {
debugMessage(_("FORCING TERMINATION: %1")
.arg(m_gdbAdapter->state()));
m_gdbAdapter->terminate();
m_gdbAdapter->waitForFinished(20000);
}
if (m_gdbAdapter->state() != QProcess::NotRunning) { if (m_gdbAdapter->state() != QProcess::NotRunning) {
debugMessage(_("PROBLEM STOPPING DEBUGGER: STATE %1") debugMessage(_("PROBLEM STOPPING DEBUGGER: STATE %1")
.arg(m_gdbAdapter->state())); .arg(m_gdbAdapter->state()));

View File

@@ -147,6 +147,7 @@ private:
void startDebugger(const QSharedPointer<DebuggerStartParameters> &sp); void startDebugger(const QSharedPointer<DebuggerStartParameters> &sp);
Q_SLOT void startDebugger2(); Q_SLOT void startDebugger2();
void exitDebugger(); void exitDebugger();
void exitDebugger2();
void detachDebugger(); void detachDebugger();
void continueInferior(); void continueInferior();
@@ -284,6 +285,7 @@ private:
void handleQuerySources(const GdbResultRecord &response, const QVariant &); void handleQuerySources(const GdbResultRecord &response, const QVariant &);
void handleTargetCore(const GdbResultRecord &, const QVariant &); void handleTargetCore(const GdbResultRecord &, const QVariant &);
void handleExit(const GdbResultRecord &, const QVariant &); void handleExit(const GdbResultRecord &, const QVariant &);
void handleExitHelper(const GdbResultRecord &, const QVariant &);
void handleSetTargetAsync(const GdbResultRecord &, const QVariant &); void handleSetTargetAsync(const GdbResultRecord &, const QVariant &);
void handleTargetRemote(const GdbResultRecord &, const QVariant &); void handleTargetRemote(const GdbResultRecord &, const QVariant &);
void handleWatchPoint(const GdbResultRecord &, const QVariant &); void handleWatchPoint(const GdbResultRecord &, const QVariant &);

View File

@@ -488,13 +488,12 @@ void TrkGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
else if (cmd == "k" || cmd.startsWith("vKill")) { else if (cmd == "k" || cmd.startsWith("vKill")) {
// Kill inferior process // Kill inferior process
logMessage(msgGdbPacket(QLatin1String("kill"))); logMessage(msgGdbPacket(QLatin1String("kill")));
sendGdbServerAck();
QByteArray ba; QByteArray ba;
appendByte(&ba, 0); // ? appendByte(&ba, 0); // ?
appendByte(&ba, 0); // Sub-command: Delete Process appendByte(&ba, 0); // Sub-command: Delete Process
appendInt(&ba, m_session.pid); appendInt(&ba, m_session.pid);
sendTrkMessage(0x41, TrkCallback(), ba, "Delete process"); // Delete Item sendTrkMessage(0x41, TrkCB(handleDeleteProcess),
sendGdbServerMessageAfterTrkResponse("", "process killed"); ba, "Delete process"); // Delete Item
} }
else if (cmd.startsWith("m")) { else if (cmd.startsWith("m")) {
@@ -935,6 +934,22 @@ void TrkGdbAdapter::handleCreateProcess(const TrkResult &result)
startGdb(); startGdb();
} }
void TrkGdbAdapter::handleDeleteProcess(const TrkResult &result)
{
Q_UNUSED(result);
logMessage("TRK Process killed");
//sendTrkMessage(0x01, TrkCB(handleDeleteProcess2)); // Ping
sendTrkMessage(0x02, TrkCB(handleDeleteProcess2)); // Disconnect
}
void TrkGdbAdapter::handleDeleteProcess2(const TrkResult &result)
{
Q_UNUSED(result);
logMessage("process killed");
sendGdbServerAck();
sendGdbServerMessage("", "process killed");
}
void TrkGdbAdapter::handleReadRegisters(const TrkResult &result) void TrkGdbAdapter::handleReadRegisters(const TrkResult &result)
{ {
logMessage(" RESULT: " + result.toString()); logMessage(" RESULT: " + result.toString());
@@ -1269,7 +1284,7 @@ void TrkGdbAdapter::handleGdbStateChanged(QProcess::ProcessState newState)
void TrkGdbAdapter::run() void TrkGdbAdapter::run()
{ {
emit output("### Starting TrkGdbAdapter"); emit output("### Starting TrkGdbAdapter");
m_rfcommProc.start("rfcomm listen " + m_rfcommDevice + " 1"); m_rfcommProc.start("rfcomm -r listen " + m_rfcommDevice + " 1");
m_rfcommProc.waitForStarted(); m_rfcommProc.waitForStarted();
if (m_rfcommProc.state() != QProcess::Running) { if (m_rfcommProc.state() != QProcess::Running) {
@@ -1369,16 +1384,26 @@ void TrkGdbAdapter::start(const QString &program, const QStringList &args,
void TrkGdbAdapter::kill() void TrkGdbAdapter::kill()
{ {
m_rfcommProc.kill();
m_gdbProc.kill(); m_gdbProc.kill();
} }
void TrkGdbAdapter::terminate() void TrkGdbAdapter::terminate()
{ {
m_rfcommProc.terminate();
m_gdbProc.terminate(); m_gdbProc.terminate();
} }
bool TrkGdbAdapter::waitForFinished(int msecs) bool TrkGdbAdapter::waitForFinished(int msecs)
{ {
QByteArray ba;
ba.append(0x03);
m_rfcommProc.write(ba);
m_rfcommProc.terminate();
m_rfcommProc.waitForFinished();
QProcess proc;
proc.start("rfcomm release " + m_rfcommDevice.toLatin1());
proc.waitForFinished();
return m_gdbProc.waitForFinished(msecs); return m_gdbProc.waitForFinished(msecs);
} }

View File

@@ -156,6 +156,8 @@ public:
void handleSupportMask(const TrkResult &result); void handleSupportMask(const TrkResult &result);
void handleTrkVersions(const TrkResult &result); void handleTrkVersions(const TrkResult &result);
void handleDisconnect(const TrkResult &result); void handleDisconnect(const TrkResult &result);
void handleDeleteProcess(const TrkResult &result);
void handleDeleteProcess2(const TrkResult &result);
void handleAndReportCreateProcess(const TrkResult &result); void handleAndReportCreateProcess(const TrkResult &result);
void handleAndReportReadRegistersAfterStop(const TrkResult &result); void handleAndReportReadRegistersAfterStop(const TrkResult &result);