1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #ifndef DEBUGGER_TCFTRKGDBADAPTER_H
35 #define DEBUGGER_TCFTRKGDBADAPTER_H
37 #include "abstractgdbadapter.h"
38 #include "localgdbprocess.h"
43 #include <QtCore/QPointer>
44 #include <QtCore/QSharedPointer>
45 #include <QtCore/QStringList>
46 #include <QtCore/QHash>
55 struct TcfTrkCommandResult;
58 class TcfTrkRunControlModuleLoadContextSuspendedEvent;
67 ///////////////////////////////////////////////////////////////////////
71 ///////////////////////////////////////////////////////////////////////
73 class TcfTrkGdbAdapter : public AbstractGdbAdapter
78 typedef trk::Callback<const GdbResult &> GdbResultCallback;
79 typedef trk::Callback<const tcftrk::TcfTrkCommandResult &> TcfTrkCallback;
80 typedef trk::Callback<const GdbResponse &> GdbCallback;
82 explicit TcfTrkGdbAdapter(GdbEngine *engine);
83 virtual ~TcfTrkGdbAdapter();
84 void setGdbServerName(const QString &name);
85 QString gdbServerName() const { return m_gdbServerName; }
87 Q_SLOT void setVerbose(const QVariant &value);
88 void setVerbose(int verbose);
89 void setBufferedMemoryRead(bool b) { m_bufferedMemoryRead = b; }
91 void trkReloadRegisters();
92 void trkReloadThreads();
95 void output(const QString &msg);
99 // Implementation of GdbProcessBase
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; }
106 virtual DumperHandling dumperHandling() const { return DumperNotAvailable; }
110 void setupInferior();
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;
138 AbstractGdbProcess *gdbProc() { return &m_gdbProc; }
142 void handleTargetRemote(const GdbResponse &response);
144 QString m_gdbServerName; // 127.0.0.1:(2222+uid)
147 tcftrk::TcfTrkDevice *m_trkDevice;
148 QSharedPointer<QIODevice> m_trkIODevice;
153 Q_SLOT void handleGdbConnection();
154 Q_SLOT void readGdbServerCommand();
155 Q_SLOT void tcftrkDeviceError(const QString &);
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);
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);
172 void logMessage(const QString &msg, int channel = LogDebug); // triggers output() if m_verbose
173 Q_SLOT void trkLogMessage(const QString &msg);
175 QPointer<QTcpServer> m_gdbServer;
176 QPointer<QTcpSocket> m_gdbConnection;
177 QByteArray m_gdbReadBuffer;
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;
185 QStringList m_remoteArguments;
186 QString m_symbolFile;
187 QString m_symbolFileFolder;
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;
197 } // namespace Internal
198 } // namespace Debugger
200 #endif // DEBUGGER_TCFTRKGDBADAPTER_H