debuggermanager.h 14.4 KB
Newer Older
con's avatar
con committed
1
2
3
4
/***************************************************************************
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
7
8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
9
10
11
**
** Non-Open Source Usage
**
con's avatar
con committed
12
13
14
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
15
16
17
18
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
con's avatar
con committed
19
20
21
22
23
24
25
26
27
28
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file.  Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
29
** rights. These rights are described in the Nokia Qt GPL Exception
30
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
31
32
**
***************************************************************************/
hjk's avatar
hjk committed
33

con's avatar
con committed
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef DEBUGGER_DEBUGGERMANAGER_H
#define DEBUGGER_DEBUGGERMANAGER_H

#include <QtCore/QByteArray>
#include <QtCore/QObject>
#include <QtCore/QPoint>
#include <QtCore/QStringList>
#include <QtCore/QVariant>

QT_BEGIN_NAMESPACE
class QAction;
class QAbstractItemModel;
class QDockWidget;
47
class QLabel;
con's avatar
con committed
48
49
50
class QMainWindow;
class QModelIndex;
class QSplitter;
51
class QTimer;
con's avatar
con committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class QWidget;
QT_END_NAMESPACE

namespace Debugger {
namespace Internal {

class DebuggerOutputWindow;
class DebuggerPlugin;
class DebugMode;

class BreakHandler;
class DisassemblerHandler;
class ModulesHandler;
class RegisterHandler;
class StackHandler;
class ThreadsHandler;
class WatchHandler;
69
class SourceFilesWindow;
con's avatar
con committed
70
71
72
73
74
75
76
77
78
79
80
81
class WatchData;
class BreakpointData;


// Note: the Debugger process itself is referred to as 'Debugger',
// whereas the debugged process is referred to as 'Inferior' or 'Debuggee'.

//     DebuggerProcessNotReady
//          |
//     DebuggerProcessStartingUp
//          | <-------------------------------------.
//     DebuggerInferiorRunningRequested             |
hjk's avatar
hjk committed
82
83
84
//          |                                       | 
//     DebuggerInferiorRunning                      | 
//          |                                       |  
con's avatar
con committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//     DebuggerInferiorStopRequested                |
//          |                                       |
//     DebuggerInferiorStopped                      |
//          |                                       |
//          `---------------------------------------'
//
// Allowed actions:
//    [R] :  Run
//    [C] :  Continue
//    [N] :  Step, Next



enum DebuggerStatus
{
    DebuggerProcessNotReady,          // Debugger not started
    DebuggerProcessStartingUp,        // Debugger starting up

    DebuggerInferiorRunningRequested, // Debuggee requested to run
    DebuggerInferiorRunning,          // Debuggee running
    DebuggerInferiorStopRequested,    // Debuggee running, stop requested
    DebuggerInferiorStopped,          // Debuggee stopped
};

class IDebuggerEngine;
class GdbEngine;
class ScriptEngine;
112
class CdbDebugEngine;
113
struct CdbDebugEnginePrivate;
con's avatar
con committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

// The construct below is not nice but enforces a bit of order. The
// DebuggerManager interfaces a lots of thing: The DebuggerPlugin,
// the DebuggerEngines, the RunMode, the handlers and views.
// Instead of making the whole interface public, we split in into
// smaller parts and grant friend access only to the classes that
// need it.


//
// IDebuggerManagerAccessForEngines
//

class IDebuggerManagerAccessForEngines
{
public:
    virtual ~IDebuggerManagerAccessForEngines() {}

private:
    // This is the part of the interface that's exclusively seen by the
134
    // debugger engines
con's avatar
con committed
135
    friend class GdbEngine;
136
137
    friend class CdbDebugEngine;
    friend class CdbDebugEventCallback;
con's avatar
con committed
138
    friend class ScriptEngine;
139
    friend struct CdbDebugEnginePrivate;
con's avatar
con committed
140
141

    // called from the engines after successful startup
142
    virtual void notifyInferiorStopRequested() = 0;
con's avatar
con committed
143
144
145
146
147
148
149
150
151
152
153
154
155
    virtual void notifyInferiorStopped() = 0; 
    virtual void notifyInferiorRunningRequested() = 0;
    virtual void notifyInferiorRunning() = 0;
    virtual void notifyInferiorExited() = 0;
    virtual void notifyInferiorPidChanged(int) = 0;

    virtual DisassemblerHandler *disassemblerHandler() = 0;
    virtual ModulesHandler *modulesHandler() = 0;
    virtual BreakHandler *breakHandler() = 0;
    virtual RegisterHandler *registerHandler() = 0;
    virtual StackHandler *stackHandler() = 0;
    virtual ThreadsHandler *threadsHandler() = 0;
    virtual WatchHandler *watchHandler() = 0;
156
    virtual SourceFilesWindow *sourceFileWindow() = 0;
con's avatar
con committed
157

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
158
    virtual void showApplicationOutput(const QString &data) = 0;
con's avatar
con committed
159
160
161
    virtual bool skipKnownFrames() const = 0;
    virtual bool debugDumpers() const = 0;
    virtual bool useCustomDumpers() const = 0;
162
163
164
165
166
    
    virtual bool wantsAllPluginBreakpoints() const = 0;
    virtual bool wantsSelectedPluginBreakpoints() const = 0;
    virtual bool wantsNoPluginBreakpoints() const = 0;
    virtual QString selectedPluginBreakpointsPattern() const = 0;
con's avatar
con committed
167
168
169

    virtual void reloadDisassembler() = 0;
    virtual void reloadModules() = 0;
170
    virtual void reloadSourceFiles() = 0;
con's avatar
con committed
171
172
173
174
    virtual void reloadRegisters() = 0;
};


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// DebuggerSettings
//

class DebuggerSettings
{
public:
    DebuggerSettings();

public:
    QString m_gdbCmd;
    QString m_gdbEnv;
    bool m_autoRun;
    bool m_autoQuit;

    bool m_useCustomDumpers;
    bool m_skipKnownFrames;
    bool m_debugDumpers;
    bool m_useFastStart;
    bool m_useToolTips;

    QString m_scriptFile;
197
198
199
200
201

    bool m_pluginAllBreakpoints;
    bool m_pluginSelectedBreakpoints;
    bool m_pluginNoBreakpoints;
    QString m_pluginSelectedBreakpointsPattern;
202
203
};

con's avatar
con committed
204
205
206
207
208
//
// DebuggerManager
//

class DebuggerManager : public QObject,
hjk's avatar
hjk committed
209
    public IDebuggerManagerAccessForEngines
con's avatar
con committed
210
211
212
213
214
215
216
217
218
{
    Q_OBJECT

public:
    DebuggerManager();
    ~DebuggerManager();

    IDebuggerManagerAccessForEngines *engineInterface();
    QMainWindow *mainWindow() const { return m_mainWindow; }
219
    QLabel *statusLabel() const { return m_statusLabel; }
220
    DebuggerSettings *settings() { return &m_settings; }
con's avatar
con committed
221

222
    enum StartMode { StartInternal, StartExternal, AttachExternal };
con's avatar
con committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    enum DebuggerType { GdbDebugger, ScriptDebugger, WinDebugger };

public slots:
    bool startNewDebugger(StartMode mode);
    void exitDebugger(); 

    void setSimpleDockWidgetArrangement();
    void setLocked(bool locked);
    void dockToggled(bool on);

    void setBusyCursor(bool on);
    void queryCurrentTextEditor(QString *fileName, int *lineNumber, QObject **ed);
    void querySessionValue(const QString &name, QVariant *value);
    void setSessionValue(const QString &name, const QVariant &value);
    QVariant configValue(const QString &name);
    void queryConfigValue(const QString &name, QVariant *value);
    void setConfigValue(const QString &name, const QVariant &value);
    QVariant sessionValue(const QString &name);

    void gotoLocation(const QString &file, int line, bool setLocationMarker);
    void resetLocation();

    void interruptDebuggingRequest();
    void startExternalApplication();
    void attachExternalApplication();

    void jumpToLineExec();
    void runToLineExec();
    void runToFunctionExec();
    void toggleBreakpoint();
    void breakByFunction();
    void breakByFunction(const QString &functionName);
    void setBreakpoint(const QString &fileName, int lineNumber);
    void watchExpression(const QString &expression);
    void breakAtMain();
    void activateFrame(int index);
    void selectThread(int index);

    void stepExec();
    void stepOutExec();
    void nextExec();
    void stepIExec();
    void nextIExec();
    void continueExec();

    void addToWatchWindow();
    void updateWatchModel();
    void removeWatchExpression(const QString &iname);
    void expandChildren(const QModelIndex &idx);
    void collapseChildren(const QModelIndex &idx);
    
    void sessionLoaded();
    void aboutToSaveSession();

    void assignValueInDebugger(const QString &expr, const QString &value);
    void executeDebuggerCommand(const QString &command);

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

282
283
284
285
    void setUseCustomDumpers(bool on);
    void setDebugDumpers(bool on);
    void setSkipKnownFrames(bool on);

con's avatar
con committed
286
287
288
private slots:
    void showDebuggerOutput(const QString &prefix, const QString &msg);
    void showDebuggerInput(const QString &prefix, const QString &msg);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
289
    void showApplicationOutput(const QString &data);
con's avatar
con committed
290
291
292
293

    void reloadDisassembler();
    void disassemblerDockToggled(bool on);

294
295
296
    void reloadSourceFiles();
    void sourceFilesDockToggled(bool on);

con's avatar
con committed
297
298
299
300
301
302
303
304
    void reloadModules();
    void modulesDockToggled(bool on);
    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();

    void reloadRegisters();
    void registerDockToggled(bool on);
    void setStatus(int status);
305
    void clearStatusMessage();
con's avatar
con committed
306
307
308
309
310
311
312
313
314
315
316
317

private:
    //
    // Implementation of IDebuggerManagerAccessForEngines
    // 
    DisassemblerHandler *disassemblerHandler() { return m_disassemblerHandler; }
    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; }
318
    SourceFilesWindow *sourceFileWindow() { return m_sourceFilesWindow; }
319

con's avatar
con committed
320
321
322
    bool skipKnownFrames() const;
    bool debugDumpers() const;
    bool useCustomDumpers() const;
323
324
325
326
327
328
329
330
    bool wantsAllPluginBreakpoints() const
        { return m_settings.m_pluginAllBreakpoints; }
    bool wantsSelectedPluginBreakpoints() const
        { return m_settings.m_pluginSelectedBreakpoints; }
    bool wantsNoPluginBreakpoints() const
        { return m_settings.m_pluginNoBreakpoints; }
    QString selectedPluginBreakpointsPattern() const
        { return m_settings.m_pluginSelectedBreakpointsPattern; }
con's avatar
con committed
331
332
333

    void notifyInferiorStopped();
    void notifyInferiorRunningRequested();
334
    void notifyInferiorStopRequested();
con's avatar
con committed
335
336
337
338
339
340
341
342
343
    void notifyInferiorRunning();
    void notifyInferiorExited();
    void notifyInferiorPidChanged(int);

    void cleanupViews(); 

    //
    // Implementation of IDebuggerManagerAccessForDebugMode
    //
344
    QWidget *threadsWindow() const { return m_threadsWindow; }
con's avatar
con committed
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
    QList<QDockWidget*> dockWidgets() const { return m_dockWidgets; }
    void createDockWidgets();

    //    
    // internal implementation
    //  
    Q_SLOT void loadSessionData();
    Q_SLOT void saveSessionData();
    Q_SLOT void dumpLog();

public:
    // stuff in this block should be made private by moving it to 
    // one of the interfaces
    QAbstractItemModel *threadsModel();
    int status() const { return m_status; }
    StartMode startMode() const { return m_startMode; }

signals:
    void debuggingFinished();
    void inferiorPidChanged(qint64 pid);
    void statusChanged(int newstatus);
    void debugModeRequested();
    void previousModeRequested();
    void statusMessageRequested(const QString &msg, int timeout); // -1 for 'forever'
    void gotoLocationRequested(const QString &file, int line, bool setLocationMarker);
    void resetLocationRequested();
    void currentTextEditorRequested(QString *fileName, int *lineNumber, QObject **ob);
    void currentMainWindowRequested(QWidget **);
    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
377
    void applicationOutputAvailable(const QString &output);
con's avatar
con committed
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

public:
    // FIXME: make private
    QString m_executable;
    QStringList m_environment;
    QString m_workingDir;
    QString m_buildDir;
    QStringList m_processArgs;
    int m_attachedPID;

private:
    void init();
    void setDebuggerType(DebuggerType type);
    QDockWidget *createDockForWidget(QWidget *widget);

    void shutdown();

    void toggleBreakpoint(const QString &fileName, int lineNumber);
    void setToolTipExpression(const QPoint &pos, const QString &exp0);

    StartMode m_startMode;
    DebuggerType m_debuggerType;

    /// Views
    QMainWindow *m_mainWindow;
403
    QLabel *m_statusLabel;
con's avatar
con committed
404
405
406
407
408
409
    QDockWidget *m_breakDock;
    QDockWidget *m_disassemblerDock;
    QDockWidget *m_modulesDock;
    QDockWidget *m_outputDock;
    QDockWidget *m_registerDock;
    QDockWidget *m_stackDock;
410
    QDockWidget *m_sourceFilesDock;
con's avatar
con committed
411
412
413
414
415
416
417
418
419
420
421
    QDockWidget *m_threadsDock;
    QDockWidget *m_watchDock;
    QList<QDockWidget*> m_dockWidgets;

    BreakHandler *m_breakHandler;
    DisassemblerHandler *m_disassemblerHandler;
    ModulesHandler *m_modulesHandler;
    RegisterHandler *m_registerHandler;
    StackHandler *m_stackHandler;
    ThreadsHandler *m_threadsHandler;
    WatchHandler *m_watchHandler;
422
    SourceFilesWindow *m_sourceFilesWindow;
con's avatar
con committed
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457

    /// Actions
    friend class DebuggerPlugin;
    QAction *m_startExternalAction;
    QAction *m_attachExternalAction;
    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_breakByFunctionAction;
    QAction *m_breakAtMainAction;
    QAction *m_sepAction;
    QAction *m_stepIAction;
    QAction *m_nextIAction;

    QWidget *m_breakWindow;
    QWidget *m_disassemblerWindow;
    QWidget *m_localsWindow;
    QWidget *m_registerWindow;
    QWidget *m_modulesWindow;
    QWidget *m_tooltipWindow;
    QWidget *m_stackWindow;
    QWidget *m_threadsWindow;
    QWidget *m_watchersWindow;
    DebuggerOutputWindow *m_outputWindow;

    int m_status;
    bool m_busy;
458
459
    QTimer *m_statusTimer;
    QString m_lastPermanentStatusMessage;
con's avatar
con committed
460
461
462

    IDebuggerEngine *engine();
    IDebuggerEngine *m_engine;
463
    DebuggerSettings m_settings;
con's avatar
con committed
464
465
466
467
468
469
};

} // namespace Internal
} // namespace Debugger

#endif // DEBUGGER_DEBUGGERMANAGER_H