debuggermanager.h 14.1 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
8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
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
26
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
33
34
35
36
37
38
39
40
41
42
#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;
43
class QLabel;
con's avatar
con committed
44
45
46
class QMainWindow;
class QModelIndex;
class QSplitter;
47
class QTimer;
con's avatar
con committed
48
49
50
class QWidget;
QT_END_NAMESPACE

51
52
53
54
namespace Core {
    class IOptionsPage;
}

con's avatar
con committed
55
56
57
58
namespace Debugger {
namespace Internal {

class DebuggerOutputWindow;
59
class DebuggerRunControl;
con's avatar
con committed
60
61
62
63
64
65
66
67
68
69
class DebuggerPlugin;
class DebugMode;

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

// 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
83
84
85
//          |                                       | 
//     DebuggerInferiorRunning                      | 
//          |                                       |  
con's avatar
con committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//     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
};

110
111
112
113
114
enum DebuggerStartMode
{
    StartInternal,                    // Start current start project's binary
    StartExternal,                    // Start binary found in file system
    AttachExternal,                   // Attach to running process
115
    AttachCore,                       // Attach to a core file
116
    StartRemote                       // Start and attach to a remote process
117
118
};

con's avatar
con committed
119
120
121
class IDebuggerEngine;
class GdbEngine;
class ScriptEngine;
122
class CdbDebugEngine;
123
struct CdbDebugEnginePrivate;
con's avatar
con committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

// 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
144
    // debugger engines
con's avatar
con committed
145
    friend class GdbEngine;
146
147
    friend class CdbDebugEngine;
    friend class CdbDebugEventCallback;
con's avatar
con committed
148
    friend class ScriptEngine;
149
    friend struct CdbDebugEnginePrivate;
150
    friend class CdbDumperHelper;
151
    friend class CdbExceptionLoggerEventCallback;
con's avatar
con committed
152
153

    // called from the engines after successful startup
154
    virtual void notifyInferiorStopRequested() = 0;
con's avatar
con committed
155
156
157
158
159
160
161
162
163
164
165
166
167
    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;
168
    virtual SourceFilesWindow *sourceFileWindow() = 0;
con's avatar
con committed
169

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
170
    virtual void showApplicationOutput(const QString &data) = 0;
171
172
    virtual void showDebuggerOutput(const QString &prefix, const QString &msg) = 0;
    virtual void showDebuggerInput(const QString &prefix, const QString &msg) = 0;
173
    
con's avatar
con committed
174
175
    virtual void reloadDisassembler() = 0;
    virtual void reloadModules() = 0;
176
    virtual void reloadSourceFiles() = 0;
con's avatar
con committed
177
    virtual void reloadRegisters() = 0;
178
179
180
181
182

    virtual bool qtDumperLibraryEnabled() const = 0;
    virtual QString qtDumperLibraryName() const = 0;
    virtual void showQtDumperLibraryWarning(const QString &details = QString()) = 0;

con's avatar
con committed
183
184
185
186
187
188
189
190
};


//
// DebuggerManager
//

class DebuggerManager : public QObject,
hjk's avatar
hjk committed
191
    public IDebuggerManagerAccessForEngines
con's avatar
con committed
192
193
194
195
{
    Q_OBJECT

public:
196
197
198
    DebuggerManager();
    QList<Core::IOptionsPage*> initializeEngines(const QStringList &arguments);

con's avatar
con committed
199
200
201
202
    ~DebuggerManager();

    IDebuggerManagerAccessForEngines *engineInterface();
    QMainWindow *mainWindow() const { return m_mainWindow; }
203
    QLabel *statusLabel() const { return m_statusLabel; }
con's avatar
con committed
204

hjk's avatar
hjk committed
205
    enum DebuggerType { NoDebugger, GdbDebugger, ScriptDebugger, WinDebugger };
con's avatar
con committed
206
207

public slots:
208
    void startNewDebugger(DebuggerRunControl *runControl);
con's avatar
con committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
    void exitDebugger(); 

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

    void setBusyCursor(bool on);
    void queryCurrentTextEditor(QString *fileName, int *lineNumber, QObject **ed);
    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);
223
    void fileOpen(const QString &file);
con's avatar
con committed
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
    void resetLocation();

    void interruptDebuggingRequest();

    void jumpToLineExec();
    void runToLineExec();
    void runToFunctionExec();
    void toggleBreakpoint();
    void breakByFunction();
    void breakByFunction(const QString &functionName);
    void setBreakpoint(const QString &fileName, int lineNumber);
    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 sessionLoaded();
250
    void sessionUnloaded();
con's avatar
con committed
251
252
    void aboutToSaveSession();

253
    void assignValueInDebugger();
con's avatar
con committed
254
    void assignValueInDebugger(const QString &expr, const QString &value);
255
256

    void executeDebuggerCommand();
con's avatar
con committed
257
258
    void executeDebuggerCommand(const QString &command);

259
    void showStatusMessage(const QString &msg, int timeout = -1); // -1 forever
con's avatar
con committed
260
261
262
263

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
264
    void showApplicationOutput(const QString &data);
con's avatar
con committed
265
266
267
268

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

269
270
271
    void reloadSourceFiles();
    void sourceFilesDockToggled(bool on);

con's avatar
con committed
272
273
274
275
276
277
278
279
    void reloadModules();
    void modulesDockToggled(bool on);
    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();

    void reloadRegisters();
    void registerDockToggled(bool on);
    void setStatus(int status);
280
    void clearStatusMessage();
281
    void attemptBreakpointSynchronization();
282
    void reloadFullStack();
con's avatar
con committed
283
284
285
286
287
288
289
290
291
292
293
294

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; }
295
    SourceFilesWindow *sourceFileWindow() { return m_sourceFilesWindow; }
296

con's avatar
con committed
297
298
    void notifyInferiorStopped();
    void notifyInferiorRunningRequested();
299
    void notifyInferiorStopRequested();
con's avatar
con committed
300
301
302
303
304
305
306
307
308
    void notifyInferiorRunning();
    void notifyInferiorExited();
    void notifyInferiorPidChanged(int);

    void cleanupViews(); 

    //
    // Implementation of IDebuggerManagerAccessForDebugMode
    //
309
    QWidget *threadsWindow() const { return m_threadsWindow; }
con's avatar
con committed
310
311
312
    QList<QDockWidget*> dockWidgets() const { return m_dockWidgets; }
    void createDockWidgets();

313
314
315
316
    virtual bool qtDumperLibraryEnabled() const;
    virtual QString qtDumperLibraryName() const;
    virtual void showQtDumperLibraryWarning(const QString &details = QString());

con's avatar
con committed
317
318
319
320
321
322
323
324
325
326
327
328
    //    
    // 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; }
329
330
    DebuggerStartMode startMode() const;
    DebuggerRunControl *runControl() const { return m_runControl; }
con's avatar
con committed
331

332
333
    QList<Symbol> moduleSymbols(const QString &moduleName);

con's avatar
con committed
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
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
349
    void applicationOutputAvailable(const QString &output);
con's avatar
con committed
350
351
352
353

public:
    // FIXME: make private
    QString m_executable;
354
    QString m_coreFile;
con's avatar
con committed
355
356
357
358
    QStringList m_environment;
    QString m_workingDir;
    QString m_buildDir;
    QStringList m_processArgs;
hjk's avatar
hjk committed
359
    QString m_dumperLib;
con's avatar
con committed
360
    int m_attachedPID;
361
    bool m_useTerminal;
362
    // for remote debugging
363
364
    QString m_remoteChannel;
    QString m_remoteArchitecture;
365
    QString m_serverStartScript;
con's avatar
con committed
366
367

private:
368
    void init();
con's avatar
con committed
369
    void setDebuggerType(DebuggerType type);
hjk's avatar
hjk committed
370
    void runTest(const QString &fileName);
con's avatar
con committed
371
    QDockWidget *createDockForWidget(QWidget *widget);
hjk's avatar
hjk committed
372
    Q_SLOT void createNewDock(QWidget *widget);
con's avatar
con committed
373
374
375
376

    void shutdown();

    void toggleBreakpoint(const QString &fileName, int lineNumber);
377
378
    void toggleBreakpointEnabled(const QString &fileName, int lineNumber);
    BreakpointData *findBreakpoint(const QString &fileName, int lineNumber);
con's avatar
con committed
379
380
    void setToolTipExpression(const QPoint &pos, const QString &exp0);

381
    DebuggerRunControl *m_runControl;
con's avatar
con committed
382
383
384
385
    DebuggerType m_debuggerType;

    /// Views
    QMainWindow *m_mainWindow;
386
    QLabel *m_statusLabel;
con's avatar
con committed
387
388
389
390
391
392
    QDockWidget *m_breakDock;
    QDockWidget *m_disassemblerDock;
    QDockWidget *m_modulesDock;
    QDockWidget *m_outputDock;
    QDockWidget *m_registerDock;
    QDockWidget *m_stackDock;
393
    QDockWidget *m_sourceFilesDock;
con's avatar
con committed
394
395
396
397
398
399
400
401
402
403
404
    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;
405
    SourceFilesWindow *m_sourceFilesWindow;
con's avatar
con committed
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438

    /// Actions
    friend class DebuggerPlugin;
    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;
439
440
    QTimer *m_statusTimer;
    QString m_lastPermanentStatusMessage;
con's avatar
con committed
441
442
443
444
445
446
447
448
449

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

} // namespace Internal
} // namespace Debugger

#endif // DEBUGGER_DEBUGGERMANAGER_H