OSDN Git Service

Debugger: Expose which languages (QML, C++, Any) an engine supports
[qt-creator-jp/qt-creator-jp.git] / src / plugins / debugger / debuggerengine.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 (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at info@qt.nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef DEBUGGER_DEBUGGERENGINE_H
34 #define DEBUGGER_DEBUGGERENGINE_H
35
36 #include "debugger_global.h"
37 #include "debuggerconstants.h"
38 #include "breakpoint.h" // For 'BreakpointId'
39
40 #include <QtCore/QObject>
41 #include <QtCore/QStringList>
42
43 QT_BEGIN_NAMESPACE
44 class QDebug;
45 class QPoint;
46 class QMessageBox;
47 class QAbstractItemModel;
48 QT_END_NAMESPACE
49
50 namespace TextEditor {
51 class ITextEditor;
52 }
53
54 namespace Core {
55 class IOptionsPage;
56 }
57
58 namespace Debugger {
59
60 class DebuggerEnginePrivate;
61 class DebuggerRunControl;
62 class DebuggerStartParameters;
63
64 DEBUGGER_EXPORT QDebug operator<<(QDebug str, const DebuggerStartParameters &);
65 DEBUGGER_EXPORT QDebug operator<<(QDebug str, DebuggerState state);
66
67 namespace Internal {
68
69 class DebuggerPluginPrivate;
70 class DisassemblerAgent;
71 class MemoryAgent;
72 class WatchData;
73 class BreakHandler;
74 class ModulesHandler;
75 class RegisterHandler;
76 class StackHandler;
77 class StackFrame;
78 class SourceFilesHandler;
79 class ThreadsHandler;
80 class WatchHandler;
81 class BreakpointParameters;
82 class QmlCppEngine;
83 class DebuggerToolTipContext;
84 class MemoryMarkup;
85
86 struct WatchUpdateFlags
87 {
88     WatchUpdateFlags() : tryIncremental(false) {}
89     bool tryIncremental;
90 };
91
92 class Location
93 {
94 public:
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; }
112
113 private:
114     void init() { m_needsMarker = false; m_needsRaise = true; m_lineNumber = -1;
115         m_address = 0; m_hasDebugInfo = true; }
116     bool m_needsMarker;
117     bool m_needsRaise;
118     bool m_hasDebugInfo;
119     int m_lineNumber;
120     QString m_fileName;
121     QString m_functionName;
122     QString m_from;
123     quint64 m_address;
124 };
125
126 class ContextData
127 {
128 public:
129     ContextData() : lineNumber(0), address(0) {}
130
131 public:
132     QString fileName;
133     int lineNumber;
134     quint64 address;
135 };
136
137 } // namespace Internal
138
139
140 // FIXME: DEBUGGER_EXPORT?
141 class DEBUGGER_EXPORT DebuggerEngine : public QObject
142 {
143     Q_OBJECT
144
145 public:
146     explicit DebuggerEngine(const DebuggerStartParameters &sp,
147         DebuggerLanguages languages,
148         DebuggerEngine *parentEngine = 0);
149     virtual ~DebuggerEngine();
150
151     const DebuggerStartParameters &startParameters() const;
152     DebuggerStartParameters &startParameters();
153
154     virtual bool setToolTipExpression(const QPoint & mousePos,
155         TextEditor::ITextEditor *editor, const Internal::DebuggerToolTipContext &);
156
157     virtual void updateWatchData(const Internal::WatchData &data,
158         const Internal::WatchUpdateFlags & flags = Internal::WatchUpdateFlags());
159     virtual void startDebugger(DebuggerRunControl *runControl);
160
161     virtual void watchPoint(const QPoint &);
162
163     enum MemoryViewFlags
164     {
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).
168     };
169
170     virtual void openMemoryView(quint64 startAddr, unsigned flags,
171                                 const QList<Internal::MemoryMarkup> &ml,
172                                 const QPoint &pos,
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);
182
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);
189
190     virtual void reloadRegisters();
191     virtual void reloadSourceFiles();
192     virtual void reloadFullStack();
193
194     virtual void setRegisterValue(int regnr, const QString &value);
195     virtual void addOptionPages(QList<Core::IOptionsPage*> *) const;
196     virtual unsigned debuggerCapabilities() const;
197
198     virtual bool isSynchronous() const;
199     virtual QByteArray qtNamespace() const;
200
201     virtual void createSnapshot();
202     virtual void updateAll();
203
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
211
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);
216
217     virtual void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
218     virtual void handleRemoteSetupFailed(const QString &message);
219
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;
227
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;
237
238     void progressPing();
239     void handleFinished();
240     void handleStartFailed();
241     bool debuggerActionsEnabled() const;
242     static bool debuggerActionsEnabled(DebuggerState state);
243
244     DebuggerState state() const;
245     DebuggerState lastGoodState() const;
246     DebuggerState targetState() const;
247     bool isDying() const;
248
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);
254
255     static const char *stateName(int s);
256
257     void notifyInferiorPid(qint64 pid);
258     qint64 inferiorPid() const;
259     bool isReverseDebugging() const;
260     void handleCommand(int role, const QVariant &value);
261
262     // Convenience
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;
266
267     virtual void resetLocation();
268     virtual void gotoLocation(const Internal::Location &location);
269     virtual void quitDebugger(); // called by DebuggerRunControl
270
271     virtual void updateViews();
272     bool isSlaveEngine() const;
273     bool isMasterEngine() const;
274     DebuggerEngine *masterEngine() const;
275
276     DebuggerLanguages languages() const;
277
278     virtual bool setupQmlStep(bool /*on*/) { return false; }
279     virtual void readyToExecuteQmlStep() {}
280
281     virtual bool canDisplayTooltip() const { return state() == InferiorStopOk; }
282
283     virtual void notifyInferiorIll();
284
285 signals:
286     void stateChanged(const Debugger::DebuggerState &state);
287     // A new stack frame is on display including locals.
288     void stackFrameCompleted();
289     void updateViewsRequested();
290     /*
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.
297      */
298     void requestRemoteSetup();
299
300 protected:
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();
307
308     virtual void notifyInferiorSetupOk();
309     virtual void notifyInferiorSetupFailed();
310
311     virtual void notifyEngineRunAndInferiorRunOk();
312     virtual void notifyEngineRunAndInferiorStopOk();
313     virtual void notifyInferiorUnrunnable(); // Called by CoreAdapter.
314
315     // Use notifyInferiorRunRequested() plus notifyInferiorRunOk() instead.
316     //virtual void notifyInferiorSpontaneousRun();
317
318     virtual void notifyInferiorRunRequested();
319     virtual void notifyInferiorRunOk();
320     virtual void notifyInferiorRunFailed();
321
322     virtual void notifyInferiorStopOk();
323     virtual void notifyInferiorSpontaneousStop();
324     virtual void notifyInferiorStopFailed();
325     virtual void notifyInferiorExited();
326
327     virtual void notifyInferiorShutdownOk();
328     virtual void notifyInferiorShutdownFailed();
329
330     virtual void notifyEngineSpontaneousShutdown();
331     virtual void notifyEngineShutdownOk();
332     virtual void notifyEngineShutdownFailed();
333
334     virtual void notifyEngineIll();
335
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;
341
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();
350
351     virtual void continueInferior();
352     virtual void interruptInferior();
353     virtual void requestInterruptInferior();
354
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);
359
360     virtual void frameUp();
361     virtual void frameDown();
362
363     DebuggerRunControl *runControl() const;
364
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);
382
383     static bool isCppBreakpoint(const Internal::BreakpointParameters &p);
384
385     bool isStateDebugging() const;
386     void setStateDebugging(bool on);
387
388     virtual void setupSlaveInferior();
389     virtual void setupSlaveEngine();
390     virtual void runSlaveEngine();
391     virtual void shutdownSlaveEngine();
392
393     virtual void slaveEngineStateChanged(DebuggerEngine *engine,
394         DebuggerState state);
395
396 private:
397     // Wrapper engine needs access to state of its subengines.
398     friend class Internal::QmlCppEngine;
399     friend class Internal::DebuggerPluginPrivate;
400     friend class QmlAdapter;
401
402     virtual void setState(DebuggerState state, bool forced = false);
403
404     friend class DebuggerEnginePrivate;
405     DebuggerEnginePrivate *d;
406 };
407
408 } // namespace Debugger
409
410 Q_DECLARE_METATYPE(Debugger::Internal::ContextData)
411
412 #endif // DEBUGGER_DEBUGGERENGINE_H