debuggerengine.h 10.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#ifndef DEBUGGER_DEBUGGERENGINE_H
#define DEBUGGER_DEBUGGERENGINE_H

#include "debugger_global.h"
#include "debuggerconstants.h"
#include "moduleshandler.h" // For 'Symbols'

#include <coreplugin/ssh/sshconnection.h> 

#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <QtCore/QStringList>

QT_BEGIN_NAMESPACE
class QDebug;
class QPoint;
46
class QMessageBox;
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
QT_END_NAMESPACE

namespace TextEditor {
class ITextEditor;
}

namespace Core {
class IOptionsPage;
}

namespace Debugger {

class DebuggerRunControl;
class DebuggerPlugin;

class DEBUGGER_EXPORT DebuggerStartParameters
{
public:
    DebuggerStartParameters();
    void clear();

    QString executable;
    QString displayName;
    QString coreFile;
    QStringList processArgs;
    QStringList environment;
    QString workingDirectory;
    qint64 attachPID;
    bool useTerminal;
    bool breakAtMain;
    QString crashParameter; // for AttachCrashedExternal
78

79
80
81
82
83
84
    // for remote debugging
    QString remoteChannel;
    QString remoteArchitecture;
    QString symbolFileName;
    QString serverStartScript;
    QString sysRoot;
85
86
    QByteArray remoteDumperLib;
    QByteArray remoteSourcesDir;
87
88
    QString remoteMountPoint;
    QString localMountDir;
89
90
    Core::SshConnectionParameters connParams;

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    QString debuggerCommand;
    int toolChainType;
    QString qtInstallPath;

    QString dumperLibrary;
    QStringList dumperLibraryLocations;
    DebuggerStartMode startMode;
};

DEBUGGER_EXPORT QDebug operator<<(QDebug str, const DebuggerStartParameters &);
DEBUGGER_EXPORT QDebug operator<<(QDebug str, DebuggerState state);

namespace Internal {

class DisassemblerViewAgent;
class MemoryViewAgent;
class Symbol;
class WatchData;
class BreakHandler;
class ModulesHandler;
class RegisterHandler;
class StackHandler;
class StackFrame;
class SourceFilesHandler;
class ThreadsHandler;
class WatchHandler;

class DebuggerEnginePrivate;

120
121
// FIXME: DEBUGGER_EXPORT?
class DEBUGGER_EXPORT DebuggerEngine : public QObject
122
123
124
125
126
127
128
{
    Q_OBJECT

public:
    DebuggerEngine(const DebuggerStartParameters &sp);
    virtual ~DebuggerEngine();

Friedemann Kleint's avatar
Friedemann Kleint committed
129
130
    virtual void setToolTipExpression(const QPoint & /* mousePos */,
            TextEditor::ITextEditor * /* editor */, int /* cursorPos */) { }
131
    void initializeFromTemplate(DebuggerEngine *other);
hjk's avatar
hjk committed
132
133

    virtual void updateWatchData(const WatchData & /* data */) { }
134
    void startDebugger(DebuggerRunControl *runControl);
hjk's avatar
hjk committed
135
136
137
138
139
140
141
142
143
    virtual bool isSessionEngine() const { return false; }

    virtual void watchPoint(const QPoint &) {}
    virtual void fetchMemory(MemoryViewAgent *, QObject *,
            quint64 addr, quint64 length);
    virtual void fetchDisassembler(DisassemblerViewAgent *) {}
    virtual void activateFrame(int index) { Q_UNUSED(index); }

    virtual void reloadModules() {}
144
    virtual void examineModules() {}
hjk's avatar
hjk committed
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    virtual void loadSymbols(const QString &moduleName)
        { Q_UNUSED(moduleName); }
    virtual void loadAllSymbols() {}
    virtual void requestModuleSymbols(const QString &moduleName)
        { Q_UNUSED(moduleName); }

    virtual void reloadRegisters() {}
    virtual void reloadSourceFiles() {}
    virtual void reloadFullStack() {}

    virtual void setRegisterValue(int regnr, const QString &value);
    virtual void addOptionPages(QList<Core::IOptionsPage*> *) const {}
    virtual unsigned debuggerCapabilities() const { return 0; }

    virtual bool isSynchroneous() const { return false; }
    virtual QString qtNamespace() const { return QString(); }

162
    virtual void createSnapshot() {}
163
    virtual void updateAll() {}
hjk's avatar
hjk committed
164
165
166
167
168
169
170

    virtual void attemptBreakpointSynchronization() {}
    virtual void selectThread(int index) { Q_UNUSED(index); }

    virtual void assignValueInDebugger(const QString &expr, const QString &value)
        { Q_UNUSED(expr); Q_UNUSED(value); }

171
172
173
174
    // Convenience
    static QMessageBox *showMessageBox
        (int icon, const QString &title, const QString &text, int buttons = 0);

hjk's avatar
hjk committed
175
protected:
176
177
178
179
180
181
182
183
184
185
186
    virtual void detachDebugger() {}
    virtual void executeStep() {}
    virtual void executeStepOut()  {}
    virtual void executeNext() {}
    virtual void executeStepI() {}
    virtual void executeNextI() {}
    virtual void executeReturn() {}

    virtual void continueInferior() {}
    virtual void interruptInferior() {}

187
188
    virtual void requestInterruptInferior();

189
190
191
192
193
194
195
196
197
198
199
200
201
    virtual void executeRunToLine(const QString &fileName, int lineNumber)
        { Q_UNUSED(fileName); Q_UNUSED(lineNumber); }
    virtual void executeRunToFunction(const QString &functionName)
        { Q_UNUSED(functionName); }
    virtual void executeJumpToLine(const QString &fileName, int lineNumber)
        { Q_UNUSED(fileName); Q_UNUSED(lineNumber); }
    virtual void executeDebuggerCommand(const QString &command)
        { Q_UNUSED(command); }

    virtual void frameUp();
    virtual void frameDown();

public:
202
    static DebuggerPlugin *plugin();
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
    const DebuggerStartParameters &startParameters() const;
    DebuggerStartParameters &startParameters();

    ModulesHandler *modulesHandler() const;
    BreakHandler *breakHandler() const;
    RegisterHandler *registerHandler() const;
    StackHandler *stackHandler() const;
    ThreadsHandler *threadsHandler() const;
    WatchHandler *watchHandler() const;
    SourceFilesHandler *sourceFilesHandler() const;

    QAbstractItemModel *commandModel() const;
    QAbstractItemModel *modulesModel() const;
    QAbstractItemModel *breakModel() const;
    QAbstractItemModel *registerModel() const;
    QAbstractItemModel *stackModel() const;
    QAbstractItemModel *threadsModel() const;
    QAbstractItemModel *localsModel() const;
    QAbstractItemModel *watchersModel() const;
    QAbstractItemModel *returnModel() const;
223
    //QAbstractItemModel *snapshotModel() const;
224
225
    QAbstractItemModel *sourceFilesModel() const;

226
    void progressPing();
227
    void handleFinished();
228
    void handleStartFailed();
229
230
231
232
233
234
235
236
237
238
239
240
241
    bool debuggerActionsEnabled() const;
    static bool debuggerActionsEnabled(DebuggerState state);
    void showModuleSymbols(const QString &moduleName, const Symbols &symbols);

    void breakByFunction(const QString &functionName);
    void breakByFunctionMain();
    
    void executeStepX();
    void executeStepOutX();
    void executeStepNextX();
    void executeReturnX();

    DebuggerState state() const;
hjk's avatar
hjk committed
242
243
244
    DebuggerState lastGoodState() const;
    DebuggerState targetState() const;
    bool isDying() const { return targetState() == DebuggerFinished; }
245
246
247
248
249

    // Dumper stuff (common to cdb and gdb).
    bool qtDumperLibraryEnabled() const;
    QString qtDumperLibraryName() const;
    QStringList qtDumperLibraryLocations() const;
250
    void showQtDumperLibraryWarning(const QString &details);
251
252
253
254
255
256

    static const char *stateName(int s);

    void notifyInferiorPid(qint64 pid);
    qint64 inferiorPid() const;
    bool isReverseDebugging() const;
257
258
    bool isActive() const; // True if this is the currently active engine;
    void setActive(bool on); // FIXME: private?
259
    void handleCommand(int role, const QVariant &value);
260

261
    // Convenience
Friedemann Kleint's avatar
Friedemann Kleint committed
262
263
    Q_SLOT void showMessage(const QString &msg, int channel = LogDebug, int timeout = -1) const;
    Q_SLOT void showStatusMessage(const QString &msg, int timeout = -1) const;
264

265
266
267
268
    void resetLocation();
    void openFile(const QString &fileName, int lineNumber = -1);
    void gotoLocation(const QString &fileName, int lineNumber, bool setMarker);
    void gotoLocation(const StackFrame &frame, bool setMarker);
hjk's avatar
hjk committed
269
    virtual void quitDebugger(); // called by DebuggerRunControl
270
271

protected:
272
273
    void notifyEngineSetupOk();
    void notifyEngineSetupFailed();
hjk's avatar
hjk committed
274
    void notifyEngineRunFailed();
275

hjk's avatar
hjk committed
276
277
278
    void notifyInferiorSetupOk();
    void notifyInferiorSetupFailed();

hjk's avatar
hjk committed
279
280
281
    void notifyEngineRunAndInferiorRunOk();
    void notifyEngineRunAndInferiorStopOk();
    void notifyInferiorUnrunnable(); // Called by CoreAdapter.
hjk's avatar
hjk committed
282
283

    // Use notifyInferiorRunRequested() plus notifyInferiorRunOk() instead.
hjk's avatar
hjk committed
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
    //void notifyInferiorSpontaneousRun();

    void notifyInferiorRunRequested();
    void notifyInferiorRunOk();
    void notifyInferiorRunFailed();

    void notifyInferiorStopOk();
    void notifyInferiorSpontaneousStop();
    void notifyInferiorStopFailed();
    void notifyInferiorExited();

    void notifyInferiorShutdownOk();
    void notifyInferiorShutdownFailed();

    void notifyEngineSpontaneousShutdown();
    void notifyEngineShutdownOk();
    void notifyEngineShutdownFailed();
301
302

    void notifyInferiorIll();
hjk's avatar
hjk committed
303
    void notifyEngineIll();
304

hjk's avatar
hjk committed
305
306
307
308
309
    virtual void setupEngine() = 0;
    virtual void setupInferior() = 0;
    virtual void runEngine() = 0;
    virtual void shutdownInferior() = 0;
    virtual void shutdownEngine() = 0;
hjk's avatar
hjk committed
310

hjk's avatar
hjk committed
311
private:
hjk's avatar
hjk committed
312
313
    void setState(DebuggerState state, bool forced = false);

hjk's avatar
hjk committed
314
315
316
317
private:
    void executeRunToLine();
    void executeRunToFunction();
    void executeJumpToLine();
hjk's avatar
hjk committed
318
    void addToWatchWindow();
hjk's avatar
hjk committed
319

hjk's avatar
hjk committed
320
    friend class DebuggerEnginePrivate;
321
322
323
324
325
326
327
    DebuggerEnginePrivate *d;
};

} // namespace Internal
} // namespace Debugger

#endif // DEBUGGER_DEBUGGERENGINE_H