trkgdbadapter.cpp 74.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

hjk's avatar
hjk committed
30
#include "trkgdbadapter.h"
31

32
#include "launcher.h"
33
#include "trkoptions.h"
34
#include "trkoptionspage.h"
35
#include "symbiandevicemanager.h"
36
37
#include "s60debuggerbluetoothstarter.h"
#include "bluetoothlistener_gui.h"
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
38

39
#include "registerhandler.h"
40
#include "stackhandler.h"
41
#include "debuggeractions.h"
42
#include "debuggerstringutils.h"
43
#include "watchutils.h"
hjk's avatar
hjk committed
44
#ifndef STANDALONE_RUNNER
45
#include "gdbengine.h"
hjk's avatar
hjk committed
46
#endif
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
47
48
49
50
51
52

#include <utils/qtcassert.h>

#include <QtCore/QTimer>
#include <QtCore/QDir>

hjk's avatar
hjk committed
53
54
55
#ifdef Q_OS_WIN
#  include <windows.h>
#else
56
57
58
#  include <sys/types.h>
#  include <unistd.h>
#endif
59

hjk's avatar
hjk committed
60
61
62
63
#define CB(callback) \
    static_cast<GdbEngine::AdapterCallback>(&TrkGdbAdapter::callback), \
    STRINGIFY(callback)

hjk's avatar
hjk committed
64
#define TrkCB(s) TrkCallback(this, &TrkGdbAdapter::s)
65

66
67
68
69
70
71
72
//#define DEBUG_MEMORY  1
#if DEBUG_MEMORY
#   define MEMORY_DEBUG(s) qDebug() << s
#else
#   define MEMORY_DEBUG(s)
#endif
#define MEMORY_DEBUGX(s) qDebug() << s
73
74
75

using namespace trk;

76
77
78
namespace Debugger {
namespace Internal {

79
80
enum { KnownRegisters = RegisterPSGdb + 1};

81
82
static inline void appendByte(QByteArray *ba, trk::byte b) { ba->append(b); }

83
84
85
86
87
88
89
90
91
92
93
static const char *registerNames[KnownRegisters] =
{
    "A1", "A2", "A3", "A4",
    0, 0, 0, 0,
    0, 0, 0, "AP",
    "IP", "SP", "LR", "PC",
    "PSTrk", 0, 0, 0,
    0, 0, 0, 0,
    0, "PSGdb"
};

94
static QByteArray dumpRegister(uint n, uint value)
95
96
97
98
99
100
101
102
103
{
    QByteArray ba;
    ba += ' ';
    if (n < KnownRegisters && registerNames[n]) {
        ba += registerNames[n];
    } else {
        ba += '#';
        ba += QByteArray::number(n);
    }
104
105
    ba += '=';
    ba += hexxNumber(value);
106
107
108
    return ba;
}

109
110
111
112
113
114
115
116
static void appendRegister(QByteArray *ba, uint regno, uint value)
{
    ba->append(hexNumber(regno, 2));
    ba->append(':');
    ba->append(hexNumber(swapEndian(value), 8));
    ba->append(';');
}

117
118
119
120
121
122
123
124
125
126
127
128
QDebug operator<<(QDebug d, MemoryRange range)
{
    return d << QString("[%1,%2] (size %3) ")
        .arg(range.from, 0, 16).arg(range.to, 0, 16).arg(range.size());
}

///////////////////////////////////////////////////////////////////////////
//
// MemoryRange
//
///////////////////////////////////////////////////////////////////////////

129
130
131
MemoryRange::MemoryRange(uint f, uint t)
    : from(f), to(t)
{
132
    QTC_ASSERT(f <= t, qDebug() << "F: " << f << " T: " << t);
133
134
}

135
136
137
bool MemoryRange::intersects(const MemoryRange &other) const
{
    Q_UNUSED(other);
138
    QTC_ASSERT(false, /**/);
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
    return false; // FIXME
}

void MemoryRange::operator-=(const MemoryRange &other)
{
    if (from == 0 && to == 0)
        return;
    MEMORY_DEBUG("      SUB: "  << *this << " - " << other);
    if (other.from <= from && to <= other.to) {
        from = to = 0;
        return;
    }
    if (other.from <= from && other.to <= to) {
        from = qMax(from, other.to);
        return;
    }
    if (from <= other.from && to <= other.to) {
        to = qMin(other.from, to);
        return;
    }
    // This would split the range.
    QTC_ASSERT(false, qDebug() << "Memory::operator-() not handled for: "
        << *this << " - " << other);
}

164
165
166
167
168
bool MemoryRange::isReadOnly() const
{
    return from >= 0x70000000 && to < 0x80000000;
}

169
170
171
172
173
174
175
176
///////////////////////////////////////////////////////////////////////////
//
// Snapshot
//
///////////////////////////////////////////////////////////////////////////

void Snapshot::reset()
{
177
178
179
180
181
182
183
    for (Memory::Iterator it = memory.begin(); it != memory.end(); ++it) {
        if (it.key().isReadOnly()) {
            MEMORY_DEBUG("KEEPING READ-ONLY RANGE" << it.key());
        } else {
            it = memory.erase(it);
        }
    }
184
185
    for (int i = 0; i < RegisterCount; ++i)
        registers[i] = 0;
hjk's avatar
hjk committed
186
    registerValid = false;
187
    wantedMemory = MemoryRange();
188
189
    lineFromAddress = 0;
    lineToAddress = 0;
190
191
}

192
193
194
195
196
197
void Snapshot::fullReset()
{
    memory.clear();
    reset();
}

198
199
void Snapshot::insertMemory(const MemoryRange &range, const QByteArray &ba)
{
200
    QTC_ASSERT(range.size() == uint(ba.size()),
201
        qDebug() << "RANGE: " << range << " BA SIZE: " << ba.size(); return);
202

203
204
205
206
207
208
209
210
211
    MEMORY_DEBUG("INSERT: " << range);
    // Try to combine with existing chunk.
    Snapshot::Memory::iterator it = memory.begin();
    Snapshot::Memory::iterator et = memory.end();
    for ( ; it != et; ++it) {
        if (range.from == it.key().to) {
            MEMORY_DEBUG("COMBINING " << it.key() << " AND " << range);
            QByteArray data = *it;
            data.append(ba);
212
            const MemoryRange res(it.key().from, range.to);
213
            memory.remove(it.key());
214
            MEMORY_DEBUG(" TO(1)  " << res);
215
            insertMemory(res, data);
216
217
218
219
220
221
            return;
        }
        if (it.key().from == range.to) {
            MEMORY_DEBUG("COMBINING " << range << " AND " << it.key());
            QByteArray data = ba;
            data.append(*it);
222
            const MemoryRange res(range.from, it.key().to);
223
            memory.remove(it.key());
224
            MEMORY_DEBUG(" TO(2)  " << res);
225
            insertMemory(res, data);
226
227
228
229
230
231
232
            return;
        }
    }

    // Not combinable, add chunk.
    memory.insert(range, ba);
}
233

234
235
236
237
238
///////////////////////////////////////////////////////////////////////////
//
// TrkGdbAdapter
//
///////////////////////////////////////////////////////////////////////////
239

hjk's avatar
hjk committed
240
241
TrkGdbAdapter::TrkGdbAdapter(GdbEngine *engine, const TrkOptionsPtr &options) :
    AbstractGdbAdapter(engine),
242
243
    m_options(options),
    m_running(false),
244
    m_deviceFromSymbianDeviceManager(false),
245
    m_gdbAckMode(true),
hjk's avatar
hjk committed
246
    m_verbose(0)
247
{
hjk's avatar
hjk committed
248
    m_bufferedMemoryRead = true;
249
250
    // Disable buffering if gdb's dcache is used.
    m_bufferedMemoryRead = false;
hjk's avatar
hjk committed
251

hjk's avatar
hjk committed
252
253
    m_gdbServer = 0;
    m_gdbConnection = 0;
hjk's avatar
hjk committed
254
    m_snapshot.reset();
dt's avatar
dt committed
255
#ifdef Q_OS_WIN
256
    const DWORD portOffset = GetCurrentProcessId() % 100;
dt's avatar
dt committed
257
#else
258
    const uid_t portOffset = getuid();
dt's avatar
dt committed
259
#endif
260
    m_gdbServerName = _("127.0.0.1:%1").arg(2222 + portOffset);
261

262
    setVerbose(theDebuggerBoolSetting(VerboseLog));
263

264
265
    connect(theDebuggerAction(VerboseLog), SIGNAL(valueChanged(QVariant)),
        this, SLOT(setVerbose(QVariant)));
266
267
}

hjk's avatar
hjk committed
268
TrkGdbAdapter::~TrkGdbAdapter()
269
{
Friedemann Kleint's avatar
Friedemann Kleint committed
270
    cleanup();
hjk's avatar
hjk committed
271
    logMessage("Shutting down.\n");
272
273
}

274
275
276
277
278
279
280
281
void TrkGdbAdapter::setVerbose(const QVariant &value)
{
    setVerbose(value.toInt());
}

void TrkGdbAdapter::setVerbose(int verbose)
{
    m_verbose = verbose;
282
283
    if (!m_trkDevice.isNull())
        m_trkDevice->setVerbose(m_verbose);
284
285
}

hjk's avatar
hjk committed
286
void TrkGdbAdapter::trkLogMessage(const QString &msg)
287
288
289
290
{
    logMessage("TRK " + msg);
}

hjk's avatar
hjk committed
291
void TrkGdbAdapter::setGdbServerName(const QString &name)
292
293
294
295
{
    m_gdbServerName = name;
}

hjk's avatar
hjk committed
296
QString TrkGdbAdapter::gdbServerIP() const
297
298
299
300
301
302
303
{
    int pos = m_gdbServerName.indexOf(':');
    if (pos == -1)
        return m_gdbServerName;
    return m_gdbServerName.left(pos);
}

hjk's avatar
hjk committed
304
uint TrkGdbAdapter::gdbServerPort() const
305
306
307
308
309
310
311
{
    int pos = m_gdbServerName.indexOf(':');
    if (pos == -1)
        return 0;
    return m_gdbServerName.mid(pos + 1).toUInt();
}

hjk's avatar
hjk committed
312
QByteArray TrkGdbAdapter::trkContinueMessage()
313
314
315
316
317
318
319
{
    QByteArray ba;
    appendInt(&ba, m_session.pid);
    appendInt(&ba, m_session.tid);
    return ba;
}

320
QByteArray TrkGdbAdapter::trkReadRegistersMessage()
321
322
323
324
325
326
327
328
329
330
{
    QByteArray ba;
    appendByte(&ba, 0); // Register set, only 0 supported
    appendShort(&ba, 0);
    appendShort(&ba, RegisterCount - 1); // last register
    appendInt(&ba, m_session.pid);
    appendInt(&ba, m_session.tid);
    return ba;
}

331
   QByteArray TrkGdbAdapter::trkWriteRegisterMessage(trk::byte reg, uint value)
332
333
334
335
336
337
338
339
340
341
342
{
    QByteArray ba;
    appendByte(&ba, 0); // ?
    appendShort(&ba, reg);
    appendShort(&ba, reg);
    appendInt(&ba, m_session.pid);
    appendInt(&ba, m_session.tid);
    appendInt(&ba, value);
    return ba;
}

343
QByteArray TrkGdbAdapter::trkReadMemoryMessage(uint from, uint len)
344
345
{
    QByteArray ba;
346
    ba.reserve(11);
347
348
    appendByte(&ba, 0x08); // Options, FIXME: why?
    appendShort(&ba, len);
349
    appendInt(&ba, from);
350
351
352
353
354
    appendInt(&ba, m_session.pid);
    appendInt(&ba, m_session.tid);
    return ba;
}

355
356
357
358
359
QByteArray TrkGdbAdapter::trkReadMemoryMessage(const MemoryRange &range)
{
    return trkReadMemoryMessage(range.from, range.size());
}

hjk's avatar
hjk committed
360
361
362
363
364
365
366
367
368
369
370
371
372
QByteArray TrkGdbAdapter::trkWriteMemoryMessage(uint addr, const QByteArray &data)
{
    QByteArray ba;
    ba.reserve(11 + data.size());
    appendByte(&ba, 0x08); // Options, FIXME: why?
    appendShort(&ba, data.size());
    appendInt(&ba, addr);
    appendInt(&ba, m_session.pid);
    appendInt(&ba, m_session.tid);
    ba.append(data);
    return ba;
}

373
QByteArray TrkGdbAdapter::trkStepRangeMessage()
hjk's avatar
hjk committed
374
{
375
    //qDebug() << "STEP ON " << hexxNumber(m_snapshot.registers[RegisterPC]);
376
377
378
    uint from = m_snapshot.lineFromAddress;
    uint to = m_snapshot.lineToAddress;
    uint pc = m_snapshot.registers[RegisterPC];
379
    trk::byte option = 0x01; // Step into.
380
381
    if (m_snapshot.stepOver)
        option = 0x11;  // Step over.
382
    if (from <= pc && pc <= to) {
383
        //to = qMax(to - 4, from);
384
385
        debugMessage("STEP IN " + hexxNumber(from) + " " + hexxNumber(to)
            + " INSTEAD OF " + hexxNumber(pc));
386
387
388
389
    } else {
        from = pc;
        to = pc;
    }
390

391
    //qDebug() << "USING" << int(option) << (option == 1 ? " INTO " : " OVER");
392
393
394
    QByteArray ba;
    ba.reserve(17);
    appendByte(&ba, option);
395
396
    appendInt(&ba, from); // Start address
    appendInt(&ba, to); // End address
hjk's avatar
hjk committed
397
398
399
400
401
    appendInt(&ba, m_session.pid);
    appendInt(&ba, m_session.tid);
    return ba;
}

402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
QByteArray TrkGdbAdapter::trkDeleteProcessMessage()
{
    QByteArray ba;
    ba.reserve(6);
    appendByte(&ba, 0); // ?
    appendByte(&ba, 0); // Sub-command: Delete Process
    appendInt(&ba, m_session.pid);
    return ba;
}

QByteArray TrkGdbAdapter::trkInterruptMessage()
{
    QByteArray ba;
    ba.reserve(9);
    // Stop the thread (2) or the process (1) or the whole system (0).
    // We choose 2, as 1 does not seem to work.
    appendByte(&ba, 2);
    appendInt(&ba, m_session.pid);
    appendInt(&ba, m_session.tid); // threadID: 4 bytes Variable number of bytes.
    return ba;
}

424
425
426
427
428
429
430
431
432
433
434
void TrkGdbAdapter::emitDelayedInferiorStartFailed(const QString &msg)
{
    m_adapterFailMessage = msg;
    QTimer::singleShot(0, this, SLOT(slotEmitDelayedInferiorStartFailed()));
}

void TrkGdbAdapter::slotEmitDelayedInferiorStartFailed()
{
    emit inferiorStartFailed(m_adapterFailMessage);
}

435

hjk's avatar
hjk committed
436
void TrkGdbAdapter::logMessage(const QString &msg)
437
{
438
439
    if (m_verbose)
        debugMessage("TRK LOG: " + msg);
440
441
442
443
444
}

//
// Gdb
//
hjk's avatar
hjk committed
445
void TrkGdbAdapter::handleGdbConnection()
446
447
{
    logMessage("HANDLING GDB CONNECTION");
hjk's avatar
hjk committed
448
449
450
    QTC_ASSERT(m_gdbConnection == 0, /**/);
    m_gdbConnection = m_gdbServer->nextPendingConnection();
    QTC_ASSERT(m_gdbConnection, return);
451
452
453
454
455
456
457
458
459
460
461
    connect(m_gdbConnection, SIGNAL(disconnected()),
            m_gdbConnection, SLOT(deleteLater()));
    connect(m_gdbConnection, SIGNAL(readyRead()),
            this, SLOT(readGdbServerCommand()));
}

static inline QString msgGdbPacket(const QString &p)
{
    return QLatin1String("gdb:                              ") + p;
}

hjk's avatar
hjk committed
462
void TrkGdbAdapter::readGdbServerCommand()
463
{
hjk's avatar
hjk committed
464
    QTC_ASSERT(m_gdbConnection, return);
465
466
467
    QByteArray packet = m_gdbConnection->readAll();
    m_gdbReadBuffer.append(packet);

468
    logMessage("gdb: -> " + currentTime() + ' ' + QString::fromAscii(packet));
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
    if (packet != m_gdbReadBuffer)
        logMessage("buffer: " + m_gdbReadBuffer);

    QByteArray &ba = m_gdbReadBuffer;
    while (ba.size()) {
        char code = ba.at(0);
        ba = ba.mid(1);

        if (code == '+') {
            //logMessage("ACK");
            continue;
        }

        if (code == '-') {
            logMessage("NAK: Retransmission requested");
484
485
            // This seems too harsh.
            //emit adapterCrashed("Communication problem encountered.");
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
            continue;
        }

        if (code == char(0x03)) {
            logMessage("INTERRUPT RECEIVED");
            interruptInferior();
            continue;
        }

        if (code != '$') {
            logMessage("Broken package (2) " + quoteUnprintableLatin1(ba)
                + hexNumber(code));
            continue;
        }

        int pos = ba.indexOf('#');
        if (pos == -1) {
            logMessage("Invalid checksum format in "
                + quoteUnprintableLatin1(ba));
            continue;
        }

        bool ok = false;
        uint checkSum = ba.mid(pos + 1, 2).toUInt(&ok, 16);
        if (!ok) {
            logMessage("Invalid checksum format 2 in "
                + quoteUnprintableLatin1(ba));
            return;
        }

        //logMessage(QString("Packet checksum: %1").arg(checkSum));
517
        trk::byte sum = 0;
518
519
520
521
522
523
524
525
526
527
528
529
530
531
        for (int i = 0; i < pos; ++i)
            sum += ba.at(i);

        if (sum != checkSum) {
            logMessage(QString("ERROR: Packet checksum wrong: %1 %2 in "
                + quoteUnprintableLatin1(ba)).arg(checkSum).arg(sum));
        }

        QByteArray cmd = ba.left(pos);
        ba.remove(0, pos + 3);
        handleGdbServerCommand(cmd);
    }
}

hjk's avatar
hjk committed
532
bool TrkGdbAdapter::sendGdbServerPacket(const QByteArray &packet, bool doFlush)
533
534
{
    if (!m_gdbConnection) {
535
536
        logMessage(_("Cannot write to gdb: No connection (%1)")
            .arg(_(packet)));
537
538
539
        return false;
    }
    if (m_gdbConnection->state() != QAbstractSocket::ConnectedState) {
540
541
        logMessage(_("Cannot write to gdb: Not connected (%1)")
            .arg(_(packet)));
542
543
544
        return false;
    }
    if (m_gdbConnection->write(packet) == -1) {
545
546
        logMessage(_("Cannot write to gdb: %1 (%2)")
            .arg(m_gdbConnection->errorString()).arg(_(packet)));
547
548
549
550
551
552
553
        return false;
    }
    if (doFlush)
        m_gdbConnection->flush();
    return true;
}

hjk's avatar
hjk committed
554
void TrkGdbAdapter::sendGdbServerAck()
555
556
557
{
    if (!m_gdbAckMode)
        return;
hjk's avatar
hjk committed
558
    logMessage("gdb: <- +");
559
    sendGdbServerPacket(QByteArray(1, '+'), false);
560
561
}

hjk's avatar
hjk committed
562
void TrkGdbAdapter::sendGdbServerMessage(const QByteArray &msg, const QByteArray &logNote)
563
{
564
    trk::byte sum = 0;
565
566
567
568
569
570
571
572
573
    for (int i = 0; i != msg.size(); ++i)
        sum += msg.at(i);

    char checkSum[30];
    qsnprintf(checkSum, sizeof(checkSum) - 1, "%02x ", sum);

    //logMessage(QString("Packet checksum: %1").arg(sum));

    QByteArray packet;
574
    packet.append('$');
575
576
577
578
    packet.append(msg);
    packet.append('#');
    packet.append(checkSum);
    int pad = qMax(0, 24 - packet.size());
579
    logMessage("gdb: <- " + currentTime() + ' ' + packet + QByteArray(pad, ' ') + logNote);
580
581
582
    sendGdbServerPacket(packet, true);
}

hjk's avatar
hjk committed
583
void TrkGdbAdapter::sendGdbServerMessageAfterTrkResponse(const QByteArray &msg,
584
585
586
587
588
589
    const QByteArray &logNote)
{
    QByteArray ba = msg + char(1) + logNote;
    sendTrkMessage(TRK_WRITE_QUEUE_NOOP_CODE, TrkCB(reportToGdb), "", ba); // Answer gdb
}

hjk's avatar
hjk committed
590
void TrkGdbAdapter::reportToGdb(const TrkResult &result)
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
{
    QByteArray message = result.cookie.toByteArray();
    QByteArray note;
    int pos = message.lastIndexOf(char(1)); // HACK
    if (pos != -1) {
        note = message.mid(pos + 1);
        message = message.left(pos);
    }
    message.replace("@CODESEG@", hexNumber(m_session.codeseg));
    message.replace("@DATASEG@", hexNumber(m_session.dataseg));
    message.replace("@PID@", hexNumber(m_session.pid));
    message.replace("@TID@", hexNumber(m_session.tid));
    sendGdbServerMessage(message, note);
}

hjk's avatar
hjk committed
606
QByteArray TrkGdbAdapter::trkBreakpointMessage(uint addr, uint len, bool armMode)
607
608
609
610
611
612
613
614
615
616
617
618
{
    QByteArray ba;
    appendByte(&ba, 0x82);  // unused option
    appendByte(&ba, armMode /*bp.mode == ArmMode*/ ? 0x00 : 0x01);
    appendInt(&ba, addr);
    appendInt(&ba, len);
    appendInt(&ba, 0x00000001);
    appendInt(&ba, m_session.pid);
    appendInt(&ba, 0xFFFFFFFF);
    return ba;
}

hjk's avatar
hjk committed
619
void TrkGdbAdapter::handleGdbServerCommand(const QByteArray &cmd)
620
621
622
623
624
625
626
627
628
629
{
    // http://sourceware.org/gdb/current/onlinedocs/gdb_34.html
    if (0) {}

    else if (cmd == "!") {
        sendGdbServerAck();
        //sendGdbServerMessage("", "extended mode not enabled");
        sendGdbServerMessage("OK", "extended mode enabled");
    }

630
    else if (cmd.startsWith('?')) {
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
        logMessage(msgGdbPacket(QLatin1String("Query halted")));
        // Indicate the reason the target halted.
        // The reply is the same as for step and continue.
        sendGdbServerAck();
        // The command below will trigger fetching a stack trace while
        // the process does not seem to be fully functional. Most notably
        // the PC points to a 0x9..., which is not in "our" range
        //sendGdbServerMessage("T05library:r;", "target halted (library load)");
        //sendGdbServerMessage("S05", "target halted (trap)");
        sendGdbServerMessage("S00", "target halted (trap)");
        //sendGdbServerMessage("O" + QByteArray("Starting...").toHex());
    }

    else if (cmd == "c") {
        logMessage(msgGdbPacket(QLatin1String("Continue")));
        sendGdbServerAck();
        QByteArray ba;
        appendByte(&ba, 0); // options
        appendInt(&ba, 0); // start address
        appendInt(&ba, 0); // end address
        appendInt(&ba, m_session.pid);
        appendInt(&ba, m_session.tid);
        sendTrkMessage(0x18, TrkCallback(), ba);
    }

656
    else if (cmd.startsWith('C')) {
657
658
659
660
661
        logMessage(msgGdbPacket(QLatin1String("Continue with signal")));
        // C sig[;addr] Continue with signal sig (hex signal number)
        //Reply: See section D.3 Stop Reply Packets, for the reply specifications.
        sendGdbServerAck();
        bool ok = false;
662
        uint signalNumber = cmd.mid(1).toUInt(&ok, 16);
663
664
665
        QByteArray ba;
        appendInt(&ba, m_session.pid);
        appendInt(&ba, m_session.tid);
hjk's avatar
hjk committed
666
        sendTrkMessage(0x18, TrkCB(handleSignalContinue), ba, signalNumber);
667
668
    }

669
    else if (cmd.startsWith('D')) {
670
671
672
673
674
675
        sendGdbServerAck();
        sendGdbServerMessage("OK", "shutting down");
    }

    else if (cmd == "g") {
        // Read general registers.
hjk's avatar
hjk committed
676
        if (m_snapshot.registerValid) {
677
            //qDebug() << "Using cached register contents";
hjk's avatar
hjk committed
678
679
680
681
            logMessage(msgGdbPacket(QLatin1String("Read registers")));
            sendGdbServerAck();
            reportRegisters();
        } else {
682
683
            //qDebug() << "Fetching register contents";
            sendGdbServerAck();
hjk's avatar
hjk committed
684
685
686
687
            sendTrkMessage(0x12,
                TrkCB(handleAndReportReadRegisters),
                trkReadRegistersMessage());
        }
688
689
    }

690
691
692
693
694
695
696
697
698
    else if (cmd == "gg") {
        // Force re-reading general registers for debugging purpose.
        sendGdbServerAck();
        m_snapshot.registerValid = false;
        sendTrkMessage(0x12,
            TrkCB(handleAndReportReadRegisters),
            trkReadRegistersMessage());
    }

699
    else if (cmd.startsWith("salstep,")) {
700
701
        // Receive address range for current line for future use when stepping.
        sendGdbServerAck();
702
        int pos = cmd.indexOf(',', 8);
703
        m_snapshot.lineFromAddress = cmd.mid(8, pos - 8).toUInt(0, 16);
704
        m_snapshot.lineToAddress = cmd.mid(pos + 1).toUInt(0, 16);
705
706
707
708
        m_snapshot.stepOver = false;
        sendGdbServerMessage("", "Stepping range received for Step Into");
    }

709
    else if (cmd.startsWith("salnext,")) {
710
711
        // Receive address range for current line for future use when stepping.
        sendGdbServerAck();
712
        int pos = cmd.indexOf(',', 8);
713
714
715
716
        m_snapshot.lineFromAddress = cmd.mid(8, pos - 8).toUInt(0, 16);
        m_snapshot.lineToAddress = cmd.mid(pos + 1).toUInt(0, 16);
        m_snapshot.stepOver = true;
        sendGdbServerMessage("", "Stepping range received for Step Over");
717
718
    }

719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
    else if (cmd.startsWith("Hc")) {
        logMessage(msgGdbPacket(QLatin1String("Set thread & continue")));
        // Set thread for subsequent operations (`m', `M', `g', `G', et.al.).
        // for step and continue operations
        //$Hc-1#09
        sendGdbServerAck();
        sendGdbServerMessage("OK", "Set current thread for step & continue");
    }

    else if (cmd.startsWith("Hg")) {
        logMessage(msgGdbPacket(QLatin1String("Set thread")));
        // Set thread for subsequent operations (`m', `M', `g', `G', et.al.).
        // for 'other operations.  0 - any thread
        //$Hg0#df
        sendGdbServerAck();
734
        m_session.currentThread = cmd.mid(2).toUInt(0, 16);
735
736
737
738
        sendGdbServerMessage("OK", "Set current thread "
            + QByteArray::number(m_session.currentThread));
    }

hjk's avatar
hjk committed
739
740
    else if (cmd == "k" || cmd.startsWith("vKill")) {
        // Kill inferior process
741
        logMessage(msgGdbPacket(QLatin1String("kill")));
hjk's avatar
hjk committed
742
        sendTrkMessage(0x41, TrkCB(handleDeleteProcess),
743
            trkDeleteProcessMessage(), "Delete process");
744
745
    }

746
    else if (cmd.startsWith('m')) {
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
        logMessage(msgGdbPacket(QLatin1String("Read memory")));
        // m addr,length
        sendGdbServerAck();
        uint addr = 0, len = 0;
        do {
            const int pos = cmd.indexOf(',');
            if (pos == -1)
                break;
            bool ok;
            addr = cmd.mid(1, pos - 1).toUInt(&ok, 16);
            if (!ok)
                break;
            len = cmd.mid(pos + 1).toUInt(&ok, 16);
            if (!ok)
                break;
        } while (false);
        if (len) {
764
            readMemory(addr, len, m_bufferedMemoryRead);
765
766
767
768
        } else {
            sendGdbServerMessage("E20", "Error " + cmd);
        }
    }
769

770
    else if (cmd.startsWith('p')) {
771
772
773
774
775
        logMessage(msgGdbPacket(QLatin1String("read register")));
        // 0xf == current instruction pointer?
        //sendGdbServerMessage("0000", "current IP");
        sendGdbServerAck();
        bool ok = false;
776
        const uint registerNumber = cmd.mid(1).toUInt(&ok, 16);
hjk's avatar
hjk committed
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
        if (m_snapshot.registerValid) {
            QByteArray logMsg = "Read Register";
            if (registerNumber == RegisterPSGdb) {
                QByteArray ba;
                appendInt(&ba, m_snapshot.registers[RegisterPSTrk], LittleEndian);
                logMsg += dumpRegister(registerNumber, m_snapshot.registers[RegisterPSTrk]);
                sendGdbServerMessage(ba.toHex(), logMsg);
            } else if (registerNumber < 16) {
                QByteArray ba;
                appendInt(&ba, m_snapshot.registers[registerNumber], LittleEndian);
                logMsg += dumpRegister(registerNumber, m_snapshot.registers[registerNumber]);
                sendGdbServerMessage(ba.toHex(), logMsg);
            } else {
                sendGdbServerMessage("0000", "read single unknown register #"
                    + QByteArray::number(registerNumber));
                //sendGdbServerMessage("E01", "read single unknown register");
            }
794
        } else {
795
            //qDebug() << "Fetching single register";
hjk's avatar
hjk committed
796
797
798
            sendTrkMessage(0x12,
                TrkCB(handleAndReportReadRegister),
                trkReadRegistersMessage(), registerNumber);
799
800
801
        }
    }

802
    else if (cmd.startsWith('P')) {
803
804
805
806
807
808
809
        logMessage(msgGdbPacket(QLatin1String("write register")));
        // $Pe=70f96678#d3
        sendGdbServerAck();
        int pos = cmd.indexOf('=');
        QByteArray regName = cmd.mid(1, pos - 1);
        QByteArray valueName = cmd.mid(pos + 1);
        bool ok = false;
810
811
        const uint registerNumber = regName.toUInt(&ok, 16);
        const uint value = swapEndian(valueName.toUInt(&ok, 16));
812
813
        // FIXME: Assume all goes well.
        m_snapshot.registers[registerNumber] = value;
814
815
816
817
818
        QByteArray ba = trkWriteRegisterMessage(registerNumber, value);
        sendTrkMessage(0x13, TrkCB(handleWriteRegister), ba, "Write register");
        // Note that App TRK refuses to write registers 13 and 14
    }

819
820
821
822
823
    else if (cmd == "qAttached") {
        //$qAttached#8f
        // 1: attached to an existing process
        // 0: created a new process
        sendGdbServerAck();
824
825
        sendGdbServerMessage(QByteArray(1, '0'), "new process created");
        //sendGdbServerMessage('1', "attached to existing process");
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
        //sendGdbServerMessage("E01", "new process created");
    }

    else if (cmd.startsWith("qC")) {
        logMessage(msgGdbPacket(QLatin1String("query thread id")));
        // Return the current thread ID
        //$qC#b4
        sendGdbServerAck();
        sendGdbServerMessageAfterTrkResponse("QC@TID@");
    }

    else if (cmd.startsWith("qSupported")) {
        //$qSupported#37
        //$qSupported:multiprocess+#c6
        //logMessage("Handling 'qSupported'");
        sendGdbServerAck();
hjk's avatar
hjk committed
842
843
844
        sendGdbServerMessage(
            "PacketSize=7cf;"
            "QPassSignals+;"
hjk's avatar
hjk committed
845
            "QStartNoAckMode+;"
hjk's avatar
hjk committed
846
847
848
849
850
            "qXfer:libraries:read+;"
            //"qXfer:auxv:read+;"
            "qXfer:features:read+");
    }

851
852
853
854
855
856
    else if (cmd.startsWith("qThreadExtraInfo")) {
        // $qThreadExtraInfo,1f9#55
        sendGdbServerAck();
        sendGdbServerMessage(QByteArray("Nothing special").toHex());
    }

hjk's avatar
hjk committed
857
    else if (cmd == "qfDllInfo") {
858
859
860
861
862
863
        // That's the _first_ query package.
        // Happens with  gdb 6.4.50.20060226-cvs / CodeSourcery.
        // Never made it into FSF gdb that got qXfer:libraries:read instead.
        // http://sourceware.org/ml/gdb/2007-05/msg00038.html
        // Name=hexname,TextSeg=textaddr[,DataSeg=dataaddr]
        sendGdbServerAck();
864
        if (!m_session.libraries.isEmpty()) {
865
            QByteArray response(1, 'm');
866
867
868
869
870
871
872
873
874
            // FIXME: Limit packet length by using qsDllInfo packages?
            for (int i = 0; i != m_session.libraries.size(); ++i) {
                if (i)
                    response += ';';
                const Library &lib = m_session.libraries.at(i);
                response += "Name=" + lib.name.toHex()
                            + ",TextSeg=" + hexNumber(lib.codeseg)
                            + ",DataSeg=" + hexNumber(lib.dataseg);
            }
Tobias Hunger's avatar
Tobias Hunger committed
875
            sendGdbServerMessage(response, "library information transferred");
876
        } else {
877
            sendGdbServerMessage(QByteArray(1, 'l'), "library information transfer finished");
878
879
880
881
882
        }
    }

    else if (cmd == "qsDllInfo") {
        // That's a following query package
hjk's avatar
hjk committed
883
        sendGdbServerAck();
884
        sendGdbServerMessage(QByteArray(1, 'l'), "library information transfer finished");
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
    }

    else if (cmd == "qPacketInfo") {
        // happens with  gdb 6.4.50.20060226-cvs / CodeSourcery
        // deprecated by qSupported?
        sendGdbServerAck();
        sendGdbServerMessage("", "FIXME: nothing?");
    }

    else if (cmd == "qOffsets") {
        sendGdbServerAck();
        sendGdbServerMessageAfterTrkResponse("TextSeg=@CODESEG@;DataSeg=@DATASEG@");
    }

    else if (cmd == "qSymbol::") {
        if (m_verbose)
            logMessage(msgGdbPacket(QLatin1String("notify can handle symbol lookup")));
        // Notify the target that GDB is prepared to serve symbol lookup requests.
        sendGdbServerAck();
        if (1)
            sendGdbServerMessage("OK", "no further symbols needed");
        else
hjk's avatar
hjk committed
907
908
            sendGdbServerMessage("qSymbol:" + QByteArray("_Z7E32Mainv").toHex(),
                "ask for more");
909
910
911
912
913
    }

    else if (cmd.startsWith("qXfer:features:read:target.xml:")) {
        //  $qXfer:features:read:target.xml:0,7ca#46...Ack
        sendGdbServerAck();
hjk's avatar
hjk committed
914
915
916
917
918
919
920
921
922
        //sendGdbServerMessage("l<target><architecture>symbianelf</architecture></target>");
        sendGdbServerMessage("l<target><architecture>arm</architecture></target>");
        //sendGdbServerMessage("l<target><architecture>arm-none-symbianelf</architecture></target>");
    }

    else if (cmd == "qfThreadInfo") {
        // That's the _first_ query package.
        sendGdbServerAck();
        if (!m_session.threads.isEmpty()) {
923
            QByteArray response(1, 'm');
hjk's avatar
hjk committed
924
925
926
            // FIXME: Limit packet length by using qsThreadInfo packages?
            qDebug()  << "CURRENT THREAD: " << m_session.tid;
            response += hexNumber(m_session.tid);
Tobias Hunger's avatar
Tobias Hunger committed
927
            sendGdbServerMessage(response, "thread information transferred");
hjk's avatar
hjk committed
928
        } else {
929
            sendGdbServerMessage(QByteArray(1, 'l'), "thread information transfer finished");
hjk's avatar
hjk committed
930
931
932
933
934
935
        }
    }

    else if (cmd == "qsThreadInfo") {
        // That's a following query package
        sendGdbServerAck();
936
        sendGdbServerMessage(QByteArray(1, 'l'), "thread information transfer finished");
937
938
    }

939
    else if (cmd.startsWith("qXfer:libraries:read")) {
940
        //qDebug() << "COMMAND: " << cmd;
941
        sendGdbServerAck();
hjk's avatar
hjk committed
942
943
944
945
        QByteArray response = "l<library-list>";
        for (int i = 0; i != m_session.libraries.size(); ++i) {
            const Library &lib = m_session.libraries.at(i);
            response += "<library name=\"" + lib.name + "\">";
946
947
948
949
            //response += "<segment address=\"0x" + hexNumber(lib.codeseg) + "\"/>";
            response += "<section address=\"0x" + hexNumber(lib.codeseg) + "\"/>";
            response += "<section address=\"0x" + hexNumber(lib.dataseg) + "\"/>";
            response += "<section address=\"0x" + hexNumber(lib.dataseg) + "\"/>";
hjk's avatar
hjk committed
950
951
952
            response += "</library>";
        }
        response += "</library-list>";
Tobias Hunger's avatar
Tobias Hunger committed
953
        sendGdbServerMessage(response, "library information transferred");
954
955
    }

956
957
    else if (cmd == "QStartNoAckMode") {
        //$qSupported#37
hjk's avatar
hjk committed
958
        logMessage("Handling 'QStartNoAckMode'");
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
        sendGdbServerAck();
        sendGdbServerMessage("OK", "ack no-ack mode");
        m_gdbAckMode = false;
    }

    else if (cmd.startsWith("QPassSignals")) {
        // list of signals to pass directly to inferior
        // $QPassSignals:e;10;14;17;1a;1b;1c;21;24;25;4c;#8f
        // happens only if "QPassSignals+;" is qSupported
        sendGdbServerAck();
        // FIXME: use the parameters
        sendGdbServerMessage("OK", "passing signals accepted");
    }

    else if (cmd == "s" || cmd.startsWith("vCont;s")) {
        logMessage(msgGdbPacket(QLatin1String("Step range")));
        logMessage("  from " + hexxNumber(m_snapshot.registers[RegisterPC]));
        sendGdbServerAck();
977
        //m_snapshot.reset();
978
        m_running = true;
979
980
        QByteArray ba = trkStepRangeMessage();
        sendTrkMessage(0x19, TrkCB(handleStep), ba, "Step range");
981
982
    }

hjk's avatar
hjk committed
983
984
985
986
987
988
989
    else if (cmd.startsWith('T')) {
        // FIXME: check whether thread is alive
        sendGdbServerAck();
        sendGdbServerMessage("OK"); // pretend all is well
        //sendGdbServerMessage("E nn");
    }

990
991
992
993
    else if (cmd == "vCont?") {
        // actions supported by the vCont packet
        sendGdbServerAck();
        //sendGdbServerMessage("OK"); // we don't support vCont.
994
        sendGdbServerMessage("vCont;c;C;s;S");
995
996
997
998
999
    }

    else if (cmd == "vCont;c") {
        // vCont[;action[:thread-id]]...'
        sendGdbServerAck();
1000
        //m_snapshot.reset();
1001
1002
1003
1004
1005
1006
        m_running = true;
        sendTrkMessage(0x18, TrkCallback(), trkContinueMessage(), "CONTINUE");
    }

    else if (cmd.startsWith("Z0,") || cmd.startsWith("Z1,")) {
        // Insert breakpoint
hjk's avatar
hjk committed
1007
        sendGdbServerAck();
1008
1009
1010
        logMessage(msgGdbPacket(QLatin1String("Insert breakpoint")));
        // $Z0,786a4ccc,4#99
        const int pos = cmd.lastIndexOf(',');
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
        bool ok1 = false;
        bool ok2 = false;
        const uint addr = cmd.mid(3, pos - 3).toUInt(&ok1, 16);
        const uint len = cmd.mid(pos + 1).toUInt(&ok2, 16);
        if (!ok1) {
            logMessage("MISPARSED ADDRESS FROM " + cmd +
                " (" + cmd.mid(3, pos - 3) + ")");
        } else if (!ok2) {
            logMessage("MISPARSED BREAKPOINT SIZE FROM " + cmd);
        } else {
            //qDebug() << "ADDR: " << hexNumber(addr) << " LEN: " << len;
            logMessage(_("Inserting breakpoint at 0x%1, %2")
                .arg(addr, 0, 16).arg(len));
            const QByteArray ba = trkBreakpointMessage(addr, len, len == 4);
            sendTrkMessage(0x1B, TrkCB(handleAndReportSetBreakpoint), ba, addr);
        }
1027
1028
1029
1030
    }

    else if (cmd.startsWith("z0,") || cmd.startsWith("z1,")) {
        // Remove breakpoint
hjk's avatar
hjk committed
1031
        sendGdbServerAck();
1032
1033
1034
1035
        logMessage(msgGdbPacket(QLatin1String("Remove breakpoint")));
        // $z0,786a4ccc,4#99
        const int pos = cmd.lastIndexOf(',');
        bool ok = false;
1036
1037
        const uint addr = cmd.mid(3, pos - 3).toUInt(&ok, 16);
        const uint len = cmd.mid(pos + 1).toUInt(&ok, 16);
1038
1039
        const uint bp = m_session.addressToBP[addr];
        if (bp == 0) {
1040
            logMessage(_("NO RECORDED BP AT 0x%1, %2")
1041
                .arg(addr, 0, 16).arg(len));
hjk's avatar
hjk committed
1042
            sendGdbServerMessage("E00");
1043
1044
1045
        } else {
            m_session.addressToBP.remove(addr);
            QByteArray ba;
1046
            appendInt(&ba, bp);
1047
1048
1049
1050
1051
            sendTrkMessage(0x1C, TrkCB(handleClearBreakpoint), ba, addr);
        }
    }

    else if (cmd.startsWith("qPart:") || cmd.startsWith("qXfer:"))  {
hjk's avatar
hjk committed
1052
        QByteArray data = cmd.mid(1 + cmd.indexOf(':'));
1053
1054
1055
1056
1057
        // "qPart:auxv:read::0,147": Read OS auxiliary data (see info aux)
        bool handled = false;
        if (data.startsWith("auxv:read::")) {
            const int offsetPos = data.lastIndexOf(':') + 1;
            const int commaPos = data.lastIndexOf(',');
1058
            if (commaPos != -1) {
1059
1060
                bool ok1 = false, ok2 = false;
                const int offset = data.mid(offsetPos,  commaPos - offsetPos)
1061
1062
                    .toUInt(&ok1, 16);
                const int length = data.mid(commaPos + 1).toUInt(&ok2, 16);
1063
                if (ok1 && ok2) {
Tobias Hunger's avatar
Tobias Hunger committed
1064
                    const QString msg = _("Read of OS auxiliary "
1065
                        "vector (%1, %2) not implemented.").arg(offset).arg(length);
hjk's avatar
hjk committed
1066
                    logMessage(msgGdbPacket(msg));
1067
1068
1069
1070
1071
                    sendGdbServerMessage("E20", msg.toLatin1());
                    handled = true;
                }
            }
        } // auxv read
hjk's avatar
hjk committed
1072

1073
1074
1075
        if (!handled) {
            const QString msg = QLatin1String("FIXME unknown 'XFER'-request: ")
                + QString::fromAscii(cmd);
hjk's avatar
hjk committed
1076
            logMessage(msgGdbPacket(msg));
1077
1078
1079
1080
1081
1082
1083
1084
1085
            sendGdbServerMessage("E20", msg.toLatin1());
        }
    } // qPart/qXfer
    else {
        logMessage(msgGdbPacket(QLatin1String("FIXME unknown: ")
            + QString::fromAscii(cmd)));
    }
}

1086
void TrkGdbAdapter::sendTrkMessage(trk::byte code, TrkCallback callback,
1087
1088
    const QByteArray &data, const QVariant &cookie)
{
1089
1090
1091
    if (m_verbose >= 2)
        logMessage("trk: -> " + QByteArray::number(code, 16) + "  "
            + stringFromArray(data));
1092
    m_trkDevice->sendTrkMessage(code, callback, data, cookie);
1093
1094
}

1095
void TrkGdbAdapter::sendTrkAck(trk::byte token)
1096
{
1097
    //logMessage(QString("SENDING ACKNOWLEDGEMENT FOR TOKEN %1").arg(int(token)));
1098
    m_trkDevice->sendTrkAck(token);
1099
1100
}

hjk's avatar
hjk committed
1101
void TrkGdbAdapter::handleTrkError(const QString &msg)
1102
1103
{
    logMessage("## TRK ERROR: " + msg);
1104
    emit adapterCrashed("TRK problem encountered:\n" + msg);
1105
1106
}

hjk's avatar
hjk committed
1107
void TrkGdbAdapter::handleTrkResult(const TrkResult &result)
1108
{
1109
1110
    if (m_verbose >= 2)
        logMessage("trk: <- " + result.toString());
1111
    if (result.isDebugOutput) {
1112
1113
1114
        // It looks like those messages _must not_ be acknowledged.
        // If we do so, TRK will complain about wrong sequencing.
        //sendTrkAck(result.token);
1115
1116
1117
1118
1119
        logMessage(QLatin1String("APPLICATION OUTPUT: ") +
            QString::fromAscii(result.data));
        sendGdbServerMessage("O" + result.data.toHex());
        return;
    }
1120
    //logMessage("READ TRK " + result.toString());
1121
1122
1123
1124
1125
1126
1127
1128
1129
    QByteArray prefix = "READ BUF:                                       ";
    QByteArray str = result.toString().toUtf8();
    switch (result.code) {
        case 0x80: // ACK
            break;
        case 0xff: { // NAK. This mostly means transmission error, not command failed.
            QString logMsg;
            QTextStream(&logMsg) << prefix << "NAK: for token=" << result.token
                << " ERROR: " << errorMessage(result.data.at(0)) << ' ' << str;
hjk's avatar
hjk committed
1130
            logMessage(logMsg);
1131
1132
            break;
        }
Friedemann Kleint's avatar
Friedemann Kleint committed
1133
        case TrkNotifyStopped: {  // 0x90 Notified Stopped
1134
            // 90 01   78 6a 40 40   00 00 07 23   00 00 07 24  00 00
1135
1136
            debugMessage(_("RESET SNAPSHOT (NOTIFY STOPPED)"));
            m_snapshot.reset();
1137
1138
1139
1140
1141
1142
1143
1144
            QString reason;
            uint addr;
            uint pid;
            uint tid;
            trk::Launcher::parseNotifyStopped(result.data, &pid, &tid, &addr, &reason);
            const QString msg = trk::Launcher::msgStopped(pid, tid, addr, reason);
            logMessage(prefix + msg);
            m_engine->manager()->showDebuggerOutput(LogMisc, msg);
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
            sendTrkAck(result.token);
            if (addr) {
                // Todo: Do not send off GdbMessages if a synced gdb
                // query is pending, queue instead
                if (m_running) {
                    m_running = false;
                }
            } else {
                logMessage(QLatin1String("Ignoring stop at 0"));
            }
1155
1156

            #if 1
hjk's avatar
hjk committed
1157
            // We almost always need register values, so get them
1158
            // now before informing gdb about the stop.s
1159
            //qDebug() << "Auto-fetching registers";
hjk's avatar
hjk committed
1160
1161
            sendTrkMessage(0x12,
                TrkCB(handleAndReportReadRegistersAfterStop),
1162
                trkReadRegistersMessage());
1163
1164
1165
1166
1167
            #else
            // As a source-line step typically consists of
            // several instruction steps, better avoid the multiple
            // roundtrips through TRK in favour of an additional
            // roundtrip through gdb. But gdb will ask for all registers.
1168
1169
1170
1171
1172
1173
1174
                #if 1
                sendGdbServerMessage("S05", "Target stopped");
                #else
                QByteArray ba = "T05";
                appendRegister(&ba, RegisterPSGdb, addr);
                sendGdbServerMessage(ba, "Registers");
                #endif
1175
            #endif
1176
1177
            break;
        }
Friedemann Kleint's avatar
Friedemann Kleint committed
1178
        case TrkNotifyException: { // 0x91 Notify Exception (obsolete)
1179
1180
            debugMessage(_("RESET SNAPSHOT (NOTIFY EXCEPTION)"));
            m_snapshot.reset();
1181
1182
1183
1184
1185
            logMessage(prefix + "NOTE: EXCEPTION  " + str);
            sendTrkAck(result.token);
            break;
        }
        case 0x92: { //
1186
1187
            debugMessage(_("RESET SNAPSHOT (NOTIFY INTERNAL ERROR)"));
            m_snapshot.reset();
1188
1189
1190
1191
1192
1193
1194
            logMessage(prefix + "NOTE: INTERNAL ERROR: " + str);
            sendTrkAck(result.token);
            break;
        }

        // target->host OS notification
        case 0xa0: { // Notify Created
1195
1196
            // Sending this ACK does not seem to make a difference. Why?
            //sendTrkAck(result.token);
1197
            debugMessage(_("RESET SNAPSHOT (NOTIFY CREATED)"));
hjk's avatar