debuggermanager.h 15.3 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
34
#include <utils/fancymainwindow.h>

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

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

54
namespace Core {
55
56
class IOptionsPage;
} // namespace Core
57

58
namespace TextEditor {
59
class ITextEditor;
60
61
}

con's avatar
con committed
62
63
64
namespace Debugger {
namespace Internal {

65
66
67
68
69
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
70
class DebuggerOutputWindow;
71
class DebuggerRunControl;
con's avatar
con committed
72
73
74
75
class DebuggerPlugin;
class DebugMode;

class BreakHandler;
76
class BreakpointData;
con's avatar
con committed
77
78
class ModulesHandler;
class RegisterHandler;
79
class SourceFilesWindow;
80
struct StackFrame;
con's avatar
con committed
81
class StackHandler;
82
class Symbol;
con's avatar
con committed
83
84
class ThreadsHandler;
class WatchData;
85
class WatchHandler;
con's avatar
con committed
86
87
88
89
90
91
92
93
94

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

//     DebuggerProcessNotReady
//          |
//     DebuggerProcessStartingUp
//          | <-------------------------------------.
//     DebuggerInferiorRunningRequested             |
95
96
97
//          |                                       |
//     DebuggerInferiorRunning                      |
//          |                                       |
con's avatar
con committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//     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
};

121
122
enum DebuggerStartMode
{
123
    NoStartMode,
124
125
126
127
128
129
130
    StartInternal,         // Start current start project's binary
    StartExternal,         // Start binary found in file system
    AttachExternal,        // Attach to running process by process id
    AttachCrashedExternal, // Attach to crashed process by process id
    AttachTcf,             // Attach to a running Target Communication Framework agent
    AttachCore,            // Attach to a core file
    StartRemote            // Start and attach to a remote process
131
132
};

133
134
135
136
enum LogChannel
{
    LogInput,   // Used for user input
    LogOutput,
137
    LogWarning,
138
139
    LogError,
    LogStatus,  // Used for status changed messages
140
    LogTime,  // Used for time stamp messages
141
142
143
144
    LogDebug,
    LogMisc    
};

145
class DebuggerStartParameters
146
{
147
public:
148
149
150
151
152
153
154
155
156
157
158
    DebuggerStartParameters();
    void clear();

    QString executable;
    QString coreFile;
    QStringList processArgs;
    QStringList environment;
    QString workingDir;
    QString buildDir;
    qint64 attachPID;
    bool useTerminal;
159
    QString crashParameter; // for AttachCrashedExternal
160
161
162
163
    // for remote debugging
    QString remoteChannel;
    QString remoteArchitecture;
    QString serverStartScript;
164
    int toolChainType;
hjk's avatar
hjk committed
165
166
167

    QString dumperLibrary;
    QStringList dumperLibraryLocations;
hjk's avatar
hjk committed
168
    DebuggerStartMode startMode;
169
170
};

hjk's avatar
hjk committed
171
typedef QSharedPointer<DebuggerStartParameters> DebuggerStartParametersPtr;
172
173
QDebug operator<<(QDebug str, const DebuggerStartParameters &);

con's avatar
con committed
174
175
176
class IDebuggerEngine;
class GdbEngine;
class ScriptEngine;
177
class CdbDebugEngine;
178
struct CdbDebugEnginePrivate;
con's avatar
con committed
179

180
// Flags for initialization
hjk's avatar
hjk committed
181
182
183
184
185
186
187
188
189
190
enum DebuggerEngineTypeFlags
{
    GdbEngineType     = 0x01,
    ScriptEngineType  = 0x02,
    CdbEngineType     = 0x04,
    TcfEngineType     = 0x08,
    AllEngineTypes = GdbEngineType
        | ScriptEngineType 
        | CdbEngineType 
        | TcfEngineType
191
192
};

con's avatar
con committed
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// 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
212
    // debugger engines
213

214
215
    friend class CdbDebugEngine;
    friend class CdbDebugEventCallback;
216
    friend class CdbDumperHelper;
217
    friend class CdbExceptionLoggerEventCallback;
218
219
220
221
    friend class GdbEngine;
    friend class ScriptEngine;
    friend class TcfEngine;
    friend struct CdbDebugEnginePrivate;
con's avatar
con committed
222
223

    // called from the engines after successful startup
224
    virtual void notifyInferiorStopRequested() = 0;
225
    virtual void notifyInferiorStopped() = 0;
con's avatar
con committed
226
227
228
    virtual void notifyInferiorRunningRequested() = 0;
    virtual void notifyInferiorRunning() = 0;
    virtual void notifyInferiorExited() = 0;
229
    virtual void notifyInferiorPidChanged(qint64) = 0;
con's avatar
con committed
230
231
232
233
234
235
236

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

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
239
    virtual void showApplicationOutput(const QString &data) = 0;
240
241
    virtual void showDebuggerOutput(int channel, const QString &msg) = 0;
    virtual void showDebuggerInput(int channel, const QString &msg) = 0;
242

con's avatar
con committed
243
    virtual void reloadModules() = 0;
244
    virtual void reloadSourceFiles() = 0;
con's avatar
con committed
245
    virtual void reloadRegisters() = 0;
246
247
248

    virtual bool qtDumperLibraryEnabled() const = 0;
    virtual QString qtDumperLibraryName() const = 0;
249
    virtual QStringList qtDumperLibraryLocations() const = 0;
250
    virtual void showQtDumperLibraryWarning(const QString &details = QString()) = 0;
251
    virtual bool isReverseDebugging() const = 0;
252

253
254
    virtual qint64 inferiorPid() const = 0;

hjk's avatar
hjk committed
255
    virtual DebuggerStartParametersPtr startParameters() const = 0;
con's avatar
con committed
256
257
258
259
260
261
262
};


//
// DebuggerManager
//

263
class DebuggerManager : public QObject, public IDebuggerManagerAccessForEngines
con's avatar
con committed
264
265
266
267
{
    Q_OBJECT

public:
268
    DebuggerManager();
269
    QList<Core::IOptionsPage*> initializeEngines(unsigned enabledTypeFlags);
270

con's avatar
con committed
271
272
273
    ~DebuggerManager();

    IDebuggerManagerAccessForEngines *engineInterface();
274
    Core::Utils::FancyMainWindow *mainWindow() const { return m_mainWindow; }
275
    QLabel *statusLabel() const { return m_statusLabel; }
276
    IDebuggerEngine *currentEngine() const { return m_engine; }
con's avatar
con committed
277

hjk's avatar
hjk committed
278
    virtual DebuggerStartParametersPtr startParameters() const;
hjk's avatar
hjk committed
279
280
    virtual qint64 inferiorPid() const;

281
282
    void showMessageBox(int icon, const QString &title, const QString &text);

con's avatar
con committed
283
public slots:
hjk's avatar
hjk committed
284
    void startNewDebugger(const DebuggerStartParametersPtr &sp);
285
286
    void exitDebugger();

con's avatar
con committed
287
288
289
290
291
    void setSimpleDockWidgetArrangement();

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

292
    void gotoLocation(const StackFrame &frame, bool setLocationMarker);
293
    void fileOpen(const QString &file);
con's avatar
con committed
294
295
296
297
298
299
300
301
302
    void resetLocation();

    void interruptDebuggingRequest();

    void jumpToLineExec();
    void runToLineExec();
    void runToFunctionExec();
    void toggleBreakpoint();
    void breakByFunction(const QString &functionName);
303
    void breakByFunctionMain();
con's avatar
con committed
304
305
306
307
308
309
310
311
    void setBreakpoint(const QString &fileName, int lineNumber);
    void activateFrame(int index);
    void selectThread(int index);

    void stepExec();
    void stepOutExec();
    void nextExec();
    void continueExec();
312
    void detachDebugger();
con's avatar
con committed
313
314

    void addToWatchWindow();
315
    void updateWatchData(const WatchData &data);
316

con's avatar
con committed
317
    void sessionLoaded();
318
    void aboutToUnloadSession();
con's avatar
con committed
319
    void aboutToSaveSession();
320
321
    QVariant sessionValue(const QString &name);
    void setSessionValue(const QString &name, const QVariant &value);
con's avatar
con committed
322

323
    void assignValueInDebugger();
con's avatar
con committed
324
    void assignValueInDebugger(const QString &expr, const QString &value);
325
326

    void executeDebuggerCommand();
con's avatar
con committed
327
328
    void executeDebuggerCommand(const QString &command);

329
    void watchPoint();
330
    void setRegisterValue(int nr, const QString &value);
331

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

private slots:
hjk's avatar
hjk committed
335
336
    void showDebuggerOutput(const QString &msg)
        { showDebuggerOutput(LogDebug, msg); }
337
338
    void showDebuggerOutput(int channel, const QString &msg);
    void showDebuggerInput(int channel, const QString &msg);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
339
    void showApplicationOutput(const QString &data);
con's avatar
con committed
340

341
342
343
    void reloadSourceFiles();
    void sourceFilesDockToggled(bool on);

con's avatar
con committed
344
345
346
347
348
349
350
351
    void reloadModules();
    void modulesDockToggled(bool on);
    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();

    void reloadRegisters();
    void registerDockToggled(bool on);
    void setStatus(int status);
352
    void clearStatusMessage();
353
    void attemptBreakpointSynchronization();
354
    void reloadFullStack();
355
    void stepByInstructionTriggered();
hjk's avatar
hjk committed
356
    void startFailed();
con's avatar
con committed
357
358
359
360

private:
    //
    // Implementation of IDebuggerManagerAccessForEngines
361
    //
con's avatar
con committed
362
363
364
365
366
367
    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; }
368
    SourceFilesWindow *sourceFileWindow() { return m_sourceFilesWindow; }
369

con's avatar
con committed
370
371
    void notifyInferiorStopped();
    void notifyInferiorRunningRequested();
372
    void notifyInferiorStopRequested();
con's avatar
con committed
373
374
    void notifyInferiorRunning();
    void notifyInferiorExited();
375
    void notifyInferiorPidChanged(qint64);
con's avatar
con committed
376

377
    void cleanupViews();
con's avatar
con committed
378
379
380
381

    //
    // Implementation of IDebuggerManagerAccessForDebugMode
    //
382
    QWidget *threadsWindow() const { return m_threadsWindow; }
con's avatar
con committed
383

384
385
    virtual bool qtDumperLibraryEnabled() const;
    virtual QString qtDumperLibraryName() const;
386
    virtual QStringList qtDumperLibraryLocations() const;
387
    virtual void showQtDumperLibraryWarning(const QString &details = QString());
388
    virtual bool isReverseDebugging() const;
389

390
    //
con's avatar
con committed
391
    // internal implementation
392
    //
con's avatar
con committed
393
394
395
396
397
    Q_SLOT void loadSessionData();
    Q_SLOT void saveSessionData();
    Q_SLOT void dumpLog();

public:
398
    // stuff in this block should be made private by moving it to
con's avatar
con committed
399
400
401
    // one of the interfaces
    QAbstractItemModel *threadsModel();
    int status() const { return m_status; }
hjk's avatar
hjk committed
402
    // FIXME: hide this in the engines?
hjk's avatar
hjk committed
403
    //DebuggerStartMode startMode() const;
con's avatar
con committed
404

405
406
    QList<Symbol> moduleSymbols(const QString &moduleName);

con's avatar
con committed
407
408
409
410
411
412
413
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'
414
    void gotoLocationRequested(const StackFrame &frame, bool setLocationMarker);
con's avatar
con committed
415
416
417
418
419
420
    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
421
    void applicationOutputAvailable(const QString &output);
con's avatar
con committed
422
423

private:
424
    void init();
hjk's avatar
hjk committed
425
    void runTest(const QString &fileName);
hjk's avatar
hjk committed
426
    Q_SLOT void createNewDock(QWidget *widget);
con's avatar
con committed
427
428
429
430

    void shutdown();

    void toggleBreakpoint(const QString &fileName, int lineNumber);
431
432
    void toggleBreakpointEnabled(const QString &fileName, int lineNumber);
    BreakpointData *findBreakpoint(const QString &fileName, int lineNumber);
433
    void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos);
con's avatar
con committed
434

hjk's avatar
hjk committed
435
    // FIXME: Remove engine-specific state
hjk's avatar
hjk committed
436
    DebuggerStartParametersPtr m_startParameters;
437
438
    qint64 m_inferiorPid;

con's avatar
con committed
439
440

    /// Views
441
    Core::Utils::FancyMainWindow *m_mainWindow;
442
    QLabel *m_statusLabel;
con's avatar
con committed
443
444
445
446
447
    QDockWidget *m_breakDock;
    QDockWidget *m_modulesDock;
    QDockWidget *m_outputDock;
    QDockWidget *m_registerDock;
    QDockWidget *m_stackDock;
448
    QDockWidget *m_sourceFilesDock;
con's avatar
con committed
449
450
451
452
453
454
455
456
457
    QDockWidget *m_threadsDock;
    QDockWidget *m_watchDock;

    BreakHandler *m_breakHandler;
    ModulesHandler *m_modulesHandler;
    RegisterHandler *m_registerHandler;
    StackHandler *m_stackHandler;
    ThreadsHandler *m_threadsHandler;
    WatchHandler *m_watchHandler;
458
    SourceFilesWindow *m_sourceFilesWindow;
con's avatar
con committed
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473

    /// 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_sepAction;
474
    //QActio *m_stepByInstructionAction;
475
    QAction *m_reverseDirectionAction;
con's avatar
con committed
476
477

    QWidget *m_breakWindow;
478
    QWidget *m_localsWindow;
con's avatar
con committed
479
480
    QWidget *m_registerWindow;
    QWidget *m_modulesWindow;
481
    //QWidget *m_tooltipWindow;
con's avatar
con committed
482
483
    QWidget *m_stackWindow;
    QWidget *m_threadsWindow;
484
    QWidget *m_watchersWindow;
con's avatar
con committed
485
486
487
488
    DebuggerOutputWindow *m_outputWindow;

    int m_status;
    bool m_busy;
489
490
    QTimer *m_statusTimer;
    QString m_lastPermanentStatusMessage;
con's avatar
con committed
491
492
493
494
495
496
497
498
499

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

} // namespace Internal
} // namespace Debugger

#endif // DEBUGGER_DEBUGGERMANAGER_H