From 7d6180f906ee50c10b27db722f55974f0f3a0ef4 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Thu, 21 Jan 2010 16:27:01 +0100 Subject: Merge from upstream The patch accepted upstream has the signal and slot renamed, so there is a corresponding change to main.cpp commit 53c672fb9853fef5a00285213084f02a4253e5f3 Author: Friedemann Kleint Date: Thu Jan 21 15:45:40 2010 +0100 trk: Handle TrkNotifyStopped in launcher. Add signal and static utility functions to parse message. Reviewed-by: Robert Loehning Initial-patch-by: Shane Kearns Task-number: QTBUG-7444 --- tools/runonphone/main.cpp | 4 +-- tools/runonphone/trk/launcher.cpp | 54 +++++++++++++++++++++++++-------------- tools/runonphone/trk/launcher.h | 10 ++++++-- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/tools/runonphone/main.cpp b/tools/runonphone/main.cpp index 77bd809..a77e713 100644 --- a/tools/runonphone/main.cpp +++ b/tools/runonphone/main.cpp @@ -203,8 +203,8 @@ int main(int argc, char *argv[]) QObject::connect(launcher.data(), SIGNAL(applicationOutputReceived(const QString &)), &handler, SLOT(applicationOutputReceived(const QString &))); QObject::connect(launcher.data(), SIGNAL(copyProgress(int)), &handler, SLOT(copyProgress(int))); QObject::connect(launcher.data(), SIGNAL(stateChanged(int)), &handler, SLOT(stateChanged(int))); - QObject::connect(launcher.data(), SIGNAL(stopped(uint,uint,uint,QString)), &handler, SLOT(stopped(uint,uint,uint,QString))); - QObject::connect(&handler, SIGNAL(resume(uint,uint)), launcher.data(), SLOT(resume(uint,uint))); + QObject::connect(launcher.data(), SIGNAL(processStopped(uint,uint,uint,QString)), &handler, SLOT(stopped(uint,uint,uint,QString))); + QObject::connect(&handler, SIGNAL(resume(uint,uint)), launcher.data(), SLOT(resumeProcess(uint,uint))); QObject::connect(&handler, SIGNAL(terminate()), launcher.data(), SLOT(terminate())); QObject::connect(launcher.data(), SIGNAL(finished()), &handler, SLOT(finished())); diff --git a/tools/runonphone/trk/launcher.cpp b/tools/runonphone/trk/launcher.cpp index 1655aaf..1796fc5 100644 --- a/tools/runonphone/trk/launcher.cpp +++ b/tools/runonphone/trk/launcher.cpp @@ -298,6 +298,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("") : 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: "; @@ -317,25 +345,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 QString reason; - if (result.data.size() >= 14) { - uint pc = extractInt(result.data.mid(0,4).constData()); - uint pid = extractInt(result.data.mid(4,4).constData()); - uint tid = extractInt(result.data.mid(8,4).constData()); - ushort len = extractShort(result.data.mid(12,2).constData()); - if(len > 0) - reason = result.data.mid(14, len); - emit(stopped(pc, pid, tid, reason)); - } else { - emit(stopped(0, 0, 0, reason)); - } - //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); + 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; } @@ -714,7 +730,7 @@ void Launcher::startInferiorIfNeeded() startProcessMessage(d->m_fileName, d->m_commandLineArgs)); // Create Item } -void Launcher::resume(uint pid, uint tid) +void Launcher::resumeProcess(uint pid, uint tid) { QByteArray ba; appendInt(&ba, pid, BigEndian); diff --git a/tools/runonphone/trk/launcher.h b/tools/runonphone/trk/launcher.h index 472f234..8dc6ebe 100644 --- a/tools/runonphone/trk/launcher.h +++ b/tools/runonphone/trk/launcher.h @@ -111,6 +111,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(); @@ -128,11 +134,11 @@ signals: void applicationOutputReceived(const QString &output); void copyProgress(int percent); void stateChanged(int); - void stopped(uint pc, uint pid, uint tid, const QString& reason); + void processStopped(uint pc, uint pid, uint tid, const QString& reason); public slots: void terminate(); - void resume(uint pid, uint tid); + void resumeProcess(uint pid, uint tid); private slots: void handleResult(const trk::TrkResult &data); -- cgit v0.12