debuggermanager.h 10.2 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
42
43
#include <QtCore/QStringList>
#include <QtCore/QVariant>

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

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

58
namespace TextEditor {
59
class ITextEditor;
60
61
}

62
63
64
65
namespace CPlusPlus {
    class Snapshot;
}

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

class DebuggerOutputWindow;
class DebuggerPlugin;

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

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

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

    QString dumperLibrary;
    QStringList dumperLibraryLocations;
hjk's avatar
hjk committed
125
    DebuggerStartMode startMode;
126
127
};

hjk's avatar
hjk committed
128
typedef QSharedPointer<DebuggerStartParameters> DebuggerStartParametersPtr;
129
130

DEBUGGER_EXPORT QDebug operator<<(QDebug str, const DebuggerStartParameters &);
131
132

// Flags for initialization
hjk's avatar
hjk committed
133
134
135
136
137
138
139
140
enum DebuggerEngineTypeFlags
{
    GdbEngineType     = 0x01,
    ScriptEngineType  = 0x02,
    CdbEngineType     = 0x04,
    AllEngineTypes = GdbEngineType
        | ScriptEngineType 
        | CdbEngineType 
141
142
};

hjk's avatar
hjk committed
143
QDebug operator<<(QDebug d, DebuggerState state);
con's avatar
con committed
144
145

//
hjk's avatar
hjk committed
146
// DebuggerManager
con's avatar
con committed
147
148
//

149
150
struct DebuggerManagerPrivate;

151
class DEBUGGER_EXPORT DebuggerManager : public QObject
con's avatar
con committed
152
{
hjk's avatar
hjk committed
153
    Q_OBJECT
con's avatar
con committed
154

hjk's avatar
hjk committed
155
156
157
public:
    DebuggerManager();
    ~DebuggerManager();
158

159
160
161
162
    friend class Internal::IDebuggerEngine;
    friend class Internal::DebuggerPlugin;
    friend class Internal::CdbDebugEventCallback;
    friend class Internal::CdbDumperHelper;
163
    friend class Internal::CdbDumperInitThread;
164
165
166
167
168
    friend class Internal::CdbExceptionLoggerEventCallback;
    friend class Internal::GdbEngine;
    friend class Internal::ScriptEngine;
    friend class Internal::CdbDebugEngine;
    friend struct Internal::CdbDebugEnginePrivate;
con's avatar
con committed
169

170
    DebuggerState state() const;
171
    QList<Core::IOptionsPage*> initializeEngines(unsigned enabledTypeFlags);
172

173
    Utils::FancyMainWindow *mainWindow() const;
174
    QLabel *statusLabel() const;
175
    Internal::IDebuggerEngine *currentEngine() const;
con's avatar
con committed
176

177
178
    DebuggerStartParametersPtr startParameters() const;
    qint64 inferiorPid() const;
hjk's avatar
hjk committed
179

180
181
    void showMessageBox(int icon, const QString &title, const QString &text);

182
183
    bool debuggerActionsEnabled() const;

184
185
186
187
188
    bool checkDebugConfiguration(int toolChain,
                                 QString *errorMessage,
                                 QString *settingsCategory = 0,
                                 QString *settingsPage = 0) const;

189
190
    const CPlusPlus::Snapshot &cppCodeModelSnapshot() const;

191
192
    static DebuggerManager *instance();

con's avatar
con committed
193
public slots:
hjk's avatar
hjk committed
194
    void startNewDebugger(const DebuggerStartParametersPtr &sp);
195
196
    void exitDebugger();

con's avatar
con committed
197
198
199
200
201
    void setSimpleDockWidgetArrangement();

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

202
    void gotoLocation(const Debugger::Internal::StackFrame &frame, bool setLocationMarker);
203
    void fileOpen(const QString &file);
con's avatar
con committed
204
205
206
207
208
209
210
211
212
    void resetLocation();

    void interruptDebuggingRequest();

    void jumpToLineExec();
    void runToLineExec();
    void runToFunctionExec();
    void toggleBreakpoint();
    void breakByFunction(const QString &functionName);
213
    void breakByFunctionMain();
con's avatar
con committed
214
215
216
217
218
219
220
221
    void setBreakpoint(const QString &fileName, int lineNumber);
    void activateFrame(int index);
    void selectThread(int index);

    void stepExec();
    void stepOutExec();
    void nextExec();
    void continueExec();
222
    void detachDebugger();
con's avatar
con committed
223
224

    void addToWatchWindow();
225
    void updateWatchData(const Debugger::Internal::WatchData &data);
226

con's avatar
con committed
227
    void sessionLoaded();
228
    void aboutToUnloadSession();
con's avatar
con committed
229
    void aboutToSaveSession();
230
231
    QVariant sessionValue(const QString &name);
    void setSessionValue(const QString &name, const QVariant &value);
con's avatar
con committed
232

233
    void assignValueInDebugger();
con's avatar
con committed
234
    void assignValueInDebugger(const QString &expr, const QString &value);
235
236

    void executeDebuggerCommand();
con's avatar
con committed
237
238
    void executeDebuggerCommand(const QString &command);

239
    void watchPoint();
240
    void setRegisterValue(int nr, const QString &value);
241

242
    void showStatusMessage(const QString &msg, int timeout = -1); // -1 forever
243
    void clearCppCodeModelSnapshot();
con's avatar
con committed
244

245
246
    static const char *stateName(int s);

247
public slots: // FIXME
hjk's avatar
hjk committed
248
249
    void showDebuggerOutput(const QString &msg)
        { showDebuggerOutput(LogDebug, msg); }
Friedemann Kleint's avatar
Friedemann Kleint committed
250
251
   void ensureLogVisible();

hjk's avatar
hjk committed
252
//private slots:  // FIXME
253
254
    void showDebuggerOutput(int channel, const QString &msg);
    void showDebuggerInput(int channel, const QString &msg);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
255
    void showApplicationOutput(const QString &data);
con's avatar
con committed
256

257
258
259
    void reloadSourceFiles();
    void sourceFilesDockToggled(bool on);

con's avatar
con committed
260
261
262
263
264
265
266
    void reloadModules();
    void modulesDockToggled(bool on);
    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();

    void reloadRegisters();
    void registerDockToggled(bool on);
267
    void clearStatusMessage();
268
    void attemptBreakpointSynchronization();
269
    void reloadFullStack();
270
    void operateByInstructionTriggered();
hjk's avatar
hjk committed
271
    void startFailed();
con's avatar
con committed
272
273

private:
274
275
276
277
278
279
280
    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;
281
282
    QWidget *threadsWindow() const;        

283
    Internal::DebuggerManagerActions debuggerManagerActions() const;
284

con's avatar
con committed
285
286
287
    void notifyInferiorStopped();
    void notifyInferiorRunning();
    void notifyInferiorExited();
288
    void notifyInferiorPidChanged(qint64);
con's avatar
con committed
289

290
    void cleanupViews();
con's avatar
con committed
291

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

294
    //
con's avatar
con committed
295
    // internal implementation
296
    //
297
298
299
300
301
302
303
    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
304
305
306
307
308
    Q_SLOT void loadSessionData();
    Q_SLOT void saveSessionData();
    Q_SLOT void dumpLog();

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

con's avatar
con committed
313
314
315
signals:
    void debuggingFinished();
    void inferiorPidChanged(qint64 pid);
hjk's avatar
hjk committed
316
    void stateChanged(int newstatus);
con's avatar
con committed
317
318
319
    void debugModeRequested();
    void previousModeRequested();
    void statusMessageRequested(const QString &msg, int timeout); // -1 for 'forever'
320
    void gotoLocationRequested(const QString &file, int line, bool setLocationMarker);
con's avatar
con committed
321
322
323
324
325
326
    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
327
    void applicationOutputAvailable(const QString &output);
328
329
    void emitShowOutput(int channel, const QString &output);
    void emitShowInput(int channel, const QString &input);
con's avatar
con committed
330
331

private:
332
    void init();
hjk's avatar
hjk committed
333
    void runTest(const QString &fileName);
hjk's avatar
hjk committed
334
    Q_SLOT void createNewDock(QWidget *widget);
con's avatar
con committed
335
336
337
338

    void shutdown();

    void toggleBreakpoint(const QString &fileName, int lineNumber);
339
    void toggleBreakpointEnabled(const QString &fileName, int lineNumber);
340
    Internal::BreakpointData *findBreakpoint(const QString &fileName, int lineNumber);
hjk's avatar
hjk committed
341
342
    void setToolTipExpression(const QPoint &mousePos,
        TextEditor::ITextEditor *editor, int cursorPos);
con's avatar
con committed
343

344
    DebuggerManagerPrivate *d;
con's avatar
con committed
345
346
347
348
349
};

} // namespace Debugger

#endif // DEBUGGER_DEBUGGERMANAGER_H