1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef DEBUGGER_CODAGDBADAPTER_H
34 #define DEBUGGER_CODAGDBADAPTER_H
36 #include "abstractgdbadapter.h"
37 #include "localgdbprocess.h"
42 #include <QtCore/QPointer>
43 #include <QtCore/QSharedPointer>
44 #include <QtCore/QStringList>
45 #include <QtCore/QHash>
54 struct CodaCommandResult;
57 class CodaRunControlModuleLoadContextSuspendedEvent;
60 namespace SymbianUtils {
70 ///////////////////////////////////////////////////////////////////////
74 ///////////////////////////////////////////////////////////////////////
76 class CodaGdbAdapter : public AbstractGdbAdapter
81 typedef trk::Callback<const GdbResult &> GdbResultCallback;
82 typedef trk::Callback<const Coda::CodaCommandResult &> CodaCallback;
83 typedef trk::Callback<const GdbResponse &> GdbCallback;
85 explicit CodaGdbAdapter(GdbEngine *engine);
86 virtual ~CodaGdbAdapter();
87 void setGdbServerName(const QString &name);
88 QString gdbServerName() const { return m_gdbServerName; }
90 Q_SLOT void setVerbose(const QVariant &value);
91 void setVerbose(int verbose);
92 void setBufferedMemoryRead(bool b) { m_bufferedMemoryRead = b; }
94 void trkReloadRegisters();
95 void trkReloadThreads();
98 void output(const QString &msg);
102 // Implementation of GdbProcessBase
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; }
109 virtual DumperHandling dumperHandling() const { return DumperNotAvailable; }
112 void setupTrkDeviceSignals();
114 void setupInferior();
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;
142 AbstractGdbProcess *gdbProc() { return &m_gdbProc; }
146 void handleTargetRemote(const GdbResponse &response);
148 QString m_gdbServerName; // 127.0.0.1:(2222+uid)
152 QSharedPointer<Coda::CodaDevice> m_codaDevice;
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);
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);
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);
178 void logMessage(const QString &msg, int channel = LogDebug); // triggers output() if m_verbose
179 Q_SLOT void codaLogMessage(const QString &msg);
181 QPointer<QTcpServer> m_gdbServer;
182 QPointer<QTcpSocket> m_gdbConnection;
183 QByteArray m_gdbReadBuffer;
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;
191 QStringList m_remoteArguments;
192 QString m_symbolFile;
193 QString m_symbolFileFolder;
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;
204 } // namespace Internal
205 } // namespace Debugger
207 #endif // DEBUGGER_CODAGDBADAPTER_H