From 53c672fb9853fef5a00285213084f02a4253e5f3 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint <Friedemann.Kleint@nokia.com> Date: Thu, 21 Jan 2010 15:45:40 +0100 Subject: [PATCH] trk: Handle TrkNotifyStopped in launcher. Add signal and static utility functions to parse message. Reviewed-by: Robert Loehning <robert.loehning@nokia.com> Initial-patch-by: Shane Kearns <shane.kearns@sosco.com> --- src/shared/trk/launcher.cpp | 50 +++++++++++++++++++++++++++++++------ src/shared/trk/launcher.h | 8 ++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/shared/trk/launcher.cpp b/src/shared/trk/launcher.cpp index d8f9e0d2c88..99cc5b415a6 100644 --- a/src/shared/trk/launcher.cpp +++ b/src/shared/trk/launcher.cpp @@ -286,6 +286,34 @@ void Launcher::handleRemoteProcessKilled(const TrkResult &result) disconnectTrk(); } +QString Launcher::msgStopped(uint pid, uint tid, uint address, const QString &why) +{ + return QString::fromLatin1("Process %1, thread %2 stopped at 0x%3: %4"). + arg(pid).arg(tid).arg(address, 0, 16). + arg(why.isEmpty() ? QString::fromLatin1("<Unknown reason>") : why); +} + +bool Launcher::parseNotifyStopped(const QByteArray &dataBA, + uint *pid, uint *tid, uint *address, + QString *why /* = 0 */) +{ + if (why) + why->clear(); + *address = *pid = *tid = 0; + if (dataBA.size() < 12) + return false; + const char *data = dataBA.data(); + *address = extractInt(data); + *pid = extractInt(data + 4); + *tid = extractInt(data + 8); + if (why && dataBA.size() >= 14) { + const unsigned short len = extractShort(data + 12); + if (len > 0) + *why = QString::fromLatin1(data + 14, len); + } + return true; +} + void Launcher::handleResult(const TrkResult &result) { QByteArray prefix = "READ BUF: "; @@ -305,13 +333,13 @@ void Launcher::handleResult(const TrkResult &result) break; } case TrkNotifyStopped: { // Notified Stopped - logMessage(prefix + "NOTE: STOPPED " + str); - // 90 01 78 6a 40 40 00 00 07 23 00 00 07 24 00 00 - //const char *data = result.data.data(); -// uint addr = extractInt(data); //code address: 4 bytes; code base address for the library -// uint pid = extractInt(data + 4); // ProcessID: 4 bytes; -// uint tid = extractInt(data + 8); // ThreadID: 4 bytes - //logMessage(prefix << " ADDR: " << addr << " PID: " << pid << " TID: " << tid); + QString reason; + uint pc; + uint pid; + uint tid; + parseNotifyStopped(result.data, &pid, &tid, &pc, &reason); + logMessage(prefix + msgStopped(pid, tid, pc, reason)); + emit(processStopped(pc, pid, tid, reason)); d->m_device->sendTrkAck(result.token); break; } @@ -689,4 +717,12 @@ void Launcher::startInferiorIfNeeded() d->m_device->sendTrkMessage(TrkCreateItem, TrkCallback(this, &Launcher::handleCreateProcess), startProcessMessage(d->m_fileName, d->m_commandLineArgs)); // Create Item } + +void Launcher::resumeProcess(uint pid, uint tid) +{ + QByteArray ba; + appendInt(&ba, pid, BigEndian); + appendInt(&ba, tid, BigEndian); + d->m_device->sendTrkMessage(TrkContinue, TrkCallback(), ba, "CONTINUE"); +} } // namespace trk diff --git a/src/shared/trk/launcher.h b/src/shared/trk/launcher.h index 67e94977ede..01ce6f66065 100644 --- a/src/shared/trk/launcher.h +++ b/src/shared/trk/launcher.h @@ -98,6 +98,12 @@ public: static QByteArray startProcessMessage(const QString &executable, const QStringList &arguments); + // Parse a TrkNotifyStopped message + static bool parseNotifyStopped(const QByteArray &a, + uint *pid, uint *tid, uint *address, + QString *why = 0); + // Helper message + static QString msgStopped(uint pid, uint tid, uint address, const QString &why); signals: void copyingStarted(); @@ -115,9 +121,11 @@ signals: void applicationOutputReceived(const QString &output); void copyProgress(int percent); void stateChanged(int); + void processStopped(uint pc, uint pid, uint tid, const QString& reason); public slots: void terminate(); + void resumeProcess(uint pid, uint tid); private slots: void handleResult(const trk::TrkResult &data); -- GitLab