OSDN Git Service

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