debuggerengine.h 14.4 KB
Newer Older
1 2 3 4
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
8 9 10 11
**
**
** GNU Lesser General Public License Usage
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** 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.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
30 31 32 33 34 35 36 37
**
**************************************************************************/

#ifndef DEBUGGER_DEBUGGERENGINE_H
#define DEBUGGER_DEBUGGERENGINE_H

#include "debugger_global.h"
#include "debuggerconstants.h"
hjk's avatar
hjk committed
38
#include "breakpoint.h" // For 'BreakpointId'
39

40 41 42 43 44 45
#include <QtCore/QObject>
#include <QtCore/QStringList>

QT_BEGIN_NAMESPACE
class QDebug;
class QPoint;
46
class QMessageBox;
Friedemann Kleint's avatar
Friedemann Kleint committed
47
class QAbstractItemModel;
48 49 50 51 52 53 54 55 56 57 58 59
QT_END_NAMESPACE

namespace TextEditor {
class ITextEditor;
}

namespace Core {
class IOptionsPage;
}

namespace Debugger {

60
class DebuggerEnginePrivate;
hjk's avatar
hjk committed
61
class DebuggerRunControl;
Friedemann Kleint's avatar
Friedemann Kleint committed
62
class DebuggerStartParameters;
63 64 65 66 67 68

DEBUGGER_EXPORT QDebug operator<<(QDebug str, const DebuggerStartParameters &);
DEBUGGER_EXPORT QDebug operator<<(QDebug str, DebuggerState state);

namespace Internal {

69
class DebuggerPluginPrivate;
70 71
class DisassemblerAgent;
class MemoryAgent;
72 73 74 75 76 77 78 79 80
class WatchData;
class BreakHandler;
class ModulesHandler;
class RegisterHandler;
class StackHandler;
class StackFrame;
class SourceFilesHandler;
class ThreadsHandler;
class WatchHandler;
81
class BreakpointParameters;
82
class QmlCppEngine;
83
class DebuggerToolTipContext;
84
class MemoryMarkup;
85

86 87 88 89 90
struct WatchUpdateFlags
{
    WatchUpdateFlags() : tryIncremental(false) {}
    bool tryIncremental;
};
hjk's avatar
hjk committed
91

92 93 94 95 96 97 98 99
class Location
{
public:
    Location() { init(); }
    Location(quint64 address) { init(); m_address = address; }
    Location(const QString &file) { init(); m_fileName = file; }
    Location(const QString &file, int line, bool marker = true)
        { init(); m_lineNumber = line; m_fileName = file; m_needsMarker = marker; }
Friedemann Kleint's avatar
Friedemann Kleint committed
100
    Location(const StackFrame &frame, bool marker = true);
101 102
    QString fileName() const { return m_fileName; }
    QString functionName() const { return m_functionName; }
103
    QString from() const { return m_from; }
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    int lineNumber() const { return m_lineNumber; }
    void setNeedsRaise(bool on) { m_needsRaise = on; }
    void setNeedsMarker(bool on) { m_needsMarker = on; }
    void setFileName(const QString &fileName) { m_fileName = fileName; }
    bool needsRaise() const { return m_needsRaise; }
    bool needsMarker() const { return m_needsMarker; }
    bool hasDebugInfo() const { return m_hasDebugInfo; }
    quint64 address() const { return m_address; }

private:
    void init() { m_needsMarker = false; m_needsRaise = true; m_lineNumber = -1;
        m_address = 0; m_hasDebugInfo = true; }
    bool m_needsMarker;
    bool m_needsRaise;
    bool m_hasDebugInfo;
    int m_lineNumber;
    QString m_fileName;
    QString m_functionName;
122
    QString m_from;
123 124 125
    quint64 m_address;
};

126 127 128 129 130 131 132 133 134 135 136
class ContextData
{
public:
    ContextData() : lineNumber(0), address(0) {}

public:
    QString fileName;
    int lineNumber;
    quint64 address;
};

137
} // namespace Internal
138

hjk's avatar
hjk committed
139

140 141
// FIXME: DEBUGGER_EXPORT?
class DEBUGGER_EXPORT DebuggerEngine : public QObject
142 143 144 145
{
    Q_OBJECT

public:
146
    explicit DebuggerEngine(const DebuggerStartParameters &sp,
147
        DebuggerLanguages languages,
148
        DebuggerEngine *parentEngine = 0);
149 150
    virtual ~DebuggerEngine();

hjk's avatar
hjk committed
151 152 153
    const DebuggerStartParameters &startParameters() const;
    DebuggerStartParameters &startParameters();

154
    virtual bool setToolTipExpression(const QPoint & mousePos,
155
        TextEditor::ITextEditor *editor, const Internal::DebuggerToolTipContext &);
hjk's avatar
hjk committed
156

157
    virtual void updateWatchData(const Internal::WatchData &data,
158
        const Internal::WatchUpdateFlags & flags = Internal::WatchUpdateFlags());
159
    virtual void startDebugger(DebuggerRunControl *runControl);
160 161

    virtual void watchPoint(const QPoint &);
162 163 164 165 166 167 168 169 170 171 172 173

    enum MemoryViewFlags
    {
        MemoryReadOnly = 0x1,      //!< Read-only.
        MemoryTrackRegister = 0x2, //!< Address parameter is register number to track
        MemoryView = 0x4           //!< Open a separate view (using the pos-parameter).
    };

    virtual void openMemoryView(quint64 startAddr, unsigned flags,
                                const QList<Internal::MemoryMarkup> &ml,
                                const QPoint &pos,
                                const QString &title = QString(), QWidget *parent = 0);
174
    virtual void fetchMemory(Internal::MemoryAgent *, QObject *,
175
                             quint64 addr, quint64 length);
hjk's avatar
hjk committed
176 177
    virtual void changeMemory(Internal::MemoryAgent *, QObject *,
                              quint64 addr, const QByteArray &data);
178
    virtual void updateMemoryViews();
179
    virtual void openDisassemblerView(const Internal::Location &location);
180
    virtual void fetchDisassembler(Internal::DisassemblerAgent *);
181 182 183 184 185
    virtual void activateFrame(int index);

    virtual void reloadModules();
    virtual void examineModules();
    virtual void loadSymbols(const QString &moduleName);
186
    virtual void loadSymbolsForStack();
187 188 189 190 191 192
    virtual void loadAllSymbols();
    virtual void requestModuleSymbols(const QString &moduleName);

    virtual void reloadRegisters();
    virtual void reloadSourceFiles();
    virtual void reloadFullStack();
hjk's avatar
hjk committed
193 194

    virtual void setRegisterValue(int regnr, const QString &value);
195
    virtual void addOptionPages(QList<Core::IOptionsPage*> *) const;
196
    virtual bool hasCapability(unsigned cap) const = 0;
hjk's avatar
hjk committed
197

198 199
    virtual bool isSynchronous() const;
    virtual QByteArray qtNamespace() const;
hjk's avatar
hjk committed
200

201 202
    virtual void createSnapshot();
    virtual void updateAll();
hjk's avatar
hjk committed
203

204
    typedef Internal::BreakpointModelId BreakpointModelId;
hjk's avatar
hjk committed
205 206
    virtual bool stateAcceptsBreakpointChanges() const { return true; }
    virtual void attemptBreakpointSynchronization();
207 208 209 210
    virtual bool acceptsBreakpoint(BreakpointModelId id) const = 0;
    virtual void insertBreakpoint(BreakpointModelId id);  // FIXME: make pure
    virtual void removeBreakpoint(BreakpointModelId id);  // FIXME: make pure
    virtual void changeBreakpoint(BreakpointModelId id);  // FIXME: make pure
hjk's avatar
hjk committed
211

212
    virtual bool acceptsDebuggerCommands() const { return true; }
hjk's avatar
hjk committed
213 214
    virtual void assignValueInDebugger(const Internal::WatchData *data,
        const QString &expr, const QVariant &value);
hjk's avatar
hjk committed
215
    virtual void selectThread(int index);
216

217 218 219
    virtual void handleRemoteSetupDone(int gdbServerPort, int qmlPort);
    virtual void handleRemoteSetupFailed(const QString &message);

220 221 222 223 224 225 226
    virtual Internal::ModulesHandler *modulesHandler() const;
    virtual Internal::RegisterHandler *registerHandler() const;
    virtual Internal::StackHandler *stackHandler() const;
    virtual Internal::ThreadsHandler *threadsHandler() const;
    virtual Internal::WatchHandler *watchHandler() const;
    virtual Internal::SourceFilesHandler *sourceFilesHandler() const;
    virtual Internal::BreakHandler *breakHandler() const;
227

228 229 230 231 232 233 234
    virtual QAbstractItemModel *modulesModel() const;
    virtual QAbstractItemModel *registerModel() const;
    virtual QAbstractItemModel *stackModel() const;
    virtual QAbstractItemModel *threadsModel() const;
    virtual QAbstractItemModel *localsModel() const;
    virtual QAbstractItemModel *watchersModel() const;
    virtual QAbstractItemModel *returnModel() const;
235
    virtual QAbstractItemModel *toolTipsModel() const;
236
    virtual QAbstractItemModel *sourceFilesModel() const;
237

238
    void progressPing();
239
    void handleFinished();
240
    void handleStartFailed();
241 242 243 244
    bool debuggerActionsEnabled() const;
    static bool debuggerActionsEnabled(DebuggerState state);

    DebuggerState state() const;
hjk's avatar
hjk committed
245 246
    DebuggerState lastGoodState() const;
    DebuggerState targetState() const;
247
    bool isDying() const;
248 249 250 251 252

    // Dumper stuff (common to cdb and gdb).
    bool qtDumperLibraryEnabled() const;
    QString qtDumperLibraryName() const;
    QStringList qtDumperLibraryLocations() const;
253
    void showQtDumperLibraryWarning(const QString &details);
254 255 256 257 258 259

    static const char *stateName(int s);

    void notifyInferiorPid(qint64 pid);
    qint64 inferiorPid() const;
    bool isReverseDebugging() const;
260
    void handleCommand(int role, const QVariant &value);
261

262
    // Convenience
263
    Q_SLOT virtual void showMessage(const QString &msg, int channel = LogDebug,
264
        int timeout = -1) const;
Friedemann Kleint's avatar
Friedemann Kleint committed
265
    Q_SLOT void showStatusMessage(const QString &msg, int timeout = -1) const;
266

267
    virtual void resetLocation();
268
    virtual void gotoLocation(const Internal::Location &location);
hjk's avatar
hjk committed
269
    virtual void quitDebugger(); // called by DebuggerRunControl
hjk's avatar
hjk committed
270
    virtual void abortDebugger(); // called by DebuggerPlugin
271

272
    virtual void updateViews();
hjk's avatar
x  
hjk committed
273
    bool isSlaveEngine() const;
274
    bool isMasterEngine() const;
hjk's avatar
hjk committed
275
    DebuggerEngine *masterEngine() const;
276

277 278
    DebuggerLanguages languages() const;

279 280
    virtual bool setupQmlStep(bool /*on*/) { return false; }
    virtual void readyToExecuteQmlStep() {}
281

282 283
    virtual bool canDisplayTooltip() const { return state() == InferiorStopOk; }

284 285
    virtual void notifyInferiorIll();

286
signals:
287
    void stateChanged(const Debugger::DebuggerState &state);
288 289
    // A new stack frame is on display including locals.
    void stackFrameCompleted();
290
    void updateViewsRequested();
291
    /*
292
     * For "external" clients of a debugger run control that needs to do
293
     * further setup before the debugger is started (e.g. Maemo).
294
     * Afterwards, handleRemoteSetupDone() or handleRemoteSetupFailed() must be called
295 296 297 298 299
     * to continue or abort debugging, respectively.
     * This signal is only emitted if the start parameters indicate that
     * a server start script should be used, but none is given.
     */
    void requestRemoteSetup();
300

301
protected:
302 303 304 305 306 307
    // The base notify*() function implementation should be sufficient
    // in most cases, but engines are free to override them to do some
    // engine specific cleanup like stopping timers etc.
    virtual void notifyEngineSetupOk();
    virtual void notifyEngineSetupFailed();
    virtual void notifyEngineRunFailed();
308

309 310
    virtual void notifyInferiorSetupOk();
    virtual void notifyInferiorSetupFailed();
hjk's avatar
hjk committed
311

312 313 314
    virtual void notifyEngineRunAndInferiorRunOk();
    virtual void notifyEngineRunAndInferiorStopOk();
    virtual void notifyInferiorUnrunnable(); // Called by CoreAdapter.
hjk's avatar
hjk committed
315 316

    // Use notifyInferiorRunRequested() plus notifyInferiorRunOk() instead.
317
    //virtual void notifyInferiorSpontaneousRun();
hjk's avatar
hjk committed
318

319 320 321
    virtual void notifyInferiorRunRequested();
    virtual void notifyInferiorRunOk();
    virtual void notifyInferiorRunFailed();
hjk's avatar
hjk committed
322

323 324 325 326
    virtual void notifyInferiorStopOk();
    virtual void notifyInferiorSpontaneousStop();
    virtual void notifyInferiorStopFailed();
    virtual void notifyInferiorExited();
hjk's avatar
hjk committed
327

328 329
    virtual void notifyInferiorShutdownOk();
    virtual void notifyInferiorShutdownFailed();
hjk's avatar
hjk committed
330

331 332 333
    virtual void notifyEngineSpontaneousShutdown();
    virtual void notifyEngineShutdownOk();
    virtual void notifyEngineShutdownFailed();
334

335
    virtual void notifyEngineIll();
336

hjk's avatar
hjk committed
337 338 339 340 341
    virtual void setupEngine() = 0;
    virtual void setupInferior() = 0;
    virtual void runEngine() = 0;
    virtual void shutdownInferior() = 0;
    virtual void shutdownEngine() = 0;
hjk's avatar
hjk committed
342

hjk's avatar
hjk committed
343 344 345
    virtual void detachDebugger();
    virtual void exitDebugger();
    virtual void executeStep();
hjk's avatar
hjk committed
346
    virtual void executeStepOut();
hjk's avatar
hjk committed
347 348 349 350 351 352 353 354 355
    virtual void executeNext();
    virtual void executeStepI();
    virtual void executeNextI();
    virtual void executeReturn();

    virtual void continueInferior();
    virtual void interruptInferior();
    virtual void requestInterruptInferior();

356
    virtual void executeRunToLine(const Internal::ContextData &data);
hjk's avatar
hjk committed
357
    virtual void executeRunToFunction(const QString &functionName);
358
    virtual void executeJumpToLine(const Internal::ContextData &data);
hjk's avatar
hjk committed
359 360 361 362 363
    virtual void executeDebuggerCommand(const QString &command);

    virtual void frameUp();
    virtual void frameDown();

364
    DebuggerRunControl *runControl() const;
hjk's avatar
hjk committed
365

366
    static QString msgWatchpointByAddressTriggered(BreakpointModelId id,
hjk's avatar
hjk committed
367
        int number, quint64 address);
368
    static QString msgWatchpointByAddressTriggered(BreakpointModelId id,
hjk's avatar
hjk committed
369
        int number, quint64 address, const QString &threadId);
370
    static QString msgWatchpointByExpressionTriggered(BreakpointModelId id,
371
        int number, const QString &expr);
372
    static QString msgWatchpointByExpressionTriggered(BreakpointModelId id,
373
        int number, const QString &expr, const QString &threadId);
374
    static QString msgBreakpointTriggered(BreakpointModelId id,
hjk's avatar
hjk committed
375
        int number, const QString &threadId);
376 377
    static QString msgStopped(const QString &reason = QString());
    static QString msgStoppedBySignal(const QString &meaning, const QString &name);
hjk's avatar
hjk committed
378 379
    static QString msgStoppedByException(const QString &description,
        const QString &threadId);
380
    static QString msgInterrupted();
hjk's avatar
hjk committed
381
    void showStoppedBySignalMessageBox(const QString meaning, QString name);
382 383
    void showStoppedByExceptionMessageBox(const QString &description);

384 385
    static bool isCppBreakpoint(const Internal::BreakpointParameters &p);

386 387 388
    bool isStateDebugging() const;
    void setStateDebugging(bool on);

389 390 391 392 393
    virtual void setupSlaveInferior();
    virtual void setupSlaveEngine();
    virtual void runSlaveEngine();
    virtual void shutdownSlaveEngine();

394 395 396
    virtual void slaveEngineStateChanged(DebuggerEngine *engine,
        DebuggerState state);

397 398
    virtual void handleAutoTests();

hjk's avatar
hjk committed
399
private:
400
    // Wrapper engine needs access to state of its subengines.
401
    friend class Internal::QmlCppEngine;
hjk's avatar
hjk committed
402
    friend class Internal::DebuggerPluginPrivate;
403
    friend class QmlAdapter;
hjk's avatar
hjk committed
404

405
    virtual void setState(DebuggerState state, bool forced = false);
406

hjk's avatar
hjk committed
407
    friend class DebuggerEnginePrivate;
408 409 410 411 412
    DebuggerEnginePrivate *d;
};

} // namespace Debugger

413 414
Q_DECLARE_METATYPE(Debugger::Internal::ContextData)

415
#endif // DEBUGGER_DEBUGGERENGINE_H