debuggermanager.h 11 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

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

35
36
#include <utils/fancymainwindow.h>

con's avatar
con committed
37
38
39
40
#include <QtCore/QByteArray>
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
41
#include <QtCore/QSharedPointer>
con's avatar
con committed
42
43
44
45
46

QT_BEGIN_NAMESPACE
class QAction;
class QAbstractItemModel;
class QDockWidget;
47
class QLabel;
48
class QMessageBox;
49
class QModelIndex;
50
class QPoint;
51
class QTimer;
con's avatar
con committed
52
class QWidget;
53
class QDebug;
con's avatar
con committed
54
55
QT_END_NAMESPACE

56
namespace Core {
57
58
class IOptionsPage;
} // namespace Core
59

60
namespace TextEditor {
61
class ITextEditor;
62
63
}

con's avatar
con committed
64
65
66
namespace Debugger {
namespace Internal {

67
68
69
70
71
typedef QLatin1Char _c;
typedef QLatin1String __;
inline QString _(const char *s) { return QString::fromLatin1(s); }
inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }

con's avatar
con committed
72
class DebuggerOutputWindow;
73
class DebuggerRunControl;
con's avatar
con committed
74
75
76
77
class DebuggerPlugin;
class DebugMode;

class BreakHandler;
78
class BreakpointData;
con's avatar
con committed
79
80
class ModulesHandler;
class RegisterHandler;
81
class SourceFilesWindow;
82
struct StackFrame;
con's avatar
con committed
83
class StackHandler;
84
class Symbol;
con's avatar
con committed
85
86
class ThreadsHandler;
class WatchData;
87
class WatchHandler;
con's avatar
con committed
88

89
class DebuggerStartParameters
90
{
91
public:
92
93
94
95
96
97
98
99
100
101
102
    DebuggerStartParameters();
    void clear();

    QString executable;
    QString coreFile;
    QStringList processArgs;
    QStringList environment;
    QString workingDir;
    QString buildDir;
    qint64 attachPID;
    bool useTerminal;
103
    QString crashParameter; // for AttachCrashedExternal
104
105
106
107
    // for remote debugging
    QString remoteChannel;
    QString remoteArchitecture;
    QString serverStartScript;
108
    int toolChainType;
hjk's avatar
hjk committed
109
110
111

    QString dumperLibrary;
    QStringList dumperLibraryLocations;
hjk's avatar
hjk committed
112
    DebuggerStartMode startMode;
113
114
};

hjk's avatar
hjk committed
115
typedef QSharedPointer<DebuggerStartParameters> DebuggerStartParametersPtr;
116
117
QDebug operator<<(QDebug str, const DebuggerStartParameters &);

con's avatar
con committed
118
119
120
class IDebuggerEngine;
class GdbEngine;
class ScriptEngine;
121
class CdbDebugEngine;
122
struct CdbDebugEnginePrivate;
con's avatar
con committed
123

124
// Flags for initialization
hjk's avatar
hjk committed
125
126
127
128
129
130
131
132
133
134
enum DebuggerEngineTypeFlags
{
    GdbEngineType     = 0x01,
    ScriptEngineType  = 0x02,
    CdbEngineType     = 0x04,
    TcfEngineType     = 0x08,
    AllEngineTypes = GdbEngineType
        | ScriptEngineType 
        | CdbEngineType 
        | TcfEngineType
135
136
};

hjk's avatar
hjk committed
137
QDebug operator<<(QDebug d, DebuggerState state);
con's avatar
con committed
138
139

//
hjk's avatar
hjk committed
140
// DebuggerManager
con's avatar
con committed
141
142
//

hjk's avatar
hjk committed
143
class DebuggerManager : public QObject
con's avatar
con committed
144
{
hjk's avatar
hjk committed
145
    Q_OBJECT
con's avatar
con committed
146

hjk's avatar
hjk committed
147
148
149
public:
    DebuggerManager();
    ~DebuggerManager();
150

151
152
    friend class CdbDebugEngine;
    friend class CdbDebugEventCallback;
153
    friend class CdbDumperHelper;
154
    friend class CdbExceptionLoggerEventCallback;
155
156
157
158
    friend class GdbEngine;
    friend class ScriptEngine;
    friend class TcfEngine;
    friend struct CdbDebugEnginePrivate;
con's avatar
con committed
159

160
    QList<Core::IOptionsPage*> initializeEngines(unsigned enabledTypeFlags);
161

162
    Core::Utils::FancyMainWindow *mainWindow() const { return m_mainWindow; }
163
    QLabel *statusLabel() const { return m_statusLabel; }
164
    IDebuggerEngine *currentEngine() const { return m_engine; }
con's avatar
con committed
165

hjk's avatar
hjk committed
166
    virtual DebuggerStartParametersPtr startParameters() const;
hjk's avatar
hjk committed
167
168
    virtual qint64 inferiorPid() const;

169
170
    void showMessageBox(int icon, const QString &title, const QString &text);

con's avatar
con committed
171
public slots:
hjk's avatar
hjk committed
172
    void startNewDebugger(const DebuggerStartParametersPtr &sp);
173
174
    void exitDebugger();

con's avatar
con committed
175
176
177
178
179
    void setSimpleDockWidgetArrangement();

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

180
    void gotoLocation(const StackFrame &frame, bool setLocationMarker);
181
    void fileOpen(const QString &file);
con's avatar
con committed
182
183
184
185
186
187
188
189
190
    void resetLocation();

    void interruptDebuggingRequest();

    void jumpToLineExec();
    void runToLineExec();
    void runToFunctionExec();
    void toggleBreakpoint();
    void breakByFunction(const QString &functionName);
191
    void breakByFunctionMain();
con's avatar
con committed
192
193
194
195
196
197
198
199
    void setBreakpoint(const QString &fileName, int lineNumber);
    void activateFrame(int index);
    void selectThread(int index);

    void stepExec();
    void stepOutExec();
    void nextExec();
    void continueExec();
200
    void detachDebugger();
con's avatar
con committed
201
202

    void addToWatchWindow();
203
    void updateWatchData(const WatchData &data);
204

con's avatar
con committed
205
    void sessionLoaded();
206
    void aboutToUnloadSession();
con's avatar
con committed
207
    void aboutToSaveSession();
208
209
    QVariant sessionValue(const QString &name);
    void setSessionValue(const QString &name, const QVariant &value);
con's avatar
con committed
210

211
    void assignValueInDebugger();
con's avatar
con committed
212
    void assignValueInDebugger(const QString &expr, const QString &value);
213
214

    void executeDebuggerCommand();
con's avatar
con committed
215
216
    void executeDebuggerCommand(const QString &command);

217
    void watchPoint();
218
    void setRegisterValue(int nr, const QString &value);
219

220
    void showStatusMessage(const QString &msg, int timeout = -1); // -1 forever
con's avatar
con committed
221
222

private slots:
hjk's avatar
hjk committed
223
224
    void showDebuggerOutput(const QString &msg)
        { showDebuggerOutput(LogDebug, msg); }
225
226
    void showDebuggerOutput(int channel, const QString &msg);
    void showDebuggerInput(int channel, const QString &msg);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
227
    void showApplicationOutput(const QString &data);
con's avatar
con committed
228

229
230
231
    void reloadSourceFiles();
    void sourceFilesDockToggled(bool on);

con's avatar
con committed
232
233
234
235
236
237
238
    void reloadModules();
    void modulesDockToggled(bool on);
    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();

    void reloadRegisters();
    void registerDockToggled(bool on);
239
    void clearStatusMessage();
240
    void attemptBreakpointSynchronization();
241
    void reloadFullStack();
242
    void stepByInstructionTriggered();
hjk's avatar
hjk committed
243
    void startFailed();
con's avatar
con committed
244
245
246
247
248
249
250
251

private:
    ModulesHandler *modulesHandler() { return m_modulesHandler; }
    BreakHandler *breakHandler() { return m_breakHandler; }
    RegisterHandler *registerHandler() { return m_registerHandler; }
    StackHandler *stackHandler() { return m_stackHandler; }
    ThreadsHandler *threadsHandler() { return m_threadsHandler; }
    WatchHandler *watchHandler() { return m_watchHandler; }
252
    SourceFilesWindow *sourceFileWindow() { return m_sourceFilesWindow; }
253
    QWidget *threadsWindow() const { return m_threadsWindow; }
254

con's avatar
con committed
255
256
257
    void notifyInferiorStopped();
    void notifyInferiorRunning();
    void notifyInferiorExited();
258
    void notifyInferiorPidChanged(qint64);
con's avatar
con committed
259

260
    void cleanupViews();
con's avatar
con committed
261

hjk's avatar
hjk committed
262
263
264
265
    DebuggerState state() const;
    void setState(DebuggerState state);
    DebuggerState m_state;

266
    //
con's avatar
con committed
267
    // internal implementation
268
    //
269
270
271
272
273
274
275
    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
276
277
278
279
280
    Q_SLOT void loadSessionData();
    Q_SLOT void saveSessionData();
    Q_SLOT void dumpLog();

public:
281
    // stuff in this block should be made private by moving it to
con's avatar
con committed
282
283
    // one of the interfaces
    int status() const { return m_status; }
284
285
    QList<Symbol> moduleSymbols(const QString &moduleName);

con's avatar
con committed
286
287
288
signals:
    void debuggingFinished();
    void inferiorPidChanged(qint64 pid);
hjk's avatar
hjk committed
289
    void stateChanged(int newstatus);
con's avatar
con committed
290
291
292
    void debugModeRequested();
    void previousModeRequested();
    void statusMessageRequested(const QString &msg, int timeout); // -1 for 'forever'
293
    void gotoLocationRequested(const StackFrame &frame, bool setLocationMarker);
con's avatar
con committed
294
295
296
297
298
299
    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
300
    void applicationOutputAvailable(const QString &output);
con's avatar
con committed
301
302

private:
303
    void init();
hjk's avatar
hjk committed
304
    void runTest(const QString &fileName);
hjk's avatar
hjk committed
305
    Q_SLOT void createNewDock(QWidget *widget);
con's avatar
con committed
306
307
308
309

    void shutdown();

    void toggleBreakpoint(const QString &fileName, int lineNumber);
310
311
    void toggleBreakpointEnabled(const QString &fileName, int lineNumber);
    BreakpointData *findBreakpoint(const QString &fileName, int lineNumber);
hjk's avatar
hjk committed
312
313
    void setToolTipExpression(const QPoint &mousePos,
        TextEditor::ITextEditor *editor, int cursorPos);
con's avatar
con committed
314

hjk's avatar
hjk committed
315
    // FIXME: Remove engine-specific state
hjk's avatar
hjk committed
316
    DebuggerStartParametersPtr m_startParameters;
317
318
    qint64 m_inferiorPid;

con's avatar
con committed
319
320

    /// Views
321
    Core::Utils::FancyMainWindow *m_mainWindow;
322
    QLabel *m_statusLabel;
con's avatar
con committed
323
324
325
326
327
    QDockWidget *m_breakDock;
    QDockWidget *m_modulesDock;
    QDockWidget *m_outputDock;
    QDockWidget *m_registerDock;
    QDockWidget *m_stackDock;
328
    QDockWidget *m_sourceFilesDock;
con's avatar
con committed
329
330
331
332
333
334
335
336
337
    QDockWidget *m_threadsDock;
    QDockWidget *m_watchDock;

    BreakHandler *m_breakHandler;
    ModulesHandler *m_modulesHandler;
    RegisterHandler *m_registerHandler;
    StackHandler *m_stackHandler;
    ThreadsHandler *m_threadsHandler;
    WatchHandler *m_watchHandler;
338
    SourceFilesWindow *m_sourceFilesWindow;
con's avatar
con committed
339
340
341

    /// Actions
    friend class DebuggerPlugin;
hjk's avatar
hjk committed
342
    friend class IDebuggerEngine;
con's avatar
con committed
343
344
345
346
347
348
349
350
351
352
353
354
    QAction *m_continueAction;
    QAction *m_stopAction;
    QAction *m_resetAction; // FIXME: Should not be needed in a stable release
    QAction *m_stepAction;
    QAction *m_stepOutAction;
    QAction *m_runToLineAction;
    QAction *m_runToFunctionAction;
    QAction *m_jumpToLineAction;
    QAction *m_nextAction;
    QAction *m_watchAction;
    QAction *m_breakAction;
    QAction *m_sepAction;
355
    QAction *m_reverseDirectionAction;
con's avatar
con committed
356
357

    QWidget *m_breakWindow;
358
    QWidget *m_localsWindow;
con's avatar
con committed
359
360
361
362
    QWidget *m_registerWindow;
    QWidget *m_modulesWindow;
    QWidget *m_stackWindow;
    QWidget *m_threadsWindow;
363
    QWidget *m_watchersWindow;
con's avatar
con committed
364
365
366
367
    DebuggerOutputWindow *m_outputWindow;

    int m_status;
    bool m_busy;
368
369
    QTimer *m_statusTimer;
    QString m_lastPermanentStatusMessage;
con's avatar
con committed
370
371
372
373
374
375
376
377
378

    IDebuggerEngine *engine();
    IDebuggerEngine *m_engine;
};

} // namespace Internal
} // namespace Debugger

#endif // DEBUGGER_DEBUGGERMANAGER_H