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 info@qt.nokia.com.
31 **************************************************************************/
33 #ifndef DEBUGGER_DEBUGGERENGINE_H
34 #define DEBUGGER_DEBUGGERENGINE_H
36 #include "debugger_global.h"
37 #include "debuggerconstants.h"
38 #include "breakpoint.h" // For 'BreakpointId'
40 #include <QtCore/QObject>
41 #include <QtCore/QStringList>
47 class QAbstractItemModel;
50 namespace TextEditor {
60 class DebuggerEnginePrivate;
61 class DebuggerRunControl;
62 class DebuggerStartParameters;
64 DEBUGGER_EXPORT QDebug operator<<(QDebug str, const DebuggerStartParameters &);
65 DEBUGGER_EXPORT QDebug operator<<(QDebug str, DebuggerState state);
69 class DebuggerPluginPrivate;
70 class DisassemblerAgent;
75 class RegisterHandler;
78 class SourceFilesHandler;
81 class BreakpointParameters;
83 class DebuggerToolTipContext;
86 struct WatchUpdateFlags
88 WatchUpdateFlags() : tryIncremental(false) {}
95 Location() { init(); }
96 Location(quint64 address) { init(); m_address = address; }
97 Location(const QString &file) { init(); m_fileName = file; }
98 Location(const QString &file, int line, bool marker = true)
99 { init(); m_lineNumber = line; m_fileName = file; m_needsMarker = marker; }
100 Location(const StackFrame &frame, bool marker = true);
101 QString fileName() const { return m_fileName; }
102 QString functionName() const { return m_functionName; }
103 QString from() const { return m_from; }
104 int lineNumber() const { return m_lineNumber; }
105 void setNeedsRaise(bool on) { m_needsRaise = on; }
106 void setNeedsMarker(bool on) { m_needsMarker = on; }
107 void setFileName(const QString &fileName) { m_fileName = fileName; }
108 bool needsRaise() const { return m_needsRaise; }
109 bool needsMarker() const { return m_needsMarker; }
110 bool hasDebugInfo() const { return m_hasDebugInfo; }
111 quint64 address() const { return m_address; }
114 void init() { m_needsMarker = false; m_needsRaise = true; m_lineNumber = -1;
115 m_address = 0; m_hasDebugInfo = true; }
121 QString m_functionName;
129 ContextData() : lineNumber(0), address(0) {}
137 } // namespace Internal
140 // FIXME: DEBUGGER_EXPORT?
141 class DEBUGGER_EXPORT DebuggerEngine : public QObject
146 explicit DebuggerEngine(const DebuggerStartParameters &sp,
147 DebuggerLanguages languages,
148 DebuggerEngine *parentEngine = 0);
149 virtual ~DebuggerEngine();
151 const DebuggerStartParameters &startParameters() const;
152 DebuggerStartParameters &startParameters();
154 virtual bool setToolTipExpression(const QPoint & mousePos,
155 TextEditor::ITextEditor *editor, const Internal::DebuggerToolTipContext &);
157 virtual void updateWatchData(const Internal::WatchData &data,
158 const Internal::WatchUpdateFlags & flags = Internal::WatchUpdateFlags());
159 virtual void startDebugger(DebuggerRunControl *runControl);
161 virtual void watchPoint(const QPoint &);
165 MemoryReadOnly = 0x1, //!< Read-only.
166 MemoryTrackRegister = 0x2, //!< Address parameter is register number to track
167 MemoryView = 0x4 //!< Open a separate view (using the pos-parameter).
170 virtual void openMemoryView(quint64 startAddr, unsigned flags,
171 const QList<Internal::MemoryMarkup> &ml,
173 const QString &title = QString(), QWidget *parent = 0);
174 virtual void fetchMemory(Internal::MemoryAgent *, QObject *,
175 quint64 addr, quint64 length);
176 virtual void changeMemory(Internal::MemoryAgent *, QObject *,
177 quint64 addr, const QByteArray &data);
178 virtual void updateMemoryViews();
179 virtual void openDisassemblerView(const Internal::Location &location);
180 virtual void fetchDisassembler(Internal::DisassemblerAgent *);
181 virtual void activateFrame(int index);
183 virtual void reloadModules();
184 virtual void examineModules();
185 virtual void loadSymbols(const QString &moduleName);
186 virtual void loadSymbolsForStack();
187 virtual void loadAllSymbols();
188 virtual void requestModuleSymbols(const QString &moduleName);
190 virtual void reloadRegisters();
191 virtual void reloadSourceFiles();
192 virtual void reloadFullStack();
194 virtual void setRegisterValue(int regnr, const QString &value);
195 virtual void addOptionPages(QList<Core::IOptionsPage*> *) const;
196 virtual unsigned debuggerCapabilities() const;
198 virtual bool isSynchronous() const;
199 virtual QByteArray qtNamespace() const;
201 virtual void createSnapshot();
202 virtual void updateAll();
204 typedef Internal::BreakpointModelId BreakpointModelId;
205 virtual bool stateAcceptsBreakpointChanges() const { return true; }
206 virtual void attemptBreakpointSynchronization();
207 virtual bool acceptsBreakpoint(BreakpointModelId id) const = 0;
208 virtual void insertBreakpoint(BreakpointModelId id); // FIXME: make pure
209 virtual void removeBreakpoint(BreakpointModelId id); // FIXME: make pure
210 virtual void changeBreakpoint(BreakpointModelId id); // FIXME: make pure
212 virtual bool acceptsDebuggerCommands() const { return true; }
213 virtual void assignValueInDebugger(const Internal::WatchData *data,
214 const QString &expr, const QVariant &value);
215 virtual void selectThread(int index);
217 virtual void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
218 virtual void handleRemoteSetupFailed(const QString &message);
220 virtual Internal::ModulesHandler *modulesHandler() const;
221 virtual Internal::RegisterHandler *registerHandler() const;
222 virtual Internal::StackHandler *stackHandler() const;
223 virtual Internal::ThreadsHandler *threadsHandler() const;
224 virtual Internal::WatchHandler *watchHandler() const;
225 virtual Internal::SourceFilesHandler *sourceFilesHandler() const;
226 virtual Internal::BreakHandler *breakHandler() const;
228 virtual QAbstractItemModel *modulesModel() const;
229 virtual QAbstractItemModel *registerModel() const;
230 virtual QAbstractItemModel *stackModel() const;
231 virtual QAbstractItemModel *threadsModel() const;
232 virtual QAbstractItemModel *localsModel() const;
233 virtual QAbstractItemModel *watchersModel() const;
234 virtual QAbstractItemModel *returnModel() const;
235 virtual QAbstractItemModel *toolTipsModel() const;
236 virtual QAbstractItemModel *sourceFilesModel() const;
239 void handleFinished();
240 void handleStartFailed();
241 bool debuggerActionsEnabled() const;
242 static bool debuggerActionsEnabled(DebuggerState state);
244 DebuggerState state() const;
245 DebuggerState lastGoodState() const;
246 DebuggerState targetState() const;
247 bool isDying() const;
249 // Dumper stuff (common to cdb and gdb).
250 bool qtDumperLibraryEnabled() const;
251 QString qtDumperLibraryName() const;
252 QStringList qtDumperLibraryLocations() const;
253 void showQtDumperLibraryWarning(const QString &details);
255 static const char *stateName(int s);
257 void notifyInferiorPid(qint64 pid);
258 qint64 inferiorPid() const;
259 bool isReverseDebugging() const;
260 void handleCommand(int role, const QVariant &value);
263 Q_SLOT virtual void showMessage(const QString &msg, int channel = LogDebug,
264 int timeout = -1) const;
265 Q_SLOT void showStatusMessage(const QString &msg, int timeout = -1) const;
267 virtual void resetLocation();
268 virtual void gotoLocation(const Internal::Location &location);
269 virtual void quitDebugger(); // called by DebuggerRunControl
271 virtual void updateViews();
272 bool isSlaveEngine() const;
273 bool isMasterEngine() const;
274 DebuggerEngine *masterEngine() const;
276 DebuggerLanguages languages() const;
278 virtual bool setupQmlStep(bool /*on*/) { return false; }
279 virtual void readyToExecuteQmlStep() {}
281 virtual bool canDisplayTooltip() const { return state() == InferiorStopOk; }
283 virtual void notifyInferiorIll();
286 void stateChanged(const Debugger::DebuggerState &state);
287 // A new stack frame is on display including locals.
288 void stackFrameCompleted();
289 void updateViewsRequested();
291 * For "external" clients of a debugger run control that needs to do
292 * further setup before the debugger is started (e.g. Maemo).
293 * Afterwards, handleSetupDone() or handleSetupFailed() must be called
294 * to continue or abort debugging, respectively.
295 * This signal is only emitted if the start parameters indicate that
296 * a server start script should be used, but none is given.
298 void requestRemoteSetup();
301 // The base notify*() function implementation should be sufficient
302 // in most cases, but engines are free to override them to do some
303 // engine specific cleanup like stopping timers etc.
304 virtual void notifyEngineSetupOk();
305 virtual void notifyEngineSetupFailed();
306 virtual void notifyEngineRunFailed();
308 virtual void notifyInferiorSetupOk();
309 virtual void notifyInferiorSetupFailed();
311 virtual void notifyEngineRunAndInferiorRunOk();
312 virtual void notifyEngineRunAndInferiorStopOk();
313 virtual void notifyInferiorUnrunnable(); // Called by CoreAdapter.
315 // Use notifyInferiorRunRequested() plus notifyInferiorRunOk() instead.
316 //virtual void notifyInferiorSpontaneousRun();
318 virtual void notifyInferiorRunRequested();
319 virtual void notifyInferiorRunOk();
320 virtual void notifyInferiorRunFailed();
322 virtual void notifyInferiorStopOk();
323 virtual void notifyInferiorSpontaneousStop();
324 virtual void notifyInferiorStopFailed();
325 virtual void notifyInferiorExited();
327 virtual void notifyInferiorShutdownOk();
328 virtual void notifyInferiorShutdownFailed();
330 virtual void notifyEngineSpontaneousShutdown();
331 virtual void notifyEngineShutdownOk();
332 virtual void notifyEngineShutdownFailed();
334 virtual void notifyEngineIll();
336 virtual void setupEngine() = 0;
337 virtual void setupInferior() = 0;
338 virtual void runEngine() = 0;
339 virtual void shutdownInferior() = 0;
340 virtual void shutdownEngine() = 0;
342 virtual void detachDebugger();
343 virtual void exitDebugger();
344 virtual void executeStep();
345 virtual void executeStepOut() ;
346 virtual void executeNext();
347 virtual void executeStepI();
348 virtual void executeNextI();
349 virtual void executeReturn();
351 virtual void continueInferior();
352 virtual void interruptInferior();
353 virtual void requestInterruptInferior();
355 virtual void executeRunToLine(const Internal::ContextData &data);
356 virtual void executeRunToFunction(const QString &functionName);
357 virtual void executeJumpToLine(const Internal::ContextData &data);
358 virtual void executeDebuggerCommand(const QString &command);
360 virtual void frameUp();
361 virtual void frameDown();
363 DebuggerRunControl *runControl() const;
365 static QString msgWatchpointByAddressTriggered(BreakpointModelId id,
366 int number, quint64 address);
367 static QString msgWatchpointByAddressTriggered(BreakpointModelId id,
368 int number, quint64 address, const QString &threadId);
369 static QString msgWatchpointByExpressionTriggered(BreakpointModelId id,
370 int number, const QString &expr);
371 static QString msgWatchpointByExpressionTriggered(BreakpointModelId id,
372 int number, const QString &expr, const QString &threadId);
373 static QString msgBreakpointTriggered(BreakpointModelId id,
374 int number, const QString &threadId);
375 static QString msgStopped(const QString &reason = QString());
376 static QString msgStoppedBySignal(const QString &meaning, const QString &name);
377 static QString msgStoppedByException(const QString &description,
378 const QString &threadId);
379 static QString msgInterrupted();
380 void showStoppedBySignalMessageBox(const QString meaning, QString name);
381 void showStoppedByExceptionMessageBox(const QString &description);
383 static bool isCppBreakpoint(const Internal::BreakpointParameters &p);
385 bool isStateDebugging() const;
386 void setStateDebugging(bool on);
388 virtual void setupSlaveInferior();
389 virtual void setupSlaveEngine();
390 virtual void runSlaveEngine();
391 virtual void shutdownSlaveEngine();
393 virtual void slaveEngineStateChanged(DebuggerEngine *engine,
394 DebuggerState state);
397 // Wrapper engine needs access to state of its subengines.
398 friend class Internal::QmlCppEngine;
399 friend class Internal::DebuggerPluginPrivate;
400 friend class QmlAdapter;
402 virtual void setState(DebuggerState state, bool forced = false);
404 friend class DebuggerEnginePrivate;
405 DebuggerEnginePrivate *d;
408 } // namespace Debugger
410 Q_DECLARE_METATYPE(Debugger::Internal::ContextData)
412 #endif // DEBUGGER_DEBUGGERENGINE_H