OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / gdb / codagdbadapter.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef DEBUGGER_CODAGDBADAPTER_H
34 #define DEBUGGER_CODAGDBADAPTER_H
35
36 #include "abstractgdbadapter.h"
37 #include "localgdbprocess.h"
38 #include "callback.h"
39 #include "trkutils.h"
40 #include "symbian.h"
41
42 #include <QtCore/QPointer>
43 #include <QtCore/QSharedPointer>
44 #include <QtCore/QStringList>
45 #include <QtCore/QHash>
46
47 QT_BEGIN_NAMESPACE
48 class QTcpServer;
49 class QTcpSocket;
50 class QIODevice;
51 QT_END_NAMESPACE
52
53 namespace Coda {
54     struct CodaCommandResult;
55     class CodaDevice;
56     class CodaEvent;
57     class CodaRunControlModuleLoadContextSuspendedEvent;
58 }
59
60 namespace SymbianUtils {
61 class SymbianDevice;
62 }
63
64 namespace Debugger {
65 namespace Internal {
66
67 struct MemoryRange;
68 struct GdbResult;
69
70 ///////////////////////////////////////////////////////////////////////
71 //
72 // CodaGdbAdapter
73 //
74 ///////////////////////////////////////////////////////////////////////
75
76 class CodaGdbAdapter : public AbstractGdbAdapter
77 {
78     Q_OBJECT
79
80 public:
81     typedef trk::Callback<const GdbResult &> GdbResultCallback;
82     typedef trk::Callback<const Coda::CodaCommandResult &> CodaCallback;
83     typedef trk::Callback<const GdbResponse &> GdbCallback;
84
85     explicit CodaGdbAdapter(GdbEngine *engine);
86     virtual ~CodaGdbAdapter();
87     void setGdbServerName(const QString &name);
88     QString gdbServerName() const { return m_gdbServerName; }
89
90     Q_SLOT void setVerbose(const QVariant &value);
91     void setVerbose(int verbose);
92     void setBufferedMemoryRead(bool b) { m_bufferedMemoryRead = b; }
93
94     void trkReloadRegisters();
95     void trkReloadThreads();
96
97 signals:
98     void output(const QString &msg);
99
100 public:
101     //
102     // Implementation of GdbProcessBase
103     //
104     void start(const QString &program, const QStringList &args,
105         QIODevice::OpenMode mode = QIODevice::ReadWrite);
106     void write(const QByteArray &data);
107     bool isTrkAdapter() const { return true; }
108
109     virtual DumperHandling dumperHandling() const { return DumperNotAvailable; }
110
111 private:
112     void setupTrkDeviceSignals();
113     void startAdapter();
114     void setupInferior();
115     void runEngine();
116     void interruptInferior();
117     void shutdownInferior();
118     void shutdownAdapter();
119     void sendRunControlTerminateCommand();
120     void handleRunControlTerminate(const Coda::CodaCommandResult &);
121     void sendRegistersGetMCommand();
122     void handleWriteRegister(const Coda::CodaCommandResult &result);
123     void reportRegisters();
124     void handleReadRegisters(const Coda::CodaCommandResult &result);
125     void handleRegisterChildren(const Coda::CodaCommandResult &result);
126     void handleAndReportReadRegisters(const Coda::CodaCommandResult &result);
127     void handleAndReportReadRegister(const Coda::CodaCommandResult &result);
128     void handleAndReportReadRegistersAfterStop(const Coda::CodaCommandResult &result);
129     QByteArray stopMessage() const;
130     void handleAndReportSetBreakpoint(const Coda::CodaCommandResult &result);
131     void handleClearBreakpoint(const Coda::CodaCommandResult &result);
132     void readMemory(uint addr, uint len, bool buffered);
133     void handleReadMemoryBuffered(const Coda::CodaCommandResult &result);
134     void handleReadMemoryUnbuffered(const Coda::CodaCommandResult &result);
135     void handleWriteMemory(const Coda::CodaCommandResult &result);
136     void tryAnswerGdbMemoryRequest(bool buffered);
137     inline void sendMemoryGetCommand(const MemoryRange &range, bool buffered);
138     void addThread(unsigned id);
139     inline QByteArray mainThreadContextId() const;
140     inline QByteArray currentThreadContextId() const;
141
142     AbstractGdbProcess *gdbProc() { return &m_gdbProc; }
143
144     void cleanup();
145
146     void handleTargetRemote(const GdbResponse &response);
147
148     QString m_gdbServerName; // 127.0.0.1:(2222+uid)
149     bool m_running;
150     int m_stopReason;
151
152     QSharedPointer<Coda::CodaDevice> m_codaDevice;
153
154     //
155     // Gdb
156     //
157     Q_SLOT void handleGdbConnection();
158     Q_SLOT void readGdbServerCommand();
159     Q_SLOT void codaDeviceError(const QString &);
160     Q_SLOT void codaDeviceRemoved(const SymbianUtils::SymbianDevice &dev);
161
162     void startGdb();
163     Q_SLOT void codaEvent(const Coda::CodaEvent &knownEvent);
164     void handleCodaRunControlModuleLoadContextSuspendedEvent(const Coda::CodaRunControlModuleLoadContextSuspendedEvent &e);
165     inline void sendTrkContinue();
166     void sendTrkStepRange();
167     void handleStep(const Coda::CodaCommandResult &result);
168     void handleCreateProcess(const Coda::CodaCommandResult &result);
169
170     void readGdbResponse();
171     void handleGdbServerCommand(const QByteArray &cmd);
172     void sendGdbServerMessage(const QByteArray &msg,
173         const QByteArray &logNote = QByteArray());
174     void sendGdbServerAck();
175     bool sendGdbServerPacket(const QByteArray &packet, bool doFlush);
176     void gdbSetCurrentThread(const QByteArray &cmd, const char *why);
177
178     void logMessage(const QString &msg, int channel = LogDebug);  // triggers output() if m_verbose
179     Q_SLOT void codaLogMessage(const QString &msg);
180
181     QPointer<QTcpServer> m_gdbServer;
182     QPointer<QTcpSocket> m_gdbConnection;
183     QByteArray m_gdbReadBuffer;
184     bool m_gdbAckMode;
185
186     // Debuggee state
187     trk::Session m_session; // global-ish data (process id, target information)
188     Symbian::Snapshot m_snapshot; // local-ish data (memory and registers)
189     QString m_remoteExecutable;
190     unsigned m_uid;
191     QStringList m_remoteArguments;
192     QString m_symbolFile;
193     QString m_symbolFileFolder;
194     int m_verbose;
195     bool m_bufferedMemoryRead;
196     bool m_firstResumableExeLoadedEvent;
197     // gdb wants registers, but we don't have the names yet. Continue in handler for names
198     bool m_registerRequestPending;
199     QByteArray m_tcfProcessId;
200     LocalGdbProcess m_gdbProc;
201     bool m_firstHelloEvent;
202 };
203
204 } // namespace Internal
205 } // namespace Debugger
206
207 #endif // DEBUGGER_CODAGDBADAPTER_H