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_DEBUGGERENGINE_H
35 #define DEBUGGER_DEBUGGERENGINE_H
37 #include "debugger_global.h"
38 #include "debuggerconstants.h"
39 #include "breakpoint.h" // For 'BreakpointId'
41 #include <QtCore/QObject>
42 #include <QtCore/QStringList>
48 class QAbstractItemModel;
51 namespace TextEditor {
61 class DebuggerEnginePrivate;
62 class DebuggerRunControl;
63 class DebuggerStartParameters;
65 DEBUGGER_EXPORT QDebug operator<<(QDebug str, const DebuggerStartParameters &);
66 DEBUGGER_EXPORT QDebug operator<<(QDebug str, DebuggerState state);
70 class DebuggerPluginPrivate;
71 class DisassemblerAgent;
76 class RegisterHandler;
79 class SourceFilesHandler;
82 class BreakpointParameters;
85 struct WatchUpdateFlags
87 WatchUpdateFlags() : tryIncremental(false) {}
94 Location() { init(); }
95 Location(quint64 address) { init(); m_address = address; }
96 Location(const QString &file) { init(); m_fileName = file; }
97 Location(const QString &file, int line, bool marker = true)
98 { init(); m_lineNumber = line; m_fileName = file; m_needsMarker = marker; }
99 Location(const StackFrame &frame, bool marker = true);
100 QString fileName() const { return m_fileName; }
101 QString functionName() const { return m_functionName; }
102 int lineNumber() const { return m_lineNumber; }
103 void setNeedsRaise(bool on) { m_needsRaise = on; }
104 void setNeedsMarker(bool on) { m_needsMarker = on; }
105 void setFileName(const QString &fileName) { m_fileName = fileName; }
106 bool needsRaise() const { return m_needsRaise; }
107 bool needsMarker() const { return m_needsMarker; }
108 bool hasDebugInfo() const { return m_hasDebugInfo; }
109 quint64 address() const { return m_address; }
112 void init() { m_needsMarker = false; m_needsRaise = true; m_lineNumber = -1;
113 m_address = 0; m_hasDebugInfo = true; }
119 QString m_functionName;
123 } // namespace Internal
126 // FIXME: DEBUGGER_EXPORT?
127 class DEBUGGER_EXPORT DebuggerEngine : public QObject
132 explicit DebuggerEngine(const DebuggerStartParameters &sp);
133 virtual ~DebuggerEngine();
135 typedef Internal::BreakpointId BreakpointId;
136 virtual void setToolTipExpression(const QPoint & mousePos,
137 TextEditor::ITextEditor *editor, int cursorPos);
139 virtual void updateWatchData(const Internal::WatchData &data,
140 const Internal::WatchUpdateFlags & flags = Internal::WatchUpdateFlags());
141 void startDebugger(DebuggerRunControl *runControl);
143 virtual void watchPoint(const QPoint &);
144 virtual void openMemoryView(quint64 addr);
145 virtual void fetchMemory(Internal::MemoryAgent *, QObject *,
146 quint64 addr, quint64 length);
147 virtual void updateMemoryViews();
148 virtual void openDisassemblerView(const Internal::Location &location);
149 virtual void fetchDisassembler(Internal::DisassemblerAgent *);
150 virtual void activateFrame(int index);
152 virtual void reloadModules();
153 virtual void examineModules();
154 virtual void loadSymbols(const QString &moduleName);
155 virtual void loadSymbolsForStack();
156 virtual void loadAllSymbols();
157 virtual void requestModuleSymbols(const QString &moduleName);
159 virtual void reloadRegisters();
160 virtual void reloadSourceFiles();
161 virtual void reloadFullStack();
163 virtual void setRegisterValue(int regnr, const QString &value);
164 virtual void addOptionPages(QList<Core::IOptionsPage*> *) const;
165 virtual unsigned debuggerCapabilities() const;
167 virtual bool isSynchronous() const;
168 virtual QByteArray qtNamespace() const;
170 virtual void createSnapshot();
171 virtual void updateAll();
174 virtual bool stateAcceptsBreakpointChanges() const { return true; }
175 virtual void attemptBreakpointSynchronization();
176 virtual bool acceptsBreakpoint(BreakpointId id) const = 0;
177 virtual void insertBreakpoint(BreakpointId id); // FIXME: make pure
178 virtual void removeBreakpoint(BreakpointId id); // FIXME: make pure
179 virtual void changeBreakpoint(BreakpointId id); // FIXME: make pure
181 virtual void assignValueInDebugger(const Internal::WatchData *data,
182 const QString &expr, const QVariant &value);
183 virtual void removeTooltip();
184 virtual void selectThread(int index);
186 virtual void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
187 virtual void handleRemoteSetupFailed(const QString &message);
190 friend class Internal::DebuggerPluginPrivate;
191 virtual void detachDebugger();
192 virtual void exitDebugger();
193 virtual void executeStep();
194 virtual void executeStepOut() ;
195 virtual void executeNext();
196 virtual void executeStepI();
197 virtual void executeNextI();
198 virtual void executeReturn();
200 virtual void continueInferior();
201 virtual void interruptInferior();
202 virtual void requestInterruptInferior();
204 virtual void executeRunToLine(const QString &fileName, int lineNumber);
205 virtual void executeRunToFunction(const QString &functionName);
206 virtual void executeJumpToLine(const QString &fileName, int lineNumber);
207 virtual void executeDebuggerCommand(const QString &command);
209 virtual void frameUp();
210 virtual void frameDown();
213 const DebuggerStartParameters &startParameters() const;
214 DebuggerStartParameters &startParameters();
216 Internal::ModulesHandler *modulesHandler() const;
217 Internal::RegisterHandler *registerHandler() const;
218 Internal::StackHandler *stackHandler() const;
219 Internal::ThreadsHandler *threadsHandler() const;
220 Internal::WatchHandler *watchHandler() const;
221 Internal::SourceFilesHandler *sourceFilesHandler() const;
222 Internal::BreakHandler *breakHandler() const;
224 virtual QAbstractItemModel *modulesModel() const;
225 virtual QAbstractItemModel *registerModel() const;
226 virtual QAbstractItemModel *stackModel() const;
227 virtual QAbstractItemModel *threadsModel() const;
228 virtual QAbstractItemModel *localsModel() const;
229 virtual QAbstractItemModel *watchersModel() const;
230 virtual QAbstractItemModel *returnModel() const;
231 virtual QAbstractItemModel *sourceFilesModel() const;
234 void handleFinished();
235 void handleStartFailed();
236 bool debuggerActionsEnabled() const;
237 static bool debuggerActionsEnabled(DebuggerState state);
239 DebuggerState state() const;
240 DebuggerState lastGoodState() const;
241 DebuggerState targetState() const;
242 bool isDying() const;
244 // Dumper stuff (common to cdb and gdb).
245 bool qtDumperLibraryEnabled() const;
246 QString qtDumperLibraryName() const;
247 QStringList qtDumperLibraryLocations() const;
248 void showQtDumperLibraryWarning(const QString &details);
250 static const char *stateName(int s);
252 void notifyInferiorPid(qint64 pid);
253 qint64 inferiorPid() const;
254 bool isReverseDebugging() const;
255 void handleCommand(int role, const QVariant &value);
258 Q_SLOT void showMessage(const QString &msg, int channel = LogDebug,
259 int timeout = -1) const;
260 Q_SLOT void showStatusMessage(const QString &msg, int timeout = -1) const;
262 void resetLocation();
263 virtual void gotoLocation(const Internal::Location &location);
264 virtual void quitDebugger(); // called by DebuggerRunControl
266 virtual void updateViews();
267 bool isSlaveEngine() const;
270 void stateChanged(const DebuggerState &state);
271 void updateViewsRequested();
273 * For "external" clients of a debugger run control that needs to do
274 * further setup before the debugger is started (e.g. Maemo).
275 * Afterwards, handleSetupDone() or handleSetupFailed() must be called
276 * to continue or abort debugging, respectively.
277 * This signal is only emitted if the start parameters indicate that
278 * a server start script should be used, but none is given.
280 void requestRemoteSetup();
283 // The base notify*() function implementation should be sufficient
284 // in most cases, but engines are free to override them to do some
285 // engine specific cleanup like stopping timers etc.
286 virtual void notifyEngineSetupOk();
287 virtual void notifyEngineSetupFailed();
288 virtual void notifyEngineRunFailed();
290 virtual void notifyInferiorSetupOk();
291 virtual void notifyInferiorSetupFailed();
293 virtual void notifyEngineRunAndInferiorRunOk();
294 virtual void notifyEngineRunAndInferiorStopOk();
295 virtual void notifyInferiorUnrunnable(); // Called by CoreAdapter.
297 // Use notifyInferiorRunRequested() plus notifyInferiorRunOk() instead.
298 //virtual void notifyInferiorSpontaneousRun();
300 virtual void notifyInferiorRunRequested();
301 virtual void notifyInferiorRunOk();
302 virtual void notifyInferiorRunFailed();
304 virtual void notifyInferiorStopOk();
305 virtual void notifyInferiorSpontaneousStop();
306 virtual void notifyInferiorStopFailed();
307 virtual void notifyInferiorExited();
309 virtual void notifyInferiorShutdownOk();
310 virtual void notifyInferiorShutdownFailed();
312 virtual void notifyEngineSpontaneousShutdown();
313 virtual void notifyEngineShutdownOk();
314 virtual void notifyEngineShutdownFailed();
316 virtual void notifyInferiorIll();
317 virtual void notifyEngineIll();
319 virtual void setupEngine() = 0;
320 virtual void setupInferior() = 0;
321 virtual void runEngine() = 0;
322 virtual void shutdownInferior() = 0;
323 virtual void shutdownEngine() = 0;
325 DebuggerRunControl *runControl() const; // FIXME: Protect.
328 static QString msgWatchpointTriggered(BreakpointId id,
329 int number, quint64 address);
330 static QString msgWatchpointTriggered(BreakpointId id,
331 int number, quint64 address, const QString &threadId);
332 static QString msgBreakpointTriggered(BreakpointId id,
333 int number, const QString &threadId);
334 static QString msgStopped(const QString &reason = QString());
335 static QString msgStoppedBySignal(const QString &meaning, const QString &name);
336 static QString msgStoppedByException(const QString &description,
337 const QString &threadId);
338 static QString msgInterrupted();
339 void showStoppedBySignalMessageBox(const QString meaning, QString name);
340 void showStoppedByExceptionMessageBox(const QString &description);
342 static bool isCppBreakpoint(const Internal::BreakpointParameters &p);
345 // Wrapper engine needs access to state of its subengines.
346 friend class Internal::QmlCppEngine;
347 void setState(DebuggerState state, bool forced = false);
348 void setSlaveEngine(bool value);
350 friend class DebuggerEnginePrivate;
351 DebuggerEnginePrivate *d;
354 } // namespace Debugger
356 #endif // DEBUGGER_DEBUGGERENGINE_H