debuggermanager.h 10.3 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** 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.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
#ifndef DEBUGGER_DEBUGGERMANAGER_H
#define DEBUGGER_DEBUGGERMANAGER_H

33
#include "debugger_global.h"
hjk's avatar
hjk committed
34
35
#include "debuggerconstants.h"

con's avatar
con committed
36
#include <QtCore/QObject>
37
#include <QtCore/QSharedPointer>
con's avatar
con committed
38
39
40
41
#include <QtCore/QStringList>
#include <QtCore/QVariant>

QT_BEGIN_NAMESPACE
42
class QAbstractItemModel;
con's avatar
con committed
43
class QAction;
44
class QDebug;
con's avatar
con committed
45
class QDockWidget;
46
class QLabel;
47
class QMessageBox;
48
49
class QPoint;
class QVariant;
con's avatar
con committed
50
51
QT_END_NAMESPACE

52
namespace Core {
53
class IOptionsPage;
54
}
55
56
57
namespace Utils {
class FancyMainWindow;
}
58

59
namespace TextEditor {
60
class ITextEditor;
61
62
}

63
64
65
66
namespace CPlusPlus {
    class Snapshot;
}

con's avatar
con committed
67
68
69
70
71
72
73
namespace Debugger {
namespace Internal {

class DebuggerOutputWindow;
class DebuggerPlugin;

class BreakHandler;
74
class BreakpointData;
con's avatar
con committed
75
76
class ModulesHandler;
class RegisterHandler;
77
class SourceFilesWindow;
78
struct StackFrame;
con's avatar
con committed
79
class StackHandler;
80
class Symbol;
con's avatar
con committed
81
82
class ThreadsHandler;
class WatchData;
83
class WatchHandler;
84
85
86
87
class IDebuggerEngine;
class GdbEngine;
class ScriptEngine;
class CdbDebugEngine;
88
class CdbDebugEnginePrivate;
89
struct DebuggerManagerActions;
90
91
92
class DebuggerPlugin;
class CdbDebugEventCallback;
class CdbDumperHelper;
93
class CdbDumperInitThread;
94
95
96
class CdbExceptionLoggerEventCallback;
class GdbEngine;
class CdbDebugEngine;
97
class CdbDebugEnginePrivate;
98
} // namespace Internal
con's avatar
con committed
99

100
class DEBUGGER_EXPORT DebuggerStartParameters
101
{
102
public:
103
104
105
106
107
108
109
110
111
112
113
    DebuggerStartParameters();
    void clear();

    QString executable;
    QString coreFile;
    QStringList processArgs;
    QStringList environment;
    QString workingDir;
    QString buildDir;
    qint64 attachPID;
    bool useTerminal;
114
    QString crashParameter; // for AttachCrashedExternal
115
116
    // for remote debugging
    QString remoteChannel;
117
    int remoteChannelType;
118
    QString remoteArchitecture;
119
    QString symbolFileName;
120
    QString serverStartScript;
121
    QString sysRoot;
ck's avatar
ck committed
122
    QString debuggerCommand;
123
    int toolChainType;
ck's avatar
ck committed
124
    QString remoteDumperLib;
hjk's avatar
hjk committed
125
    QString qtInstallPath;
hjk's avatar
hjk committed
126
127
128

    QString dumperLibrary;
    QStringList dumperLibraryLocations;
hjk's avatar
hjk committed
129
    DebuggerStartMode startMode;
130
131
};

hjk's avatar
hjk committed
132
typedef QSharedPointer<DebuggerStartParameters> DebuggerStartParametersPtr;
133
134

DEBUGGER_EXPORT QDebug operator<<(QDebug str, const DebuggerStartParameters &);
135
136

// Flags for initialization
hjk's avatar
hjk committed
137
138
139
140
141
142
143
144
enum DebuggerEngineTypeFlags
{
    GdbEngineType     = 0x01,
    ScriptEngineType  = 0x02,
    CdbEngineType     = 0x04,
    AllEngineTypes = GdbEngineType
        | ScriptEngineType 
        | CdbEngineType 
145
146
};

hjk's avatar
hjk committed
147
QDebug operator<<(QDebug d, DebuggerState state);
con's avatar
con committed
148
149

//
hjk's avatar
hjk committed
150
// DebuggerManager
con's avatar
con committed
151
152
//

153
154
struct DebuggerManagerPrivate;

155
class DEBUGGER_EXPORT DebuggerManager : public QObject
con's avatar
con committed
156
{
hjk's avatar
hjk committed
157
    Q_OBJECT
con's avatar
con committed
158

hjk's avatar
hjk committed
159
160
161
public:
    DebuggerManager();
    ~DebuggerManager();
162

163
164
165
166
    friend class Internal::IDebuggerEngine;
    friend class Internal::DebuggerPlugin;
    friend class Internal::CdbDebugEventCallback;
    friend class Internal::CdbDumperHelper;
167
    friend class Internal::CdbDumperInitThread;
168
169
170
171
    friend class Internal::CdbExceptionLoggerEventCallback;
    friend class Internal::GdbEngine;
    friend class Internal::ScriptEngine;
    friend class Internal::CdbDebugEngine;
172
    friend class Internal::CdbDebugEnginePrivate;
con's avatar
con committed
173

174
    DebuggerState state() const;
175
    QList<Core::IOptionsPage*> initializeEngines(unsigned enabledTypeFlags);
176

177
    Utils::FancyMainWindow *mainWindow() const;
178
    QLabel *statusLabel() const;
179
    Internal::IDebuggerEngine *currentEngine() const;
con's avatar
con committed
180

181
182
    DebuggerStartParametersPtr startParameters() const;
    qint64 inferiorPid() const;
hjk's avatar
hjk committed
183

184
185
    QMessageBox *showMessageBox(int icon, const QString &title, const QString &text,
        int buttons = 0);
186

187
188
    bool debuggerActionsEnabled() const;

189
190
191
192
193
    bool checkDebugConfiguration(int toolChain,
                                 QString *errorMessage,
                                 QString *settingsCategory = 0,
                                 QString *settingsPage = 0) const;

194
195
    const CPlusPlus::Snapshot &cppCodeModelSnapshot() const;

196
197
    static DebuggerManager *instance();

con's avatar
con committed
198
public slots:
hjk's avatar
hjk committed
199
    void startNewDebugger(const DebuggerStartParametersPtr &sp);
200
201
    void exitDebugger();

con's avatar
con committed
202
203
204
205
206
    void setSimpleDockWidgetArrangement();

    void setBusyCursor(bool on);
    void queryCurrentTextEditor(QString *fileName, int *lineNumber, QObject **ed);

207
    void gotoLocation(const Debugger::Internal::StackFrame &frame, bool setLocationMarker);
208
    void fileOpen(const QString &file);
con's avatar
con committed
209
210
211
212
213
214
215
216
217
    void resetLocation();

    void interruptDebuggingRequest();

    void jumpToLineExec();
    void runToLineExec();
    void runToFunctionExec();
    void toggleBreakpoint();
    void breakByFunction(const QString &functionName);
218
    void breakByFunctionMain();
con's avatar
con committed
219
220
221
222
223
224
225
226
    void setBreakpoint(const QString &fileName, int lineNumber);
    void activateFrame(int index);
    void selectThread(int index);

    void stepExec();
    void stepOutExec();
    void nextExec();
    void continueExec();
227
    void detachDebugger();
con's avatar
con committed
228
229

    void addToWatchWindow();
230
    void updateWatchData(const Debugger::Internal::WatchData &data);
231

con's avatar
con committed
232
    void sessionLoaded();
233
    void aboutToUnloadSession();
con's avatar
con committed
234
    void aboutToSaveSession();
235
236
    QVariant sessionValue(const QString &name);
    void setSessionValue(const QString &name, const QVariant &value);
con's avatar
con committed
237

238
    void assignValueInDebugger();
con's avatar
con committed
239
    void assignValueInDebugger(const QString &expr, const QString &value);
240
241

    void executeDebuggerCommand();
con's avatar
con committed
242
243
    void executeDebuggerCommand(const QString &command);

244
    void watchPoint();
245
    void setRegisterValue(int nr, const QString &value);
246

247
    void showStatusMessage(const QString &msg, int timeout = -1); // -1 forever
248
    void clearCppCodeModelSnapshot();
con's avatar
con committed
249

250
251
    static const char *stateName(int s);

252
public slots: // FIXME
hjk's avatar
hjk committed
253
254
    void showDebuggerOutput(const QString &msg)
        { showDebuggerOutput(LogDebug, msg); }
Friedemann Kleint's avatar
Friedemann Kleint committed
255
256
   void ensureLogVisible();

hjk's avatar
hjk committed
257
//private slots:  // FIXME
258
259
    void showDebuggerOutput(int channel, const QString &msg);
    void showDebuggerInput(int channel, const QString &msg);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
260
    void showApplicationOutput(const QString &data);
con's avatar
con committed
261

262
263
264
    void reloadSourceFiles();
    void sourceFilesDockToggled(bool on);

con's avatar
con committed
265
266
267
268
269
270
271
    void reloadModules();
    void modulesDockToggled(bool on);
    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();

    void reloadRegisters();
    void registerDockToggled(bool on);
272
    void clearStatusMessage();
273
    void attemptBreakpointSynchronization();
274
    void reloadFullStack();
275
    void operateByInstructionTriggered();
hjk's avatar
hjk committed
276
    void startFailed();
con's avatar
con committed
277
278

private:
279
280
281
282
283
284
285
    Internal::ModulesHandler *modulesHandler() const;
    Internal::BreakHandler *breakHandler() const;
    Internal::RegisterHandler *registerHandler() const;
    Internal::StackHandler *stackHandler() const;
    Internal::ThreadsHandler *threadsHandler() const;
    Internal::WatchHandler *watchHandler() const;
    Internal::SourceFilesWindow *sourceFileWindow() const;
286
287
    QWidget *threadsWindow() const;        

288
    Internal::DebuggerManagerActions debuggerManagerActions() const;
289

con's avatar
con committed
290
291
292
    void notifyInferiorStopped();
    void notifyInferiorRunning();
    void notifyInferiorExited();
293
    void notifyInferiorPidChanged(qint64);
con's avatar
con committed
294

295
    void cleanupViews();
con's avatar
con committed
296

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
297
    void setState(DebuggerState state, bool forced = false);
hjk's avatar
hjk committed
298

299
    //
con's avatar
con committed
300
    // internal implementation
301
    //
302
303
304
305
306
307
308
    bool qtDumperLibraryEnabled() const;
    QString qtDumperLibraryName() const;
    QStringList qtDumperLibraryLocations() const;
    void showQtDumperLibraryWarning(const QString &details = QString());
    bool isReverseDebugging() const;
    QAbstractItemModel *threadsModel();

con's avatar
con committed
309
310
311
312
313
    Q_SLOT void loadSessionData();
    Q_SLOT void saveSessionData();
    Q_SLOT void dumpLog();

public:
314
    // stuff in this block should be made private by moving it to
con's avatar
con committed
315
    // one of the interfaces
316
    QList<Internal::Symbol> moduleSymbols(const QString &moduleName);
317

con's avatar
con committed
318
319
320
signals:
    void debuggingFinished();
    void inferiorPidChanged(qint64 pid);
hjk's avatar
hjk committed
321
    void stateChanged(int newstatus);
con's avatar
con committed
322
323
324
    void debugModeRequested();
    void previousModeRequested();
    void statusMessageRequested(const QString &msg, int timeout); // -1 for 'forever'
325
    void gotoLocationRequested(const QString &file, int line, bool setLocationMarker);
con's avatar
con committed
326
327
328
329
330
331
    void resetLocationRequested();
    void currentTextEditorRequested(QString *fileName, int *lineNumber, QObject **ob);
    void sessionValueRequested(const QString &name, QVariant *value);
    void setSessionValueRequested(const QString &name, const QVariant &value);
    void configValueRequested(const QString &name, QVariant *value);
    void setConfigValueRequested(const QString &name, const QVariant &value);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
332
    void applicationOutputAvailable(const QString &output);
333
334
    void emitShowOutput(int channel, const QString &output);
    void emitShowInput(int channel, const QString &input);
con's avatar
con committed
335
336

private:
337
    void init();
hjk's avatar
hjk committed
338
    void runTest(const QString &fileName);
hjk's avatar
hjk committed
339
    Q_SLOT void createNewDock(QWidget *widget);
con's avatar
con committed
340
341
342
343

    void shutdown();

    void toggleBreakpoint(const QString &fileName, int lineNumber);
344
    void toggleBreakpointEnabled(const QString &fileName, int lineNumber);
345
    Internal::BreakpointData *findBreakpoint(const QString &fileName, int lineNumber);
hjk's avatar
hjk committed
346
347
    void setToolTipExpression(const QPoint &mousePos,
        TextEditor::ITextEditor *editor, int cursorPos);
con's avatar
con committed
348

349
    DebuggerManagerPrivate *d;
con's avatar
con committed
350
351
352
353
354
};

} // namespace Debugger

#endif // DEBUGGER_DEBUGGERMANAGER_H