Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
19 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/runonphone/symbianutils/bluetoothlistener.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/tools/runonphone/symbianutils/bluetoothlistener.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/tools/runonphone/symbianutils/bluetoothlistener_gui.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/tools/runonphone/symbianutils/bluetoothlistener_gui.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/tools/runonphone/symbianutils/callback.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/tools/runonphone/symbianutils/communicationstarter.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/tools/runonphone/symbianutils/communicationstarter.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/tools/runonphone/symbianutils/launcher.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4545#include "trkdevice.h"
    4646#include "bluetoothlistener.h"
     47#include "symbiandevicemanager.h"
    4748
    4849#include <QtCore/QTimer>
     
    5455#include <QtCore/QScopedPointer>
    5556
     57#include <cstdio>
     58
    5659namespace trk {
     60
     61struct CrashReportState {
     62    CrashReportState();
     63    void clear();
     64
     65    typedef uint Thread;
     66    typedef QList<Thread> Threads;
     67    Threads threads;
     68
     69    QList<uint> registers;
     70    QByteArray stack;
     71    uint sp;
     72    uint fetchingStackPID;
     73    uint fetchingStackTID;
     74};
     75
     76CrashReportState::CrashReportState()
     77{
     78    clear();
     79}
     80
     81void CrashReportState::clear()
     82{
     83    threads.clear();
     84    stack.clear();
     85    sp = fetchingStackPID = fetchingStackTID = 0;
     86}
    5787
    5888struct LauncherPrivate {
     
    6292        uint copyFileHandle;
    6393        QScopedPointer<QByteArray> data;
    64         int position;
     94        qint64 position;
     95        QScopedPointer<QFile> localFile;
    6596    };
    6697
     
    76107
    77108    CopyState m_copyState;
     109    CopyState m_downloadState;
    78110    QString m_fileName;
    79111    QStringList m_commandLineArgs;
     
    82114    Launcher::Actions m_startupActions;
    83115    bool m_closeDevice;
     116    CrashReportState m_crashReportState;
    84117};
    85118
     
    101134{
    102135    d->m_startupActions = startupActions;
    103     connect(d->m_device.data(), SIGNAL(messageReceived(trk::TrkResult)), this, SLOT(handleResult(trk::TrkResult)));   
    104     connect(this, SIGNAL(finished()), d->m_device.data(), SLOT(close()));
     136    connect(d->m_device.data(), SIGNAL(messageReceived(trk::TrkResult)), this, SLOT(handleResult(trk::TrkResult)));
    105137}
    106138
    107139Launcher::~Launcher()
    108140{
     141    // Destroyed before protocol was through: Close
     142    if (d->m_closeDevice && d->m_device->isOpen())
     143        d->m_device->close();
     144    emit destroyed(d->m_device->port());
    109145    logMessage("Shutting down.\n");
    110146    delete d;
     
    155191}
    156192
     193void Launcher::setDownloadFileName(const QString &srcName, const QString &dstName)
     194{
     195    d->m_downloadState.sourceFileName = srcName;
     196    d->m_downloadState.destinationFileName = dstName;
     197}
     198
    157199void Launcher::setInstallFileName(const QString &name)
    158200{
     
    189231{
    190232    errorMessage->clear();
     233    d->m_crashReportState.clear();
    191234    if (d->m_verbose) {
    192         const QString msg = QString::fromLatin1("Port=%1 Executable=%2 Arguments=%3 Package=%4 Remote Package=%5 Install file=%6")
    193                             .arg(trkServerName(), d->m_fileName,
    194                                  d->m_commandLineArgs.join(QString(QLatin1Char(' '))),
    195                                  d->m_copyState.sourceFileName, d->m_copyState.destinationFileName, d->m_installFileName);
     235        QString msg;
     236        QTextStream str(&msg);
     237        str.setIntegerBase(16);
     238        str << "Actions=0x" << d->m_startupActions;
     239        str.setIntegerBase(10);
     240        str << " Port=" << trkServerName();
     241        if (!d->m_fileName.isEmpty())
     242            str << " Executable=" << d->m_fileName;
     243        if (!d->m_commandLineArgs.isEmpty())
     244            str << " Arguments= " << d->m_commandLineArgs.join(QString(QLatin1Char(' ')));
     245        if (!d->m_copyState.sourceFileName.isEmpty())
     246            str << " Package/Source=" << d->m_copyState.sourceFileName;
     247        if (!d->m_copyState.destinationFileName.isEmpty())
     248            str << " Remote Package/Destination=" << d->m_copyState.destinationFileName;
     249        if (!d->m_downloadState.sourceFileName.isEmpty())
     250            str << " Source=" << d->m_downloadState.sourceFileName;
     251        if (!d->m_downloadState.destinationFileName.isEmpty())
     252            str << " Destination=" << d->m_downloadState.destinationFileName;
     253        if (!d->m_installFileName.isEmpty())
     254            str << " Install file=" << d->m_installFileName;
    196255        logMessage(msg);
    197256    }
     
    215274    if (!d->m_device->isOpen() && !d->m_device->open(errorMessage))
    216275        return false;
    217     if (d->m_closeDevice) {
    218         connect(this, SIGNAL(finished()), d->m_device.data(), SLOT(close()));
    219     } else {
    220         disconnect(this, SIGNAL(finished()), d->m_device.data(), 0);
    221     }
    222276    setState(Connecting);
    223277    // Set up the temporary 'waiting' state if we do not get immediate connection
     
    253307    else if (d->m_startupActions & ActionRun)
    254308        startInferiorIfNeeded();
     309    else if (d->m_startupActions & ActionDownload)
     310        copyFileFromRemote();
    255311}
    256312
     
    265321    if (d->m_verbose)
    266322        qDebug() << "LAUNCHER: " << qPrintable(msg);
     323}
     324
     325void Launcher::handleFinished()
     326{
     327    if (d->m_closeDevice)
     328        d->m_device->close();
     329    emit finished();
    267330}
    268331
     
    288351    case WaitingForTrk:
    289352        setState(Disconnected);
    290         emit finished();
     353        handleFinished();
    291354        break;
    292355    }
     
    332395    QByteArray str = result.toString().toUtf8();
    333396    if (result.isDebugOutput) { // handle application output
    334         logMessage("APPLICATION OUTPUT: " + result.data);
    335         emit applicationOutputReceived(result.data);
     397        QString msg;
     398        if (result.multiplex == MuxTextTrace) {
     399            if (result.data.length() > 8) {
     400            quint64 timestamp = extractInt64(result.data) & 0x0FFFFFFFFFFFFFFFULL;
     401            quint64 secs = timestamp / 1000000000;
     402            quint64 ns = timestamp % 1000000000;
     403            msg = QString("[%1.%2] %3").arg(secs).arg(ns).arg(QString(result.data.mid(8)));
     404            logMessage("TEXT TRACE: " + msg);
     405            }
     406        } else {
     407            logMessage("APPLICATION OUTPUT: " + stringFromArray(result.data));
     408            msg = result.data;
     409        }
     410        msg.replace("\r\n", "\n");
     411        if(!msg.endsWith('\n')) msg.append('\n');
     412        emit applicationOutputReceived(msg);
    336413        return;
    337414    }
     
    369446        // target->host OS notification
    370447        case TrkNotifyCreated: { // Notify Created
    371             /*
    372             const char *data = result.data.data();
    373             byte error = result.data.at(0);
    374             byte type = result.data.at(1); // type: 1 byte; for dll item, this value is 2.
    375             uint pid = extractInt(data + 2); //  ProcessID: 4 bytes;
    376             uint tid = extractInt(data + 6); //threadID: 4 bytes
    377             uint codeseg = extractInt(data + 10); //code address: 4 bytes; code base address for the library
    378             uint dataseg = extractInt(data + 14); //data address: 4 bytes; data base address for the library
    379             uint len = extractShort(data + 18); //length: 2 bytes; length of the library name string to follow
    380             QByteArray name = result.data.mid(20, len); // name: library name
    381 
    382             logMessage(prefix + "NOTE: LIBRARY LOAD: " + str);
    383             logMessage(prefix + "TOKEN: " + result.token);
    384             logMessage(prefix + "ERROR: " + int(error));
    385             logMessage(prefix + "TYPE:  " + int(type));
    386             logMessage(prefix + "PID:   " + pid);
    387             logMessage(prefix + "TID:   " + tid);
    388             logMessage(prefix + "CODE:  " + codeseg);
    389             logMessage(prefix + "DATA:  " + dataseg);
    390             logMessage(prefix + "LEN:   " + len);
    391             logMessage(prefix + "NAME:  " + name);
    392             */
    393448
    394449            if (result.data.size() < 10)
    395450                break;
     451            const char *data = result.data.constData();
     452            const byte error = result.data.at(0);
     453            Q_UNUSED(error)
     454            const byte type = result.data.at(1); // type: 1 byte; for dll item, this value is 2.
     455            const uint tid = extractInt(data + 6); //threadID: 4 bytes
     456            Q_UNUSED(tid)
     457            if (type == kDSOSDLLItem && result.data.size() >=20) {
     458                const Library lib = Library(result);
     459                d->m_session.libraries.push_back(lib);
     460                emit libraryLoaded(lib);
     461            }
    396462            QByteArray ba;
    397463            ba.append(result.data.mid(2, 8));
    398464            d->m_device->sendTrkMessage(TrkContinue, TrkCallback(), ba, "CONTINUE");
    399             //d->m_device->sendTrkAck(result.token)
    400465            break;
    401466        }
    402467        case TrkNotifyDeleted: { // NotifyDeleted
    403468            const ushort itemType = (unsigned char)result.data.at(1);
    404             const ushort len = result.data.size() > 12 ? extractShort(result.data.data() + 10) : ushort(0);
     469            const uint pid = result.data.size() >= 6 ? extractShort(result.data.constData() + 2) : 0;
     470            const uint tid = result.data.size() >= 10 ? extractShort(result.data.constData() + 6) : 0;
     471            Q_UNUSED(tid)
     472            const ushort len = result.data.size() > 12 ? extractShort(result.data.constData() + 10) : ushort(0);
    405473            const QString name = len ? QString::fromAscii(result.data.mid(12, len)) : QString();
    406474            logMessage(QString::fromLatin1("%1 %2 UNLOAD: %3").
     
    408476                       arg(name));
    409477            d->m_device->sendTrkAck(result.token);
    410             if (itemType == 0 // process
     478            if (itemType == kDSOSProcessItem // process
    411479                && result.data.size() >= 10
    412480                && d->m_session.pid == extractInt(result.data.data() + 6)) {
    413                 disconnectTrk();
     481                    if (d->m_startupActions & ActionDownload)
     482                        copyFileFromRemote();
     483                    else
     484                        disconnectTrk();
     485            }
     486            else if (itemType == kDSOSDLLItem && len) {
     487                // Remove libraries of process.
     488                for (QList<Library>::iterator it = d->m_session.libraries.begin(); it != d->m_session.libraries.end(); ) {
     489                    if ((*it).pid == pid && (*it).name == name) {
     490                        emit libraryUnloaded(*it);
     491                        it = d->m_session.libraries.erase(it);
     492                    } else {
     493                        ++it;
     494                    }
     495                }
    414496            }
    415497            break;
     
    447529        if (d->m_startupActions == ActionPingOnly) {
    448530            setState(Disconnected);
    449             emit finished();
     531            handleFinished();
    450532        }
    451533        return;
     
    456538    d->m_session.trkAppVersion.protocolMinor = result.data.at(4);
    457539    setState(DeviceDescriptionReceived);
     540    const QString msg = deviceDescription();
     541    emit deviceDescriptionReceived(trkServerName(), msg);
    458542    // Ping mode: Log & Terminate
    459543    if (d->m_startupActions == ActionPingOnly) {
    460         qWarning("%s", qPrintable(deviceDescription()));
     544        qWarning("%s", qPrintable(msg));
    461545        setState(Disconnected);
    462         emit finished();
    463     }
     546        handleFinished();
     547    }
     548}
     549
     550static inline QString msgCannotOpenRemoteFile(const QString &fileName, const QString &message)
     551{
     552    return Launcher::tr("Cannot open remote file '%1': %2").arg(fileName, message);
     553}
     554
     555static inline QString msgCannotOpenLocalFile(const QString &fileName, const QString &message)
     556{
     557    return Launcher::tr("Cannot open '%1': %2").arg(fileName, message);
    464558}
    465559
     
    467561{
    468562    if (result.errorCode() || result.data.size() < 6) {
    469         emit canNotCreateFile(d->m_copyState.destinationFileName, result.errorString());
     563        const QString msg = msgCannotOpenRemoteFile(d->m_copyState.destinationFileName, result.errorString());
     564        logMessage(msg);
     565        emit canNotCreateFile(d->m_copyState.destinationFileName, msg);
    470566        disconnectTrk();
    471567        return;
     
    473569    const char *data = result.data.data();
    474570    d->m_copyState.copyFileHandle = extractInt(data + 2);
    475     QFile file(d->m_copyState.sourceFileName);
    476     file.open(QIODevice::ReadOnly);
     571    const QString localFileName = d->m_copyState.sourceFileName;
     572    QFile file(localFileName);
     573    d->m_copyState.position = 0;
     574    if (!file.open(QIODevice::ReadOnly)) {
     575        const QString msg = msgCannotOpenLocalFile(localFileName, file.errorString());
     576        logMessage(msg);
     577        emit canNotOpenLocalFile(localFileName, msg);
     578        closeRemoteFile(true);
     579        disconnectTrk();
     580        return;
     581    }
    477582    d->m_copyState.data.reset(new QByteArray(file.readAll()));
    478     d->m_copyState.position = 0;
    479583    file.close();
    480584    continueCopying();
     585}
     586
     587void Launcher::handleFileOpened(const TrkResult &result)
     588{
     589    if (result.errorCode() || result.data.size() < 6) {
     590        const QString msg = msgCannotOpenRemoteFile(d->m_downloadState.sourceFileName, result.errorString());
     591        logMessage(msg);
     592        emit canNotOpenFile(d->m_downloadState.sourceFileName, msg);
     593        disconnectTrk();
     594        return;
     595    }
     596    d->m_downloadState.position = 0;
     597    const QString localFileName = d->m_downloadState.destinationFileName;
     598    bool opened = false;
     599    if (localFileName == QLatin1String("-")) {
     600        d->m_downloadState.localFile.reset(new QFile);
     601        opened = d->m_downloadState.localFile->open(stdout, QFile::WriteOnly);
     602    } else {
     603        d->m_downloadState.localFile.reset(new QFile(localFileName));
     604        opened = d->m_downloadState.localFile->open(QFile::WriteOnly | QFile::Truncate);
     605    }
     606    if (!opened) {
     607        const QString msg = msgCannotOpenLocalFile(localFileName, d->m_downloadState.localFile->errorString());
     608        logMessage(msg);
     609        emit canNotOpenLocalFile(localFileName, msg);
     610        closeRemoteFile(true);
     611        disconnectTrk();
     612    }
     613    continueReading();
     614}
     615
     616void Launcher::continueReading()
     617{
     618    QByteArray ba;
     619    appendInt(&ba, d->m_downloadState.copyFileHandle, TargetByteOrder);
     620    appendShort(&ba, 2048, TargetByteOrder);
     621    d->m_device->sendTrkMessage(TrkReadFile, TrkCallback(this, &Launcher::handleRead), ba);
     622}
     623
     624void Launcher::handleRead(const TrkResult &result)
     625{
     626    if (result.errorCode() || result.data.size() < 4) {
     627        d->m_downloadState.localFile->close();
     628        closeRemoteFile(true);
     629        disconnectTrk();
     630    } else {
     631        int length = extractShort(result.data.data() + 2);
     632        //TRK doesn't tell us the file length, so we need to keep reading until it returns 0 length
     633        if (length > 0) {
     634            d->m_downloadState.localFile->write(result.data.data() + 4, length);
     635            continueReading();
     636        } else {
     637            closeRemoteFile(true);
     638            disconnectTrk();
     639        }
     640    }
    481641}
    482642
     
    494654void Launcher::continueCopying(uint lastCopiedBlockSize)
    495655{
    496     int size = d->m_copyState.data->length();
     656    qint64 size = d->m_copyState.data->length();
    497657    d->m_copyState.position += lastCopiedBlockSize;
    498658    if (size == 0)
    499659        emit copyProgress(100);
    500660    else {
    501         int percent = qMin((d->m_copyState.position*100)/size, 100);
    502         emit copyProgress(percent);
     661        const qint64 hundred = 100;
     662        const qint64 percent = qMin( (d->m_copyState.position * hundred) / size, hundred);
     663        emit copyProgress(static_cast<int>(percent));
    503664    }
    504665    if (d->m_copyState.position < size) {
     
    533694    else if (d->m_startupActions & ActionRun)
    534695        startInferiorIfNeeded();
     696    else if (d->m_startupActions & ActionDownload)
     697        copyFileFromRemote();
    535698    else
    536699        disconnectTrk();
     
    577740    }
    578741    emit applicationRunning(d->m_session.pid);
     742    //create a "library" entry for the executable which launched the process
     743    Library lib;
     744    lib.pid = d->m_session.pid;
     745    lib.codeseg = d->m_session.codeseg;
     746    lib.dataseg = d->m_session.dataseg;
     747    lib.name = d->m_fileName.toUtf8();
     748    d->m_session.libraries << lib;
     749    emit libraryLoaded(lib);
     750
    579751    QByteArray ba;
    580752    appendInt(&ba, d->m_session.pid);
     
    587759    logMessage("   FINISHED: " + stringFromArray(result.data));
    588760    setState(Disconnected);
    589     emit finished();
     761    handleFinished();
    590762}
    591763
     
    596768    const char *data = result.data.data() + 1;
    597769
    598     QString str = QLatin1String("SUPPORTED: ");
    599     for (int i = 0; i < 32; ++i) {
    600         //str.append("  [" + formatByte(data[i]) + "]: ");
    601         for (int j = 0; j < 8; ++j) {
    602             if (data[i] & (1 << j)) {
    603                 str.append(QString::number(i * 8 + j, 16));
    604                 str.append(QLatin1Char(' '));
     770    if (d->m_verbose > 1) {
     771        QString str = QLatin1String("SUPPORTED: ");
     772        for (int i = 0; i < 32; ++i) {
     773            for (int j = 0; j < 8; ++j) {
     774                if (data[i] & (1 << j)) {
     775                    str.append(QString::number(i * 8 + j, 16));
     776                    str.append(QLatin1Char(' '));
     777                }
    605778            }
    606779        }
    607     }
    608     logMessage(str);
     780        logMessage(str);
     781    }
    609782}
    610783
     
    670843    emit copyingStarted();
    671844    QByteArray ba;
    672     ba.append(char(10));
     845    ba.append(char(10)); //kDSFileOpenWrite | kDSFileOpenBinary
    673846    appendString(&ba, d->m_copyState.destinationFileName.toLocal8Bit(), TargetByteOrder, false);
    674847    d->m_device->sendTrkMessage(TrkOpenFile, TrkCallback(this, &Launcher::handleFileCreation), ba);
     848}
     849
     850void Launcher::copyFileFromRemote()
     851{
     852    emit copyingStarted();
     853    QByteArray ba;
     854    ba.append(char(9)); //kDSFileOpenRead | kDSFileOpenBinary
     855    appendString(&ba, d->m_downloadState.sourceFileName.toLocal8Bit(), TargetByteOrder, false);
     856    d->m_device->sendTrkMessage(TrkOpenFile, TrkCallback(this, &Launcher::handleFileOpened), ba);
    675857}
    676858
     
    695877    if (d->m_startupActions & ActionRun) {
    696878        startInferiorIfNeeded();
     879    } else if (d->m_startupActions & ActionDownload) {
     880        copyFileFromRemote();
    697881    } else {
    698882        disconnectTrk();
     
    705889    // It's not started yet
    706890    QByteArray ba;
    707     appendShort(&ba, 0, TargetByteOrder); // create new process
     891    appendShort(&ba, 0, TargetByteOrder); // create new process (kDSOSProcessItem)
    708892    ba.append(char(0)); // options - currently unused
    709     if(arguments.isEmpty()) {
    710         appendString(&ba, executable.toLocal8Bit(), TargetByteOrder);
    711         return ba;
    712     }
    713     // Append full command line as one string (leading length information).
    714     QByteArray commandLineBa;
    715     commandLineBa.append(executable.toLocal8Bit());
    716     commandLineBa.append('\0');
    717     commandLineBa.append(arguments.join(QString(QLatin1Char(' '))).toLocal8Bit());
    718     appendString(&ba, commandLineBa, TargetByteOrder);
     893    // One string consisting of binary terminated by '\0' and arguments terminated by '\0'
     894    QByteArray commandLineBa = executable.toLocal8Bit();
     895    commandLineBa.append(char(0));
     896    if (!arguments.isEmpty())
     897        commandLineBa.append(arguments.join(QString(QLatin1Char(' '))).toLocal8Bit());
     898    appendString(&ba, commandLineBa, TargetByteOrder, true);
     899    return ba;
     900}
     901
     902QByteArray Launcher::readMemoryMessage(uint pid, uint tid, uint from, uint len)
     903{
     904    QByteArray ba;
     905    ba.reserve(11);
     906    ba.append(char(0x8)); // Options, FIXME: why?
     907    appendShort(&ba, len);
     908    appendInt(&ba, from);
     909    appendInt(&ba, pid);
     910    appendInt(&ba, tid);
     911    return ba;
     912}
     913
     914QByteArray Launcher::readRegistersMessage(uint pid, uint tid)
     915{
     916    QByteArray ba;
     917    ba.reserve(15);
     918    ba.append(char(0)); // Register set, only 0 supported
     919    appendShort(&ba, 0); //R0
     920    appendShort(&ba, 16); // last register CPSR
     921    appendInt(&ba, pid);
     922    appendInt(&ba, tid);
    719923    return ba;
    720924}
     
    738942    d->m_device->sendTrkMessage(TrkContinue, TrkCallback(), ba, "CONTINUE");
    739943}
     944
     945// Acquire a device from SymbianDeviceManager, return 0 if not available.
     946Launcher *Launcher::acquireFromDeviceManager(const QString &serverName,
     947                                             QObject *parent,
     948                                             QString *errorMessage)
     949{
     950    SymbianUtils::SymbianDeviceManager *sdm = SymbianUtils::SymbianDeviceManager::instance();
     951    const QSharedPointer<trk::TrkDevice> device = sdm->acquireDevice(serverName);
     952    if (device.isNull()) {
     953        *errorMessage = tr("Unable to acquire a device for port '%1'. It appears to be in use.").arg(serverName);
     954        return 0;
     955    }
     956    // Wire release signal.
     957    Launcher *rc = new Launcher(trk::Launcher::ActionPingOnly, device, parent);
     958    connect(rc, SIGNAL(deviceDescriptionReceived(QString,QString)),
     959            sdm, SLOT(setAdditionalInformation(QString,QString)));
     960    connect(rc, SIGNAL(destroyed(QString)), sdm, SLOT(releaseDevice(QString)));
     961    return rc;
     962}
     963
     964// Preliminary release of device, disconnecting the signal.
     965void Launcher::releaseToDeviceManager(Launcher *launcher)
     966{
     967    SymbianUtils::SymbianDeviceManager *sdm = SymbianUtils::SymbianDeviceManager::instance();
     968    // Disentangle launcher and its device, remove connection from destroyed
     969    launcher->setCloseDevice(false);
     970    TrkDevice *device = launcher->trkDevice().data();
     971    launcher->disconnect(device);
     972    device->disconnect(launcher);
     973    launcher->disconnect(sdm);
     974    sdm->releaseDevice(launcher->trkServerName());
     975}
     976
     977void Launcher::getRegistersAndCallStack(uint pid, uint tid)
     978{
     979    d->m_device->sendTrkMessage(TrkReadRegisters,
     980                                TrkCallback(this, &Launcher::handleReadRegisters),
     981                                Launcher::readRegistersMessage(pid, tid));
     982    d->m_crashReportState.fetchingStackPID = pid;
     983    d->m_crashReportState.fetchingStackTID = tid;
     984}
     985
     986void Launcher::handleReadRegisters(const TrkResult &result)
     987{
     988    if(result.errorCode() || result.data.size() < (17*4)) {
     989        terminate();
     990        return;
     991    }
     992    const char* data = result.data.constData() + 1;
     993    d->m_crashReportState.registers.clear();
     994    d->m_crashReportState.stack.clear();
     995    for (int i=0;i<17;i++) {
     996        uint r = extractInt(data);
     997        data += 4;
     998        d->m_crashReportState.registers.append(r);
     999    }
     1000    d->m_crashReportState.sp = d->m_crashReportState.registers.at(13);
     1001
     1002    const ushort len = 1024 - (d->m_crashReportState.sp % 1024); //read to 1k boundary first
     1003    const QByteArray ba = Launcher::readMemoryMessage(d->m_crashReportState.fetchingStackPID,
     1004                                                      d->m_crashReportState.fetchingStackTID,
     1005                                                      d->m_crashReportState.sp,
     1006                                                      len);
     1007    d->m_device->sendTrkMessage(TrkReadMemory, TrkCallback(this, &Launcher::handleReadStack), ba);
     1008    d->m_crashReportState.sp += len;
     1009}
     1010
     1011void Launcher::handleReadStack(const TrkResult &result)
     1012{
     1013    if (result.errorCode()) {
     1014        //error implies memory fault when reaching end of stack
     1015        emit registersAndCallStackReadComplete(d->m_crashReportState.registers, d->m_crashReportState.stack);
     1016        return;
     1017    }
     1018
     1019    const uint len = extractShort(result.data.constData() + 1);
     1020    d->m_crashReportState.stack.append(result.data.mid(3, len));
     1021
     1022    if (d->m_crashReportState.sp - d->m_crashReportState.registers.at(13) > 0x10000) {
     1023        //read enough stack, stop here
     1024        emit registersAndCallStackReadComplete(d->m_crashReportState.registers, d->m_crashReportState.stack);
     1025        return;
     1026    }
     1027    //read 1k more
     1028    const QByteArray ba = Launcher::readMemoryMessage(d->m_crashReportState.fetchingStackPID,
     1029                                                      d->m_crashReportState.fetchingStackTID,
     1030                                                      d->m_crashReportState.sp,
     1031                                                      1024);
     1032    d->m_device->sendTrkMessage(TrkReadMemory, TrkCallback(this, &Launcher::handleReadStack), ba);
     1033    d->m_crashReportState.sp += 1024;
     1034}
     1035
    7401036} // namespace trk
  • trunk/tools/runonphone/symbianutils/launcher.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4444
    4545#include "trkdevice.h"
     46#include "trkutils.h"
    4647
    4748#include <QtCore/QObject>
     
    7071        ActionCopyInstall = ActionCopy | ActionInstall,
    7172        ActionRun = 0x4,
     73        ActionDownload = 0x8,
    7274        ActionCopyRun = ActionCopy | ActionRun,
    7375        ActionInstallRun = ActionInstall | ActionRun,
     
    9597    void setFileName(const QString &name);
    9698    void setCopyFileName(const QString &srcName, const QString &dstName);
     99    void setDownloadFileName(const QString &srcName, const QString &dstName);
    97100    void setInstallFileName(const QString &name);
    98101    void setCommandLineArgs(const QStringList &args);
    99102    bool startServer(QString *errorMessage);
    100     void setVerbose(int v);   
     103    void setVerbose(int v);
    101104    void setSerialFrame(bool b);
    102105    bool serialFrame() const;
     
    110113    QString deviceDescription(unsigned verbose = 0u) const;
    111114
     115    // Acquire a device from SymbianDeviceManager, return 0 if not available.
     116    // The device will be released on destruction.
     117    static Launcher *acquireFromDeviceManager(const QString &serverName,
     118                                              QObject *parent,
     119                                              QString *errorMessage);
     120    // Preliminary release of device, disconnecting the signal.
     121    static void releaseToDeviceManager(Launcher *l);
     122
     123    // Create Trk message to start a process.
    112124    static QByteArray startProcessMessage(const QString &executable,
    113125                                          const QStringList &arguments);
     126    // Create Trk message to read memory
     127    static QByteArray readMemoryMessage(uint pid, uint tid, uint from, uint len);
     128    static QByteArray readRegistersMessage(uint pid, uint tid);
    114129    // Parse a TrkNotifyStopped message
    115130    static bool parseNotifyStopped(const QByteArray &a,
     
    120135
    121136signals:
     137    void deviceDescriptionReceived(const QString &port, const QString &description);
    122138    void copyingStarted();
    123139    void canNotConnect(const QString &errorMessage);
    124140    void canNotCreateFile(const QString &filename, const QString &errorMessage);
     141    void canNotOpenFile(const QString &filename, const QString &errorMessage);
     142    void canNotOpenLocalFile(const QString &filename, const QString &errorMessage);
    125143    void canNotWriteFile(const QString &filename, const QString &errorMessage);
    126144    void canNotCloseFile(const QString &filename, const QString &errorMessage);
     
    136154    void stateChanged(int);
    137155    void processStopped(uint pc, uint pid, uint tid, const QString& reason);
     156    void processResumed(uint pid, uint tid);
     157    void libraryLoaded(const trk::Library &lib);
     158    void libraryUnloaded(const trk::Library &lib);
     159    void registersAndCallStackReadComplete(const QList<uint>& registers, const QByteArray& stack);
     160    // Emitted by the destructor, for releasing devices of SymbianDeviceManager by name
     161    void destroyed(const QString &serverName);
    138162
    139163public slots:
    140164    void terminate();
    141165    void resumeProcess(uint pid, uint tid);
     166    //can be used to obtain traceback after a breakpoint / exception
     167    void getRegistersAndCallStack(uint pid, uint tid);
    142168
    143169private slots:
     
    153179    void handleConnect(const TrkResult &result);
    154180    void handleFileCreation(const TrkResult &result);
     181    void handleFileOpened(const TrkResult &result);
    155182    void handleCopy(const TrkResult &result);
     183    void handleRead(const TrkResult &result);
    156184    void continueCopying(uint lastCopiedBlockSize = 0);
     185    void continueReading();
    157186    void closeRemoteFile(bool failed = false);
    158187    void handleFileCopied(const TrkResult &result);
     
    164193    void handleSupportMask(const TrkResult &result);
    165194    void handleTrkVersion(const TrkResult &result);
     195    void handleReadRegisters(const TrkResult &result);
     196    void handleReadStack(const TrkResult &result);
    166197
    167198    void copyFileToRemote();
     199    void copyFileFromRemote();
    168200    void installRemotePackageSilently();
    169201    void startInferiorIfNeeded();
     202    void handleFinished();
    170203
    171204    void logMessage(const QString &msg);
  • trunk/tools/runonphone/symbianutils/symbiandevicemanager.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4141
    4242#include "symbiandevicemanager.h"
     43#include "trkdevice.h"
    4344
    4445#include <QtCore/QSettings>
     
    4950#include <QtCore/QSharedData>
    5051#include <QtCore/QScopedPointer>
     52#include <QtCore/QSignalMapper>
    5153
    5254namespace SymbianUtils {
     
    6264class SymbianDeviceData : public QSharedData {
    6365public:
    64     SymbianDeviceData() : type(SerialPortCommunication) {}
     66    SymbianDeviceData();
     67    ~SymbianDeviceData();
     68
     69    inline bool isOpen() const { return !device.isNull() && device->isOpen(); }
     70    void forcedClose();
    6571
    6672    QString portName;
     
    6874    QString deviceDesc;
    6975    QString manufacturer;
     76    QString additionalInformation;
     77
    7078    DeviceCommunicationType type;
     79    QSharedPointer<trk::TrkDevice> device;
     80    bool deviceAcquired;
    7181};
     82
     83SymbianDeviceData::SymbianDeviceData() :
     84        type(SerialPortCommunication),
     85        deviceAcquired(false)
     86{
     87}
     88
     89SymbianDeviceData::~SymbianDeviceData()
     90{
     91    forcedClose();
     92}
     93
     94void SymbianDeviceData::forcedClose()
     95{
     96    // Close the device when unplugging. Should devices be in 'acquired' state,
     97    // their owners should hit on write failures.
     98    // Apart from the <shared item> destructor, also called by the devicemanager
     99    // to ensure it also happens if other shared instances are still around.
     100    if (isOpen()) {
     101        if (deviceAcquired)
     102            qWarning("Device on '%s' unplugged while an operation is in progress.",
     103                     qPrintable(portName));
     104        device->close();
     105    }
     106}
    72107
    73108SymbianDevice::SymbianDevice(SymbianDeviceData *data) :
    74109    m_data(data)
    75110{
    76 
    77111}
    78112
     
    97131}
    98132
     133void SymbianDevice::forcedClose()
     134{
     135    m_data->forcedClose();
     136}
     137
    99138QString SymbianDevice::portName() const
    100139{
     
    107146}
    108147
     148QString SymbianDevice::additionalInformation() const
     149{
     150    return m_data->additionalInformation;
     151}
     152
     153void SymbianDevice::setAdditionalInformation(const QString &a)
     154{
     155    m_data->additionalInformation = a;
     156}
     157
     158SymbianDevice::TrkDevicePtr SymbianDevice::acquireDevice()
     159{
     160    if (debug)
     161        qDebug() << "SymbianDevice::acquireDevice" << m_data->portName
     162                << "acquired: " << m_data->deviceAcquired << " open: " << isOpen();
     163    if (isNull() || m_data->deviceAcquired)
     164        return TrkDevicePtr();
     165    if (m_data->device.isNull()) {
     166        m_data->device = TrkDevicePtr(new trk::TrkDevice);
     167        m_data->device->setPort(m_data->portName);
     168        m_data->device->setSerialFrame(m_data->type == SerialPortCommunication);
     169    }
     170    m_data->deviceAcquired = true;
     171    return m_data->device;
     172}
     173
     174void SymbianDevice::releaseDevice(TrkDevicePtr *ptr /* = 0 */)
     175{
     176    if (debug)
     177        qDebug() << "SymbianDevice::releaseDevice" << m_data->portName
     178                << " open: " << isOpen();
     179    if (m_data->deviceAcquired) {
     180        if (m_data->device->isOpen())
     181            m_data->device->clearWriteQueue();
     182        // Release if a valid pointer was passed in.
     183        if (ptr && !ptr->isNull()) {
     184            ptr->data()->disconnect();
     185            *ptr = TrkDevicePtr();
     186        }
     187        m_data->deviceAcquired = false;
     188    } else {
     189        qWarning("Internal error: Attempt to release device that is not acquired.");
     190    }
     191}
     192
    109193QString SymbianDevice::deviceDesc() const
    110194{
     
    124208bool SymbianDevice::isNull() const
    125209{
    126     return !m_data->portName.isEmpty();
     210    return m_data->portName.isEmpty();
     211}
     212
     213bool SymbianDevice::isOpen() const
     214{
     215    return m_data->isOpen();
    127216}
    128217
     
    159248}
    160249
    161 QDebug operator<<(QDebug d, const SymbianDevice &cd)
     250SYMBIANUTILS_EXPORT QDebug operator<<(QDebug d, const SymbianDevice &cd)
    162251{
    163252    d.nospace() << cd.toString();
     
    167256// ------------- SymbianDeviceManagerPrivate
    168257struct SymbianDeviceManagerPrivate {
    169     SymbianDeviceManagerPrivate() : m_initialized(false) {}
     258    SymbianDeviceManagerPrivate() : m_initialized(false), m_destroyReleaseMapper(0) {}
    170259
    171260    bool m_initialized;
    172261    SymbianDeviceManager::SymbianDeviceList m_devices;
     262    QSignalMapper *m_destroyReleaseMapper;
    173263};
    174264
     
    186276SymbianDeviceManager::SymbianDeviceList SymbianDeviceManager::devices() const
    187277{
    188     if (!d->m_initialized)
    189         const_cast<SymbianDeviceManager*>(this)->update(false);
     278    ensureInitialized();
    190279    return d->m_devices;
    191280}
     
    195284    QString rc;
    196285    QTextStream str(&rc);
     286    str << d->m_devices.size() << " devices:\n";
    197287    const int count = d->m_devices.size();
    198288    for (int i = 0; i < count; i++) {
     
    204294}
    205295
     296int SymbianDeviceManager::findByPortName(const QString &p) const
     297{
     298    ensureInitialized();
     299    const int count = d->m_devices.size();
     300    for (int i = 0; i < count; i++)
     301        if (d->m_devices.at(i).portName() == p)
     302            return i;
     303    return -1;
     304}
     305
    206306QString SymbianDeviceManager::friendlyNameForPort(const QString &port) const
    207307{
    208     foreach (const SymbianDevice &device, d->m_devices) {
    209         if (device.portName() == port)
    210             return device.friendlyName();
    211     }
    212     return QString();
     308    const int idx = findByPortName(port);
     309    return idx == -1 ? QString() : d->m_devices.at(idx).friendlyName();
     310}
     311
     312SymbianDeviceManager::TrkDevicePtr
     313        SymbianDeviceManager::acquireDevice(const QString &port)
     314{
     315    ensureInitialized();
     316    const int idx = findByPortName(port);
     317    if (idx == -1) {
     318        qWarning("Attempt to acquire device '%s' that does not exist.", qPrintable(port));
     319        if (debug)
     320            qDebug() << *this;
     321        return TrkDevicePtr();
     322      }
     323    const TrkDevicePtr rc = d->m_devices[idx].acquireDevice();
     324    if (debug)
     325        qDebug() << "SymbianDeviceManager::acquireDevice" << port << " returns " << !rc.isNull();
     326    return rc;
    213327}
    214328
     
    218332}
    219333
     334void SymbianDeviceManager::releaseDevice(const QString &port)
     335{
     336    const int idx = findByPortName(port);
     337    if (debug)
     338        qDebug() << "SymbianDeviceManager::releaseDevice" << port << idx << sender();
     339    if (idx != -1) {
     340        d->m_devices[idx].releaseDevice();
     341    } else {
     342        qWarning("Attempt to release non-existing device %s.", qPrintable(port));
     343    }
     344}
     345
     346void SymbianDeviceManager::setAdditionalInformation(const QString &port, const QString &ai)
     347{
     348    const int idx = findByPortName(port);
     349    if (idx != -1)
     350        d->m_devices[idx].setAdditionalInformation(ai);
     351}
     352
     353void SymbianDeviceManager::ensureInitialized() const
     354{
     355    if (!d->m_initialized) // Flag is set in update()
     356        const_cast<SymbianDeviceManager*>(this)->update(false);
     357}
     358
    220359void SymbianDeviceManager::update(bool emitSignals)
    221360{
     361    static int n = 0;
    222362    typedef SymbianDeviceList::iterator SymbianDeviceListIterator;
    223363
    224364    if (debug)
    225         qDebug(">SerialDeviceLister::update(%d)\n%s", int(emitSignals),
     365        qDebug(">SerialDeviceLister::update(#%d, signals=%d)\n%s", n++, int(emitSignals),
    226366               qPrintable(toString()));
    227367
     
    231371    if (newDevices.size() > 1)
    232372        qStableSort(newDevices.begin(), newDevices.end());
    233     if (d->m_devices == newDevices) // Happy, nothing changed.
     373    if (d->m_devices == newDevices) { // Happy, nothing changed.
     374        if (debug)
     375            qDebug("<SerialDeviceLister::update: unchanged\n");
    234376        return;
     377    }
    235378    // Merge the lists and emit the respective added/removed signals, assuming
    236379    // no one can plug a different device on the same port at the speed of lightning
     
    241384                ++oldIt;
    242385            } else {
    243                 const SymbianDevice toBeDeleted = *oldIt;
     386                SymbianDevice toBeDeleted = *oldIt;
     387                toBeDeleted.forcedClose();
    244388                oldIt = d->m_devices.erase(oldIt);
    245389                if (emitSignals)
     
    302446    // or at least the first one.
    303447    const QString prefix = QLatin1String(linuxBlueToothDeviceRootC);
    304     const QString friendlyFormat = QLatin1String("Bluetooth device (%1)");
     448    const QString blueToothfriendlyFormat = QLatin1String("Bluetooth device (%1)");
    305449    for (int d = 0; d < 4; d++) {
    306450        QScopedPointer<SymbianDeviceData> device(new SymbianDeviceData);
     
    308452        device->portName = prefix + QString::number(d);
    309453        if (d == 0 || QFileInfo(device->portName).exists()) {
    310             device->friendlyName = friendlyFormat.arg(device->portName);
     454            device->friendlyName = blueToothfriendlyFormat.arg(device->portName);
    311455            rc.push_back(SymbianDevice(device.take()));
     456        }
     457    }
     458    // New kernel versions support /dev/ttyUSB0, /dev/ttyUSB1. Trk responds
     459    // on the latter (usually), try first.
     460    static const char *usbTtyDevices[] = { "/dev/ttyUSB1", "/dev/ttyUSB0" };
     461    const int usbTtyCount = sizeof(usbTtyDevices)/sizeof(const char *);
     462    for (int d = 0; d < usbTtyCount; d++) {
     463        const QString ttyUSBDevice = QLatin1String(usbTtyDevices[d]);
     464        if (QFileInfo(ttyUSBDevice).exists()) {
     465            SymbianDeviceData *device = new SymbianDeviceData;
     466            device->type = SerialPortCommunication;
     467            device->portName = ttyUSBDevice;
     468            device->friendlyName = QString::fromLatin1("USB/Serial device (%1)").arg(device->portName);
     469            rc.push_back(SymbianDevice(device));
    312470        }
    313471    }
     
    323481}
    324482
    325 QDebug operator<<(QDebug d, const SymbianDeviceManager &sdm)
     483SYMBIANUTILS_EXPORT QDebug operator<<(QDebug d, const SymbianDeviceManager &sdm)
    326484{
    327485    d.nospace() << sdm.toString();
  • trunk/tools/runonphone/symbianutils/symbiandevicemanager.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4747#include <QtCore/QObject>
    4848#include <QtCore/QExplicitlySharedDataPointer>
     49#include <QtCore/QSharedPointer>
    4950
    5051QT_BEGIN_NAMESPACE
     
    5253class QTextStream;
    5354QT_END_NAMESPACE
     55
     56namespace trk {
     57    class TrkDevice;
     58}
    5459
    5560namespace SymbianUtils {
     
    6368};
    6469
    65 // SymbianDevice, explicitly shared.
     70// SymbianDevice: Explicitly shared device data and a TrkDevice
     71// instance that can be acquired (exclusively) for use.
     72// A device removal from the manager will result in the
     73// device being closed.
    6674class SYMBIANUTILS_EXPORT SymbianDevice {
    6775    explicit SymbianDevice(SymbianDeviceData *data);
    6876    friend class SymbianDeviceManager;
    6977public:
     78    typedef QSharedPointer<trk::TrkDevice> TrkDevicePtr;
     79
    7080    SymbianDevice();
    7181    SymbianDevice(const SymbianDevice &rhs);
     
    7888    QString portName() const;
    7989    QString friendlyName() const;
     90    QString additionalInformation() const;
     91    void setAdditionalInformation(const QString &);
     92
     93    // Acquire: Mark the device as 'out' and return a shared pointer
     94    // unless it is already in use by another owner. The result should not
     95    // be passed on further.
     96    TrkDevicePtr acquireDevice();
     97    // Give back a device and mark it as 'free'.
     98    void releaseDevice(TrkDevicePtr *ptr = 0);
     99
     100    bool isOpen() const;
    80101
    81102    // Windows only.
     
    87108
    88109private:
     110    void forcedClose();
     111
    89112    QExplicitlySharedDataPointer<SymbianDeviceData> m_data;
    90113};
    91114
    92 QDebug operator<<(QDebug d, const SymbianDevice &);
     115SYMBIANUTILS_EXPORT QDebug operator<<(QDebug d, const SymbianDevice &);
    93116
    94117inline bool operator==(const SymbianDevice &d1, const SymbianDevice &d2)
     
    101124/* SymbianDeviceManager: Singleton that maintains a list of Symbian devices.
    102125 * and emits change signals.
    103  * On Windows, the update slot must be connected to a signal
    104  * emitted from an event handler listening for WM_DEVICECHANGE. */
     126 * On Windows, the update slot must be connected to a [delayed] signal
     127 * emitted from an event handler listening for WM_DEVICECHANGE.
     128 * Device removal will result in the device being closed. */
    105129class SYMBIANUTILS_EXPORT SymbianDeviceManager : public QObject
    106130{
     
    108132public:
    109133    typedef QList<SymbianDevice> SymbianDeviceList;
     134    typedef QSharedPointer<trk::TrkDevice> TrkDevicePtr;
    110135
    111136    static const char *linuxBlueToothDeviceRootC;
     
    121146    QString toString() const;
    122147
     148    // Acquire a device for use. See releaseDevice().
     149    TrkDevicePtr acquireDevice(const QString &port);
     150
     151    int findByPortName(const QString &p) const;
    123152    QString friendlyNameForPort(const QString &port) const;
    124153
    125154public slots:
    126155    void update();
     156    // Relase a device, make it available for further use.
     157    void releaseDevice(const QString &port);
     158    void setAdditionalInformation(const QString &port, const QString &ai);
    127159
    128160signals:
    129     void deviceRemoved(const SymbianDevice &d);
    130     void deviceAdded(const SymbianDevice &d);
     161    void deviceRemoved(const SymbianUtils::SymbianDevice &d);
     162    void deviceAdded(const SymbianUtils::SymbianDevice &d);
    131163    void updated();
    132164
    133165private:
     166    void ensureInitialized() const;
    134167    void update(bool emitSignals);
    135168    SymbianDeviceList serialPorts() const;
     
    139172};
    140173
    141 QDebug operator<<(QDebug d, const SymbianDeviceManager &);
     174SYMBIANUTILS_EXPORT QDebug operator<<(QDebug d, const SymbianDeviceManager &);
    142175
    143176} // namespace SymbianUtils
  • trunk/tools/runonphone/symbianutils/symbianutils.pri

    r769 r846  
    11INCLUDEPATH *= $$PWD
     2
     3QT += network
    24
    35# Input
     
    1012    $$PWD/bluetoothlistener.h \
    1113    $$PWD/communicationstarter.h \
    12     $$PWD/symbiandevicemanager.h
     14    $$PWD/symbiandevicemanager.h \
     15    $$PWD/tcftrkdevice.h \
     16    $$PWD/tcftrkmessage.h \
     17    $$PWD/json.h
    1318
    1419SOURCES += $$PWD/trkutils.cpp \
     
    1722    $$PWD/bluetoothlistener.cpp \
    1823    $$PWD/communicationstarter.cpp \
    19     $$PWD/symbiandevicemanager.cpp
     24    $$PWD/symbiandevicemanager.cpp \
     25    $$PWD/tcftrkdevice.cpp \
     26    $$PWD/tcftrkmessage.cpp \
     27    $$PWD/json.cpp
    2028
    2129# Tests/trklauncher is a console application
  • trunk/tools/runonphone/symbianutils/symbianutils_global.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
  • trunk/tools/runonphone/symbianutils/trkdevice.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5353#include <QtCore/QWaitCondition>
    5454#include <QtCore/QSharedPointer>
     55#include <QtCore/QScopedPointer>
    5556#include <QtCore/QMetaType>
    5657
     
    103104enum { verboseTrk = 0 };
    104105
     106static inline QString msgAccessingClosedDevice(const QString &msg)
     107{
     108    return QString::fromLatin1("Error: Attempt to access device '%1', which is closed.").arg(msg);
     109}
     110
    105111namespace trk {
    106112
     
    156162
    157163class TrkWriteQueue
    158 {   
     164{
    159165    Q_DISABLE_COPY(TrkWriteQueue)
    160166public:
    161167    explicit TrkWriteQueue();
     168    void clear();
    162169
    163170    // Enqueue messages.
     
    209216}
    210217
     218void TrkWriteQueue::clear()
     219{
     220    m_trkWriteToken = 0;
     221    m_trkWriteBusy = false;
     222    m_trkWriteQueue.clear();
     223    const int discarded = m_writtenTrkMessages.size();
     224    m_writtenTrkMessages.clear();
     225    if (verboseTrk)
     226        qDebug() << "TrkWriteQueue::clear: discarded " << discarded;
     227}
     228
    211229byte TrkWriteQueue::nextTrkWriteToken()
    212230{
     
    215233        ++m_trkWriteToken;
    216234    if (verboseTrk)
    217         qDebug() << "Write token: " << m_trkWriteToken;
     235        qDebug() << "nextTrkWriteToken:" << m_trkWriteToken;
    218236    return m_trkWriteToken;
    219237}
     
    350368    Q_OBJECT
    351369    Q_DISABLE_COPY(WriterThread)
    352 public:           
     370public:
    353371    explicit WriterThread(const QSharedPointer<DeviceContext> &context);
    354372
     
    358376    void queueTrkInitialPing();
    359377
     378    void clearWriteQueue();
     379
    360380    // Call this from the device read notification with the results.
    361381    void slotHandleResult(const TrkResult &result);
     
    375395    void invokeNoopMessage(const trk::TrkMessage &);
    376396
    377 private:   
     397private:
    378398    bool write(const QByteArray &data, QString *errorMessage);
    379399    inline int writePendingMessage();
     
    463483    wait();
    464484    m_terminate = false;
     485    m_queue.clear();
    465486}
    466487
     
    562583}
    563584
     585void WriterThread::clearWriteQueue()
     586{
     587    m_dataMutex.lock();
     588    m_queue.clear();
     589    m_dataMutex.unlock();
     590}
     591
    564592void WriterThread::queueTrkInitialPing()
    565593{
     
    593621public:
    594622
     623    int bytesPending() const { return m_trkReadBuffer.size(); }
     624
    595625signals:
    596626    void messageReceived(const trk::TrkResult &result, const QByteArray &rawData);
     
    607637
    608638    QByteArray m_trkReadBuffer;
     639    bool linkEstablishmentMode;
    609640};
    610641
    611642ReaderThreadBase::ReaderThreadBase(const QSharedPointer<DeviceContext> &context) :
    612     m_context(context)
     643    m_context(context), linkEstablishmentMode(true)
    613644{
    614645    static const int trkResultMetaId = qRegisterMetaType<trk::TrkResult>();
     
    633664    TrkResult r;
    634665    QByteArray rawData;
    635     while (extractResult(&m_trkReadBuffer, m_context->serialFrame, &r, &rawData)) {
     666    while (extractResult(&m_trkReadBuffer, m_context->serialFrame, &r, linkEstablishmentMode, &rawData)) {
    636667        emit messageReceived(r, rawData);
    637668    }
     
    693724        emit error(QString::fromLatin1("ClearCommError failed: %1").arg(winErrorMessage(GetLastError())));
    694725        return -7;
    695     }   
     726    }
    696727    const DWORD bytesToRead = qMax(DWORD(1), qMin(comStat.cbInQue, DWORD(BufSize)));
    697728    // Trigger read
     
    709740        emit error(QString::fromLatin1("Read error: %1").arg(winErrorMessage(readError)));
    710741        return -1;
    711     }   
     742    }
    712743    // Wait for either termination or data
    713744    const DWORD wr = WaitForMultipleObjects(HandleCount, m_handles, false, INFINITE);
     
    784815};
    785816
    786 UnixReaderThread::UnixReaderThread(const QSharedPointer<DeviceContext> &context) : 
     817UnixReaderThread::UnixReaderThread(const QSharedPointer<DeviceContext> &context) :
    787818    ReaderThreadBase(context)
    788819{
     
    878909
    879910    QSharedPointer<DeviceContext> deviceContext;
    880     QSharedPointer<WriterThread> writerThread;
    881     QSharedPointer<ReaderThread> readerThread;
     911    QScopedPointer<WriterThread> writerThread;
     912    QScopedPointer<ReaderThread> readerThread;
    882913
    883914    QByteArray trkReadBuffer;
     
    918949bool TrkDevice::open(QString *errorMessage)
    919950{
    920     if (d->verbose)
     951    if (d->verbose || verboseTrk)
    921952        qDebug() << "Opening" << port() << "is open: " << isOpen() << " serialFrame=" << serialFrame();
     953    if (isOpen())
     954        return true;
    922955    if (d->port.isEmpty()) {
    923956        *errorMessage = QLatin1String("Internal error: No port set on TrkDevice");
    924957        return false;
    925958    }
    926 
    927     close();
    928959#ifdef Q_OS_WIN
    929960    const QString fullPort = QLatin1String("\\\\.\\") + d->port;
     
    9761007    }
    9771008#endif
    978     d->readerThread = QSharedPointer<ReaderThread>(new ReaderThread(d->deviceContext));
     1009    d->readerThread.reset(new ReaderThread(d->deviceContext));
    9791010    connect(d->readerThread.data(), SIGNAL(error(QString)), this, SLOT(emitError(QString)),
    9801011            Qt::QueuedConnection);
     
    9841015    d->readerThread->start();
    9851016
    986     d->writerThread = QSharedPointer<WriterThread>(new WriterThread(d->deviceContext));
     1017    d->writerThread.reset(new WriterThread(d->deviceContext));
    9871018    connect(d->writerThread.data(), SIGNAL(error(QString)), this, SLOT(emitError(QString)),
    988             Qt::QueuedConnection);   
    989     d->writerThread->start();   
    990 
    991     if (d->verbose)
    992         qDebug() << "Opened" << d->port;
     1019            Qt::QueuedConnection);
     1020    d->writerThread->start();
     1021
     1022    if (d->verbose || verboseTrk)
     1023        qDebug() << "Opened" << d->port << d->readerThread.data() << d->writerThread.data();
    9931024    return true;
    9941025}
     
    9961027void TrkDevice::close()
    9971028{
     1029    if (verboseTrk)
     1030        qDebug() << "close" << d->port << " is open: " << isOpen()
     1031        << " read pending " << (d->readerThread.isNull() ? 0 : d->readerThread->bytesPending())
     1032        << sender();
    9981033    if (!isOpen())
    9991034        return;
     
    10111046    d->deviceContext->file.close();
    10121047#endif
     1048
    10131049    if (d->verbose)
    10141050        emitLogMessage("Close");
     
    10311067void TrkDevice::setPort(const QString &p)
    10321068{
     1069    if (verboseTrk)
     1070        qDebug() << "setPort" << p;
    10331071    d->port = p;
    10341072}
     
    10461084void TrkDevice::setSerialFrame(bool f)
    10471085{
     1086    if (verboseTrk)
     1087        qDebug() << "setSerialFrame" << f;
    10481088    d->deviceContext->serialFrame = f;
    10491089}
     
    10611101void TrkDevice::slotMessageReceived(const trk::TrkResult &result, const QByteArray &rawData)
    10621102{
    1063     d->writerThread->slotHandleResult(result);
    1064     if (d->verbose > 1)
    1065         qDebug() << "Received: " << result.toString();
    1066     emit messageReceived(result);   
    1067     if (!rawData.isEmpty())
    1068         emit rawDataReceived(rawData);
     1103    if (isOpen()) { // Might receive bytes after closing due to queued connections.
     1104        d->writerThread->slotHandleResult(result);
     1105        if (d->verbose > 1)
     1106            qDebug() << "Received: " << result.toString();
     1107        emit messageReceived(result);
     1108        if (!rawData.isEmpty())
     1109            emit rawDataReceived(rawData);
     1110    }
    10691111}
    10701112
     
    10761118}
    10771119
     1120void TrkDevice::clearWriteQueue()
     1121{
     1122    if (isOpen())
     1123        d->writerThread->clearWriteQueue();
     1124}
     1125
    10781126void TrkDevice::sendTrkMessage(byte code, TrkCallback callback,
    10791127     const QByteArray &data, const QVariant &cookie)
    10801128{
     1129    if (!isOpen()) {
     1130        emitError(msgAccessingClosedDevice(d->port));
     1131        return;
     1132    }
    10811133    if (!d->writerThread.isNull()) {
    10821134        if (d->verbose > 1) {
    1083             QByteArray msg = "Sending:  ";
     1135            QByteArray msg = "Sending:  0x";
    10841136            msg += QByteArray::number(code, 16);
    10851137            msg += ": ";
    10861138            msg += stringFromArray(data).toLatin1();
     1139            if (cookie.isValid())
     1140                msg += " Cookie: " + cookie.toString().toLatin1();
    10871141            qDebug("%s", msg.data());
    10881142        }
     
    10931147void TrkDevice::sendTrkInitialPing()
    10941148{
     1149    if (!isOpen()) {
     1150        emitError(msgAccessingClosedDevice(d->port));
     1151        return;
     1152    }
    10951153    if (!d->writerThread.isNull())
    10961154        d->writerThread->queueTrkInitialPing();
     
    10991157bool TrkDevice::sendTrkAck(byte token)
    11001158{
     1159    if (!isOpen()) {
     1160        emitError(msgAccessingClosedDevice(d->port));
     1161        return false;
     1162    }
    11011163    if (d->writerThread.isNull())
    11021164        return false;
  • trunk/tools/runonphone/symbianutils/trkdevice.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6565 * read operation.
    6666 * The serialFrames property specifies whether packets are encapsulated in
    67  * "0x90 <length>" frames, which is currently the case for serial ports. 
     67 * "0x90 <length>" frames, which is currently the case for serial ports.
    6868 * Contains a write message queue allowing
    6969 * for queueing messages with a notification callback. If the message receives
    7070 * an ACK, the callback is invoked.
    71  * The special message TRK_WRITE_QUEUE_NOOP_CODE code can be used for synchronisation.
    72  * The respective  message will not be sent, the callback is just invoked. */
     71 * The special message TRK_WRITE_QUEUE_NOOP_CODE code can be used for synchronization.
     72 * The respective  message will not be sent, the callback is just invoked.
     73 * Note that calling open/close in quick succession can cause crashes
     74 * due to the use of queused signals. */
    7375
    7476enum { TRK_WRITE_QUEUE_NOOP_CODE = 0x7f };
     
    112114    bool sendTrkAck(unsigned char token);
    113115
     116public slots:
     117    void clearWriteQueue();
     118
    114119signals:
    115120    void messageReceived(const trk::TrkResult &result);
  • trunk/tools/runonphone/symbianutils/trkutils.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5252
    5353namespace trk {
     54
     55Library::Library() : codeseg(0), dataseg(0), pid(0)
     56{
     57}
     58
     59Library::Library(const TrkResult &result) : codeseg(0), dataseg(0), pid(0)
     60{
     61    if (result.data.size() < 20) {
     62        qWarning("Invalid trk creation notification received.");
     63        return;
     64    }
     65
     66    const char *data = result.data.constData();
     67    pid = extractInt(data + 2);
     68    codeseg = extractInt(data + 10);
     69    dataseg = extractInt(data + 14);
     70    const uint len = extractShort(data + 18);
     71    name = result.data.mid(20, len);
     72}
    5473
    5574TrkAppVersion::TrkAppVersion()
     
    7897    extended2TypeSize = 0;
    7998    pid = 0;
     99    mainTid = 0;
    80100    tid = 0;
    81101    codeseg = 0;
    82102    dataseg = 0;
    83103
    84     currentThread = 0;
    85104    libraries.clear();
    86105    trkAppVersion.reset();
     
    144163}
    145164
     165QByteArray Session::gdbLibraryList() const
     166{
     167    const int count = libraries.size();
     168    QByteArray response = "l<library-list>";
     169    for (int i = 0; i != count; ++i) {
     170        const trk::Library &lib = libraries.at(i);
     171        response += "<library name=\"";
     172        response += lib.name;
     173        response += "\">";
     174        response += "<section address=\"0x";
     175        response += trk::hexNumber(lib.codeseg);
     176        response += "\"/>";
     177        response += "<section address=\"0x";
     178        response += trk::hexNumber(lib.dataseg);
     179        response += "\"/>";
     180        response += "<section address=\"0x";
     181        response += trk::hexNumber(lib.dataseg);
     182        response += "\"/>";
     183        response += "</library>";
     184    }
     185    response += "</library-list>";
     186    return response;
     187}
     188
     189QByteArray Session::gdbQsDllInfo(int start, int count) const
     190{
     191    // Happens with  gdb 6.4.50.20060226-cvs / CodeSourcery.
     192    // Never made it into FSF gdb that got qXfer:libraries:read instead.
     193    // http://sourceware.org/ml/gdb/2007-05/msg00038.html
     194    // Name=hexname,TextSeg=textaddr[,DataSeg=dataaddr]
     195    const int libraryCount = libraries.size();
     196    const int end = count < 0 ? libraryCount : qMin(libraryCount, start + count);
     197    QByteArray response(1, end == libraryCount ? 'l' : 'm');
     198    for (int i = start; i < end; ++i) {
     199        if (i != start)
     200            response += ';';
     201        const Library &lib = libraries.at(i);
     202        response += "Name=";
     203        response += lib.name.toHex();
     204        response += ",TextSeg=";
     205        response += hexNumber(lib.codeseg);
     206        response += ",DataSeg=";
     207        response += hexNumber(lib.dataseg);
     208    }
     209    return response;
     210}
     211
     212QString Session::toString() const
     213{
     214    QString rc;
     215    QTextStream str(&rc);
     216    str << "Session: " << deviceDescription(false) << '\n'
     217            << "pid: " << pid <<  "main thread: " << mainTid
     218            << " current thread: " << tid << ' ';
     219    str.setIntegerBase(16);
     220    str << " code: 0x" << codeseg << " data: 0x" << dataseg << '\n';
     221    if (const int libCount = libraries.size()) {
     222        str << "Libraries:\n";
     223        for (int i = 0; i < libCount; i++)
     224            str << " #" << i << ' ' << libraries.at(i).name
     225                << " code: 0x" << libraries.at(i).codeseg
     226                << " data: 0x" << libraries.at(i).dataseg << '\n';
     227    }
     228    if (const int moduleCount = modules.size()) {
     229        str << "Modules:\n";
     230        for (int i = 0; i < moduleCount; i++)
     231            str << " #" << i << ' ' << modules.at(i) << '\n';
     232    }
     233    str.setIntegerBase(10);
     234    if (!addressToBP.isEmpty()) {
     235        typedef QHash<uint, uint>::const_iterator BP_ConstIterator;
     236        str << "Breakpoints:\n";
     237        const BP_ConstIterator cend = addressToBP.constEnd();
     238        for (BP_ConstIterator it = addressToBP.constBegin(); it != cend; ++it) {
     239            str.setIntegerBase(16);
     240            str << "  0x" << it.key();
     241            str.setIntegerBase(10);
     242            str << ' ' << it.value() << '\n';
     243        }
     244    }
     245
     246    return rc;
     247}
     248
    146249// --------------
    147250
     
    189292    const int size = maxLen == -1 ? ba.size() : qMin(ba.size(), maxLen);
    190293    for (int i = 0; i < size; ++i) {
    191         //if (i == 5 || i == ba.size() - 2)
    192         //    str += "  ";
    193         int c = byte(ba.at(i));
    194         str += QString("%1 ").arg(c, 2, 16, QChar('0'));
    195         if (i >= 8 && i < ba.size() - 2)
    196             ascii += QChar(c).isPrint() ? QChar(c) : QChar('.');
     294        const int c = byte(ba.at(i));
     295        str += QString::fromAscii("%1 ").arg(c, 2, 16, QChar('0'));
     296        ascii += QChar(c).isPrint() ? QChar(c) : QChar('.');
    197297    }
    198298    if (size != ba.size()) {
    199         str += "...";
    200         ascii += "...";
    201     }
    202     return str + "  " + ascii;
     299        str += QLatin1String("...");
     300        ascii += QLatin1String("...");
     301    }
     302    return str + QLatin1String("  ") + ascii;
    203303}
    204304
     
    277377/* returns 0 if array doesn't represent a result,
    278378otherwise returns the length of the result data */
    279 ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame)
     379ushort isValidTrkResult(const QByteArray &buffer, bool serialFrame, ushort& mux)
    280380{
    281381    if (serialFrame) {
     
    283383        if (buffer.length() < 4)
    284384            return 0;
    285         if (buffer.at(0) != 0x01 || byte(buffer.at(1)) != 0x90)
    286             return 0;
     385        mux = extractShort(buffer.data());
    287386        const ushort len = extractShort(buffer.data() + 2);
    288387        return (buffer.size() >= len + 4) ? len : ushort(0);
     
    293392    // Regular message delimited by 0x7e..0x7e
    294393    if (firstDelimiterPos == 0) {
     394        mux = MuxTrk;
    295395        const int endPos = buffer.indexOf(delimiter, firstDelimiterPos + 1);
    296396        return endPos != -1 ? endPos + 1 - firstDelimiterPos : 0;
     
    300400}
    301401
    302 bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, QByteArray *rawData)
     402bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *result, bool &linkEstablishmentMode, QByteArray *rawData)
    303403{
    304404    result->clear();
    305405    if(rawData)
    306406        rawData->clear();
    307     const ushort len = isValidTrkResult(*buffer, serialFrame);
     407    ushort len = isValidTrkResult(*buffer, serialFrame, result->multiplex);
     408    // handle receiving application output, which is not a regular command
     409    const int delimiterPos = serialFrame ? 4 : 0;
     410    if (linkEstablishmentMode) {
     411        //when "hot connecting" a device, we can receive partial frames.
     412        //this code resyncs by discarding data until a TRK frame is found
     413        while (buffer->length() > delimiterPos
     414               && result->multiplex != MuxTextTrace
     415               && !(result->multiplex == MuxTrk && buffer->at(delimiterPos) == 0x7e)) {
     416            buffer->remove(0,1);
     417            len = isValidTrkResult(*buffer, serialFrame, result->multiplex);
     418        }
     419    }
    308420    if (!len)
    309421        return false;
    310     // handle receiving application output, which is not a regular command
    311     const int delimiterPos = serialFrame ? 4 : 0;
    312422    if (buffer->at(delimiterPos) != 0x7e) {
    313423        result->isDebugOutput = true;
    314424        result->data = buffer->mid(delimiterPos, len);
    315         result->data.replace("\r\n", "\n");
    316         *buffer->remove(0, delimiterPos + len);
     425        buffer->remove(0, delimiterPos + len);
    317426        return true;
    318427    }
     
    322431    if(rawData)
    323432        *rawData = data;
    324     *buffer->remove(0, delimiterPos + len);
     433    buffer->remove(0, delimiterPos + len);
    325434
    326435    byte sum = 0;
     
    337446    //QByteArray prefix = "READ BUF:                                       ";
    338447    //logMessage((prefix + "HEADER: " + stringFromArray(header).toLatin1()).data());
     448    linkEstablishmentMode = false; //have received a good TRK packet, therefore in sync
    339449    return true;
    340450}
     
    351461    res *= 256; res += byte(data[2]);
    352462    res *= 256; res += byte(data[3]);
     463    return res;
     464}
     465
     466SYMBIANUTILS_EXPORT quint64 extractInt64(const char *data)
     467{
     468    quint64 res = byte(data[0]);
     469    res <<= 8; res += byte(data[1]);
     470    res <<= 8; res += byte(data[2]);
     471    res <<= 8; res += byte(data[3]);
     472    res <<= 8; res += byte(data[4]);
     473    res <<= 8; res += byte(data[5]);
     474    res <<= 8; res += byte(data[6]);
     475    res <<= 8; res += byte(data[7]);
    353476    return res;
    354477}
  • trunk/tools/runonphone/symbianutils/trkutils.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4444
    4545#include "symbianutils_global.h"
     46
    4647#include <QtCore/QByteArray>
    4748#include <QtCore/QHash>
     
    5657
    5758typedef unsigned char byte;
     59struct TrkResult;
    5860
    5961enum Command {
     62    //meta commands
    6063    TrkPing = 0x00,
    6164    TrkConnect = 0x01,
    6265    TrkDisconnect = 0x02,
     66    TrkReset = 0x03,
    6367    TrkVersions = 0x04,
    6468    TrkSupported = 0x05,
    6569    TrkCpuType = 0x06,
     70    TrkConfigTransport = 0x07,
     71    TrkVersions2 = 0x08,
    6672    TrkHostVersions = 0x09,
     73
     74    //state commands
     75    TrkReadMemory = 0x10,
     76    TrkWriteMemory = 0x11,
     77    TrkReadRegisters = 0x12,
     78    TrkWriteRegisters = 0x13,
     79    TrkFillMemory = 0x14,
     80    TrkCopyMemory = 0x15,
     81    TrkFlushCache = 0x16,
     82
     83    //execution commands
    6784    TrkContinue = 0x18,
     85    TrkStep = 0x19,
     86    TrkStop = 0x1a,
     87    TrkSetBreak = 0x1b,
     88    TrkClearBreak = 0x1c,
     89    TrkDownload = 0x1d,
     90    TrkModifyBreakThread = 0x1e,
     91
     92    //host -> target IO management
     93    TrkNotifyFileInput = 0x20,
     94    TrkBlockFileIo = 0x21,
     95
     96    //host -> target os commands
    6897    TrkCreateItem = 0x40,
    6998    TrkDeleteItem = 0x41,
     99    TrkReadInfo = 0x42,
     100    TrkWriteInfo = 0x43,
    70101
    71102    TrkWriteFile = 0x48,
     103    TrkReadFile = 0x49,
    72104    TrkOpenFile = 0x4a,
    73105    TrkCloseFile = 0x4b,
     106    TrkPositionFile = 0x4c,
    74107    TrkInstallFile = 0x4d,
    75108    TrkInstallFile2 = 0x4e,
    76109
     110    TrkPhoneSwVersion = 0x4f,
     111    TrkPhoneName = 0x50,
     112    TrkVersions3 = 0x51,
     113
     114    //replies
    77115    TrkNotifyAck = 0x80,
    78116    TrkNotifyNak = 0xff,
     117
     118    //target -> host notification
    79119    TrkNotifyStopped = 0x90,
    80120    TrkNotifyException = 0x91,
    81121    TrkNotifyInternalError = 0x92,
     122    TrkNotifyStopped2 = 0x94,
     123
     124    //target -> host OS notification
    82125    TrkNotifyCreated = 0xa0,
    83126    TrkNotifyDeleted = 0xa1,
    84127    TrkNotifyProcessorStarted = 0xa2,
    85128    TrkNotifyProcessorStandBy = 0xa6,
    86     TrkNotifyProcessorReset = 0xa7
     129    TrkNotifyProcessorReset = 0xa7,
     130
     131    //target -> host support commands (these are defined but not implemented in TRK)
     132    TrkDSWriteFile = 0xd0,
     133    TrkDSReadFile = 0xd1,
     134    TrkDSOpenFile = 0xd2,
     135    TrkDSCloseFile = 0xd3,
     136    TrkDSPositionFile = 0xd4
     137};
     138
     139enum DSOSItemTypes {
     140    kDSOSProcessItem = 0x0000,
     141    kDSOSThreadItem = 0x0001,
     142    kDSOSDLLItem = 0x0002,
     143    kDSOSAppItem = 0x0003,
     144    kDSOSMemBlockItem = 0x0004,
     145    kDSOSProcAttachItem = 0x0005,
     146    kDSOSThreadAttachItem = 0x0006,
     147    kDSOSProcAttach2Item = 0x0007,
     148    kDSOSProcRunItem = 0x0008,
     149    /* 0x0009 - 0x00ff reserved for general expansion */
     150    /* 0x0100 - 0xffff available for target-specific use */
     151};
     152
     153enum SerialMultiplexor {
     154    MuxRaw = 0,
     155    MuxTextTrace = 0x0102,
     156    MuxTrk = 0x0190
    87157};
    88158
     
    90160SYMBIANUTILS_EXPORT ushort extractShort(const char *data);
    91161SYMBIANUTILS_EXPORT uint extractInt(const char *data);
     162SYMBIANUTILS_EXPORT quint64 extractInt64(const char *data);
    92163
    93164SYMBIANUTILS_EXPORT QString quoteUnprintableLatin1(const QByteArray &ba);
     
    109180struct SYMBIANUTILS_EXPORT Library
    110181{
    111     Library() {}
     182    Library();
     183    explicit Library(const TrkResult &r);
    112184
    113185    QByteArray name;
    114186    uint codeseg;
    115187    uint dataseg;
     188     //library addresses are valid for a given process (depending on memory model, they might be loaded at the same address in all processes or not)
     189    uint pid;
    116190};
    117191
     
    119193{
    120194    TrkAppVersion();
    121     void reset();   
     195    void reset();
    122196
    123197    int trkMajor;
     
    132206    void reset();
    133207    QString deviceDescription(unsigned verbose) const;
     208    QString toString() const;
     209    // Answer to qXfer::libraries
     210    QByteArray gdbLibraryList() const;
     211    // Answer to qsDllInfo, can be sent chunk-wise.
     212    QByteArray gdbQsDllInfo(int start = 0, int count = -1) const;
    134213
    135214    // Trk feedback
     
    143222    TrkAppVersion trkAppVersion;
    144223    uint pid;
     224    uint mainTid;
    145225    uint tid;
    146226    uint codeseg;
     
    151231    Libraries libraries;
    152232
    153     typedef uint Thread;
    154     typedef QList<Thread> Threads;
    155     Threads threads;
    156 
    157233    // Gdb request
    158     uint currentThread;
    159234    QStringList modules;
    160235};
     
    169244    QString errorString() const;
    170245
     246    ushort multiplex;
    171247    byte code;
    172248    byte token;
  • trunk/tools/runonphone/symbianutils/trkutils_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5656// the serial frame [0x01 0x90 <len>] and 0x7e encoded7d(ba) 0x7e
    5757QByteArray frameMessage(byte command, byte token, const QByteArray &data, bool serialFrame);
    58 bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *r, QByteArray *rawData = 0);
     58bool extractResult(QByteArray *buffer, bool serialFrame, TrkResult *r, bool& linkEstablishmentMode, QByteArray *rawData = 0);
    5959
    6060} // namespace trk
Note: See TracChangeset for help on using the changeset viewer.