OSDN Git Service

It's 2011 now.
[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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef DEBUGGER_DEBUGGERENGINE_H
35 #define DEBUGGER_DEBUGGERENGINE_H
36
37 #include "debugger_global.h"
38 #include "debuggerconstants.h"
39 #include "breakpoint.h" // For 'BreakpointId'
40
41 #include <QtCore/QObject>
42 #include <QtCore/QStringList>
43
44 QT_BEGIN_NAMESPACE
45 class QDebug;
46 class QPoint;
47 class QMessageBox;
48 class QAbstractItemModel;
49 QT_END_NAMESPACE
50
51 namespace TextEditor {
52 class ITextEditor;
53 }
54
55 namespace Core {
56 class IOptionsPage;
57 }
58
59 namespace Debugger {
60
61 class DebuggerEnginePrivate;
62 class DebuggerRunControl;
63 class DebuggerStartParameters;
64
65 DEBUGGER_EXPORT QDebug operator<<(QDebug str, const DebuggerStartParameters &);
66 DEBUGGER_EXPORT QDebug operator<<(QDebug str, DebuggerState state);
67
68 namespace Internal {
69
70 class DebuggerPluginPrivate;
71 class DisassemblerAgent;
72 class MemoryAgent;
73 class WatchData;
74 class BreakHandler;
75 class ModulesHandler;
76 class RegisterHandler;
77 class StackHandler;
78 class StackFrame;
79 class SourceFilesHandler;
80 class ThreadsHandler;
81 class WatchHandler;
82 class BreakpointParameters;
83 class QmlCppEngine;
84
85 struct WatchUpdateFlags
86 {
87     WatchUpdateFlags() : tryIncremental(false) {}
88     bool tryIncremental;
89 };
90
91 class Location
92 {
93 public:
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; }
110
111 private:
112     void init() { m_needsMarker = false; m_needsRaise = true; m_lineNumber = -1;
113         m_address = 0; m_hasDebugInfo = true; }
114     bool m_needsMarker;
115     bool m_needsRaise;
116     bool m_hasDebugInfo;
117     int m_lineNumber;
118     QString m_fileName;
119     QString m_functionName;
120     quint64 m_address;
121 };
122
123 } // namespace Internal
124
125
126 // FIXME: DEBUGGER_EXPORT?
127 class DEBUGGER_EXPORT DebuggerEngine : public QObject
128 {
129     Q_OBJECT
130
131 public:
132     explicit DebuggerEngine(const DebuggerStartParameters &sp);
133     virtual ~DebuggerEngine();
134
135     typedef Internal::BreakpointId BreakpointId;
136     virtual void setToolTipExpression(const QPoint & mousePos,
137         TextEditor::ITextEditor *editor, int cursorPos);
138
139     virtual void updateWatchData(const Internal::WatchData &data,
140         const Internal::WatchUpdateFlags & flags = Internal::WatchUpdateFlags());
141     void startDebugger(DebuggerRunControl *runControl);
142
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);
151
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);
158
159     virtual void reloadRegisters();
160     virtual void reloadSourceFiles();
161     virtual void reloadFullStack();
162
163     virtual void setRegisterValue(int regnr, const QString &value);
164     virtual void addOptionPages(QList<Core::IOptionsPage*> *) const;
165     virtual unsigned debuggerCapabilities() const;
166
167     virtual bool isSynchronous() const;
168     virtual QByteArray qtNamespace() const;
169
170     virtual void createSnapshot();
171     virtual void updateAll();
172
173
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
180
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);
185
186     virtual void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
187     virtual void handleRemoteSetupFailed(const QString &message);
188
189 protected:
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();
199
200     virtual void continueInferior();
201     virtual void interruptInferior();
202     virtual void requestInterruptInferior();
203
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);
208
209     virtual void frameUp();
210     virtual void frameDown();
211
212 public:
213     const DebuggerStartParameters &startParameters() const;
214     DebuggerStartParameters &startParameters();
215
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;
223
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;
232
233     void progressPing();
234     void handleFinished();
235     void handleStartFailed();
236     bool debuggerActionsEnabled() const;
237     static bool debuggerActionsEnabled(DebuggerState state);
238
239     DebuggerState state() const;
240     DebuggerState lastGoodState() const;
241     DebuggerState targetState() const;
242     bool isDying() const;
243
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);
249
250     static const char *stateName(int s);
251
252     void notifyInferiorPid(qint64 pid);
253     qint64 inferiorPid() const;
254     bool isReverseDebugging() const;
255     void handleCommand(int role, const QVariant &value);
256
257     // Convenience
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;
261
262     void resetLocation();
263     virtual void gotoLocation(const Internal::Location &location);
264     virtual void quitDebugger(); // called by DebuggerRunControl
265
266     virtual void updateViews();
267     bool isSlaveEngine() const;
268
269 signals:
270     void stateChanged(const DebuggerState &state);
271     void updateViewsRequested();
272     /*
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.
279      */
280     void requestRemoteSetup();
281
282 protected:
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();
289
290     virtual void notifyInferiorSetupOk();
291     virtual void notifyInferiorSetupFailed();
292
293     virtual void notifyEngineRunAndInferiorRunOk();
294     virtual void notifyEngineRunAndInferiorStopOk();
295     virtual void notifyInferiorUnrunnable(); // Called by CoreAdapter.
296
297     // Use notifyInferiorRunRequested() plus notifyInferiorRunOk() instead.
298     //virtual void notifyInferiorSpontaneousRun();
299
300     virtual void notifyInferiorRunRequested();
301     virtual void notifyInferiorRunOk();
302     virtual void notifyInferiorRunFailed();
303
304     virtual void notifyInferiorStopOk();
305     virtual void notifyInferiorSpontaneousStop();
306     virtual void notifyInferiorStopFailed();
307     virtual void notifyInferiorExited();
308
309     virtual void notifyInferiorShutdownOk();
310     virtual void notifyInferiorShutdownFailed();
311
312     virtual void notifyEngineSpontaneousShutdown();
313     virtual void notifyEngineShutdownOk();
314     virtual void notifyEngineShutdownFailed();
315
316     virtual void notifyInferiorIll();
317     virtual void notifyEngineIll();
318
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;
324
325     DebuggerRunControl *runControl() const; // FIXME: Protect.
326
327 protected:
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);
341
342     static bool isCppBreakpoint(const Internal::BreakpointParameters &p);
343
344 private:
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);
349
350     friend class DebuggerEnginePrivate;
351     DebuggerEnginePrivate *d;
352 };
353
354 } // namespace Debugger
355
356 #endif // DEBUGGER_DEBUGGERENGINE_H