aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/debugger/gdb/codagdbadapter.h
blob: 3da3f77faaad210d4bc67daafd36d1a82fba92db (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/

#ifndef DEBUGGER_CODAGDBADAPTER_H
#define DEBUGGER_CODAGDBADAPTER_H

#include "abstractgdbadapter.h"
#include "localgdbprocess.h"
#include "callback.h"
#include "trkutils.h"
#include "symbian.h"

#include <QtCore/QPointer>
#include <QtCore/QSharedPointer>
#include <QtCore/QStringList>
#include <QtCore/QHash>

QT_BEGIN_NAMESPACE
class QTcpServer;
class QTcpSocket;
class QIODevice;
QT_END_NAMESPACE

namespace Coda {
    struct CodaCommandResult;
    class CodaDevice;
    class CodaEvent;
    class CodaRunControlModuleLoadContextSuspendedEvent;
}

namespace SymbianUtils {
class SymbianDevice;
}

namespace Debugger {
namespace Internal {

struct MemoryRange;
struct GdbResult;

///////////////////////////////////////////////////////////////////////
//
// CodaGdbAdapter
//
///////////////////////////////////////////////////////////////////////

class CodaGdbAdapter : public AbstractGdbAdapter
{
    Q_OBJECT

public:
    typedef trk::Callback<const GdbResult &> GdbResultCallback;
    typedef trk::Callback<const Coda::CodaCommandResult &> CodaCallback;
    typedef trk::Callback<const GdbResponse &> GdbCallback;

    explicit CodaGdbAdapter(GdbEngine *engine);
    virtual ~CodaGdbAdapter();
    void setGdbServerName(const QString &name);
    QString gdbServerName() const { return m_gdbServerName; }

    Q_SLOT void setVerbose(const QVariant &value);
    void setVerbose(int verbose);
    void setBufferedMemoryRead(bool b) { m_bufferedMemoryRead = b; }

    void trkReloadRegisters();
    void trkReloadThreads();

signals:
    void output(const QString &msg);

public:
    //
    // Implementation of GdbProcessBase
    //
    void start(const QString &program, const QStringList &args,
        QIODevice::OpenMode mode = QIODevice::ReadWrite);
    void write(const QByteArray &data);
    bool isTrkAdapter() const { return true; }

    virtual DumperHandling dumperHandling() const { return DumperNotAvailable; }

private:
    void setupTrkDeviceSignals();
    void startAdapter();
    void setupInferior();
    void runEngine();
    void interruptInferior();
    void shutdownInferior();
    void shutdownAdapter();
    void sendRunControlTerminateCommand();
    void handleRunControlTerminate(const Coda::CodaCommandResult &);
    void sendRegistersGetMCommand();
    void handleWriteRegister(const Coda::CodaCommandResult &result);
    void reportRegisters();
    void handleReadRegisters(const Coda::CodaCommandResult &result);
    void handleRegisterChildren(const Coda::CodaCommandResult &result);
    void handleAndReportReadRegisters(const Coda::CodaCommandResult &result);
    void handleAndReportReadRegister(const Coda::CodaCommandResult &result);
    void handleAndReportReadRegistersAfterStop(const Coda::CodaCommandResult &result);
    QByteArray stopMessage() const;
    void handleAndReportSetBreakpoint(const Coda::CodaCommandResult &result);
    void handleClearBreakpoint(const Coda::CodaCommandResult &result);
    void readMemory(uint addr, uint len, bool buffered);
    void handleReadMemoryBuffered(const Coda::CodaCommandResult &result);
    void handleReadMemoryUnbuffered(const Coda::CodaCommandResult &result);
    void handleWriteMemory(const Coda::CodaCommandResult &result);
    void tryAnswerGdbMemoryRequest(bool buffered);
    inline void sendMemoryGetCommand(const MemoryRange &range, bool buffered);
    void addThread(unsigned id);
    inline QByteArray mainThreadContextId() const;
    inline QByteArray currentThreadContextId() const;

    AbstractGdbProcess *gdbProc() { return &m_gdbProc; }

    void cleanup();

    void handleTargetRemote(const GdbResponse &response);

    QString m_gdbServerName; // 127.0.0.1:(2222+uid)
    bool m_running;
    int m_stopReason;

    QSharedPointer<Coda::CodaDevice> m_codaDevice;

    //
    // Gdb
    //
    Q_SLOT void handleGdbConnection();
    Q_SLOT void readGdbServerCommand();
    Q_SLOT void codaDeviceError(const QString &);
    Q_SLOT void codaDeviceRemoved(const SymbianUtils::SymbianDevice &dev);

    void startGdb();
    Q_SLOT void codaEvent(const Coda::CodaEvent &knownEvent);
    void handleCodaRunControlModuleLoadContextSuspendedEvent(const Coda::CodaRunControlModuleLoadContextSuspendedEvent &e);
    inline void sendTrkContinue();
    void sendTrkStepRange();
    void handleStep(const Coda::CodaCommandResult &result);
    void handleCreateProcess(const Coda::CodaCommandResult &result);

    void readGdbResponse();
    void handleGdbServerCommand(const QByteArray &cmd);
    void sendGdbServerMessage(const QByteArray &msg,
        const QByteArray &logNote = QByteArray());
    void sendGdbServerAck();
    bool sendGdbServerPacket(const QByteArray &packet, bool doFlush);
    void gdbSetCurrentThread(const QByteArray &cmd, const char *why);

    void logMessage(const QString &msg, int channel = LogDebug);  // triggers output() if m_verbose
    Q_SLOT void codaLogMessage(const QString &msg);

    QPointer<QTcpServer> m_gdbServer;
    QPointer<QTcpSocket> m_gdbConnection;
    QByteArray m_gdbReadBuffer;
    bool m_gdbAckMode;

    // Debuggee state
    trk::Session m_session; // global-ish data (process id, target information)
    Symbian::Snapshot m_snapshot; // local-ish data (memory and registers)
    QString m_remoteExecutable;
    unsigned m_uid;
    QStringList m_remoteArguments;
    QString m_symbolFile;
    QString m_symbolFileFolder;
    int m_verbose;
    bool m_bufferedMemoryRead;
    bool m_firstResumableExeLoadedEvent;
    // gdb wants registers, but we don't have the names yet. Continue in handler for names
    bool m_registerRequestPending;
    QByteArray m_tcfProcessId;
    LocalGdbProcess m_gdbProc;
    bool m_firstHelloEvent;
};

} // namespace Internal
} // namespace Debugger

#endif // DEBUGGER_CODAGDBADAPTER_H