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:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • 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}
Note: See TracChangeset for help on using the changeset viewer.