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
#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
88
89
class IDebuggerEngine;
class GdbEngine;
class ScriptEngine;
class CdbDebugEngine;
struct CdbDebugEnginePrivate;
struct DebuggerManagerActions;
90
91
92
class DebuggerPlugin;
class CdbDebugEventCallback;
class CdbDumperHelper;
93
class CdbDumperInitThread;
94
95
96
97
98
class CdbExceptionLoggerEventCallback;
class GdbEngine;
class CdbDebugEngine;
struct CdbDebugEnginePrivate;
} // 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
    int toolChainType;
hjk's avatar
hjk committed
122
    QString qtInstallPath;
hjk's avatar
hjk committed
123
124
125

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

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

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

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

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

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

150
151
struct DebuggerManagerPrivate;

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

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

160
161
162
163
    friend class Internal::IDebuggerEngine;
    friend class Internal::DebuggerPlugin;
    friend class Internal::CdbDebugEventCallback;
    friend class Internal::CdbDumperHelper;
164
    friend class Internal::CdbDumperInitThread;
165
166
167
168
169
    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
170

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

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

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

181
182
    QMessageBox *showMessageBox(int icon, const QString &title, const QString &text,
        int buttons = 0);
183

184
185
    bool debuggerActionsEnabled() const;

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

191
192
    const CPlusPlus::Snapshot &cppCodeModelSnapshot() const;

193
194
    static DebuggerManager *instance();

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

con's avatar
con committed
199
200
201
202
203
    void setSimpleDockWidgetArrangement();

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

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

    void interruptDebuggingRequest();

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

    void stepExec();
    void stepOutExec();
    void nextExec();
    void continueExec();
224
    void detachDebugger();
con's avatar
con committed
225
226

    void addToWatchWindow();
227
    void updateWatchData(const Debugger::Internal::WatchData &data);
228

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

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

    void executeDebuggerCommand();
con's avatar
con committed
239
240
    void executeDebuggerCommand(const QString &command);

241
    void watchPoint();
242
    void setRegisterValue(int nr, const QString &value);
243

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

247
248
    static const char *stateName(int s);

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

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

259
260
261
    void reloadSourceFiles();
    void sourceFilesDockToggled(bool on);

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

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

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

285
    Internal::DebuggerManagerActions debuggerManagerActions() const;
286

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

292
    void cleanupViews();
con's avatar
con committed
293

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

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

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

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

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

    void shutdown();

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

346
    DebuggerManagerPrivate *d;
con's avatar
con committed
347
348
349
350
351
};

} // namespace Debugger

#endif // DEBUGGER_DEBUGGERMANAGER_H