debuggerengine.h 11.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** 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.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#ifndef DEBUGGER_DEBUGGERENGINE_H
#define DEBUGGER_DEBUGGERENGINE_H

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

#include <coreplugin/ssh/sshconnection.h> 

40 41
#include <utils/environment.h>

42 43 44 45 46 47
#include <QtCore/QObject>
#include <QtCore/QStringList>

QT_BEGIN_NAMESPACE
class QDebug;
class QPoint;
48
class QMessageBox;
49 50 51 52 53 54 55 56 57 58 59 60
QT_END_NAMESPACE

namespace TextEditor {
class ITextEditor;
}

namespace Core {
class IOptionsPage;
}

namespace Debugger {

61
class DebuggerEnginePrivate;
hjk's avatar
hjk committed
62
class DebuggerRunControl;
63
class QmlCppEngine;
64 65 66 67 68 69 70 71 72 73

class DEBUGGER_EXPORT DebuggerStartParameters
{
public:
    DebuggerStartParameters();
    void clear();

    QString executable;
    QString displayName;
    QString coreFile;
74
    bool isSnapshot; // set if created internally
75 76
    QString processArgs;
    Utils::Environment environment;
77 78 79 80 81
    QString workingDirectory;
    qint64 attachPID;
    bool useTerminal;
    bool breakAtMain;
    QString crashParameter; // for AttachCrashedExternal
82

Lasse Holmstedt's avatar
Lasse Holmstedt committed
83 84 85
    // for qml debugging
    QString qmlServerAddress;
    quint16 qmlServerPort;
86 87 88 89
    QString projectBuildDir;
    QString projectDir;
    // for cpp+qml debugging
    DebuggerEngineType cppEngineType;
Lasse Holmstedt's avatar
Lasse Holmstedt committed
90

91 92 93
    // for remote debugging
    QString remoteChannel;
    QString remoteArchitecture;
94
    QString gnuTarget;
95
    QString symbolFileName;
hjk's avatar
hjk committed
96
    bool useServerStartScript;
97 98
    QString serverStartScript;
    QString sysRoot;
99 100
    QByteArray remoteDumperLib;
    QByteArray remoteSourcesDir;
101 102
    QString remoteMountPoint;
    QString localMountDir;
103 104
    Core::SshConnectionParameters connParams;

105 106 107 108 109 110 111
    QString debuggerCommand;
    int toolChainType;
    QString qtInstallPath;

    QString dumperLibrary;
    QStringList dumperLibraryLocations;
    DebuggerStartMode startMode;
112 113 114

    // for SymbianOS debugging
    quint32 executableUid;
115 116 117 118 119 120 121
};

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

namespace Internal {

122
class DebuggerPluginPrivate;
123 124 125 126 127 128 129 130 131 132 133
class DisassemblerViewAgent;
class MemoryViewAgent;
class WatchData;
class BreakHandler;
class ModulesHandler;
class RegisterHandler;
class StackHandler;
class StackFrame;
class SourceFilesHandler;
class ThreadsHandler;
class WatchHandler;
134
class BreakpointParameters;
135

136 137 138 139 140
struct WatchUpdateFlags
{
    WatchUpdateFlags() : tryIncremental(false) {}
    bool tryIncremental;
};
hjk's avatar
hjk committed
141

142
} // namespace Internal
143

hjk's avatar
hjk committed
144

145 146
// FIXME: DEBUGGER_EXPORT?
class DEBUGGER_EXPORT DebuggerEngine : public QObject
147 148 149 150
{
    Q_OBJECT

public:
151
    explicit DebuggerEngine(const DebuggerStartParameters &sp);
152 153
    virtual ~DebuggerEngine();

154
    typedef Internal::BreakpointId BreakpointId;
155
    virtual void setToolTipExpression(const QPoint & mousePos,
hjk's avatar
hjk committed
156
        TextEditor::ITextEditor *editor, int cursorPos);
hjk's avatar
hjk committed
157

158
    virtual void updateWatchData(const Internal::WatchData &data,
159
        const Internal::WatchUpdateFlags & flags = Internal::WatchUpdateFlags());
160
    void startDebugger(DebuggerRunControl *runControl);
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

    virtual void watchPoint(const QPoint &);
    virtual void fetchMemory(Internal::MemoryViewAgent *, QObject *,
                             quint64 addr, quint64 length);
    virtual void fetchDisassembler(Internal::DisassemblerViewAgent *);
    virtual void activateFrame(int index);

    virtual void reloadModules();
    virtual void examineModules();
    virtual void loadSymbols(const QString &moduleName);
    virtual void loadAllSymbols();
    virtual void requestModuleSymbols(const QString &moduleName);

    virtual void reloadRegisters();
    virtual void reloadSourceFiles();
    virtual void reloadFullStack();
hjk's avatar
hjk committed
177 178

    virtual void setRegisterValue(int regnr, const QString &value);
179 180
    virtual void addOptionPages(QList<Core::IOptionsPage*> *) const;
    virtual unsigned debuggerCapabilities() const;
hjk's avatar
hjk committed
181

182 183
    virtual bool isSynchronous() const;
    virtual QByteArray qtNamespace() const;
hjk's avatar
hjk committed
184

185 186
    virtual void createSnapshot();
    virtual void updateAll();
hjk's avatar
hjk committed
187

188

hjk's avatar
hjk committed
189 190 191 192 193 194
    virtual bool stateAcceptsBreakpointChanges() const { return true; }
    virtual void attemptBreakpointSynchronization();
    virtual bool acceptsBreakpoint(BreakpointId id) const;  // FIXME: make pure
    virtual void insertBreakpoint(BreakpointId id);  // FIXME: make pure
    virtual void removeBreakpoint(BreakpointId id);  // FIXME: make pure
    virtual void changeBreakpoint(BreakpointId id);  // FIXME: make pure
hjk's avatar
hjk committed
195

hjk's avatar
hjk committed
196 197
    virtual void assignValueInDebugger(const Internal::WatchData *data,
        const QString &expr, const QVariant &value);
198
    virtual void removeTooltip();
hjk's avatar
hjk committed
199
    virtual void selectThread(int index);
200

hjk's avatar
hjk committed
201
protected:
202
    friend class Internal::DebuggerPluginPrivate;
203
    virtual void detachDebugger();
204
    virtual void exitDebugger();
205 206 207 208 209 210
    virtual void executeStep();
    virtual void executeStepOut() ;
    virtual void executeNext();
    virtual void executeStepI();
    virtual void executeNextI();
    virtual void executeReturn();
211

212 213
    virtual void continueInferior();
    virtual void interruptInferior();
214 215
    virtual void requestInterruptInferior();

216 217 218 219
    virtual void executeRunToLine(const QString &fileName, int lineNumber);
    virtual void executeRunToFunction(const QString &functionName);
    virtual void executeJumpToLine(const QString &fileName, int lineNumber);
    virtual void executeDebuggerCommand(const QString &command);
220 221 222 223 224 225 226 227

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

public:
    const DebuggerStartParameters &startParameters() const;
    DebuggerStartParameters &startParameters();

228 229 230 231 232 233
    Internal::ModulesHandler *modulesHandler() const;
    Internal::RegisterHandler *registerHandler() const;
    Internal::StackHandler *stackHandler() const;
    Internal::ThreadsHandler *threadsHandler() const;
    Internal::WatchHandler *watchHandler() const;
    Internal::SourceFilesHandler *sourceFilesHandler() const;
234
    Internal::BreakHandler *breakHandler() const;
235

236 237 238 239 240 241 242 243
    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;
    virtual QAbstractItemModel *sourceFilesModel() const;
244

245
    void progressPing();
246
    void handleFinished();
247
    void handleStartFailed();
248 249
    bool debuggerActionsEnabled() const;
    static bool debuggerActionsEnabled(DebuggerState state);
250
    void showModuleSymbols(const QString &moduleName, const Internal::Symbols &symbols);
251 252 253 254 255

    void breakByFunction(const QString &functionName);
    void breakByFunctionMain();
    
    DebuggerState state() const;
hjk's avatar
hjk committed
256 257
    DebuggerState lastGoodState() const;
    DebuggerState targetState() const;
258
    bool isDying() const;
259 260 261 262 263

    // Dumper stuff (common to cdb and gdb).
    bool qtDumperLibraryEnabled() const;
    QString qtDumperLibraryName() const;
    QStringList qtDumperLibraryLocations() const;
264
    void showQtDumperLibraryWarning(const QString &details);
265 266 267 268 269 270

    static const char *stateName(int s);

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

273
    // Convenience
Friedemann Kleint's avatar
Friedemann Kleint committed
274 275
    Q_SLOT void showMessage(const QString &msg, int channel = LogDebug, int timeout = -1) const;
    Q_SLOT void showStatusMessage(const QString &msg, int timeout = -1) const;
276

277
    void resetLocation();
278
    virtual void gotoLocation(const QString &fileName, int lineNumber, bool setMarker);
279
    virtual void gotoLocation(const Internal::StackFrame &frame, bool setMarker);
hjk's avatar
hjk committed
280
    virtual void quitDebugger(); // called by DebuggerRunControl
281

282
    virtual void updateViews();
hjk's avatar
x  
hjk committed
283
    bool isSlaveEngine() const;
284

285 286
signals:
    void stateChanged(const DebuggerState &state);
287
    void updateViewsRequested();
288

289
protected:
290 291 292 293 294 295
    // 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();
296

297 298
    virtual void notifyInferiorSetupOk();
    virtual void notifyInferiorSetupFailed();
hjk's avatar
hjk committed
299

300 301 302
    virtual void notifyEngineRunAndInferiorRunOk();
    virtual void notifyEngineRunAndInferiorStopOk();
    virtual void notifyInferiorUnrunnable(); // Called by CoreAdapter.
hjk's avatar
hjk committed
303 304

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

307 308 309
    virtual void notifyInferiorRunRequested();
    virtual void notifyInferiorRunOk();
    virtual void notifyInferiorRunFailed();
hjk's avatar
hjk committed
310

311 312 313 314
    virtual void notifyInferiorStopOk();
    virtual void notifyInferiorSpontaneousStop();
    virtual void notifyInferiorStopFailed();
    virtual void notifyInferiorExited();
hjk's avatar
hjk committed
315

316 317
    virtual void notifyInferiorShutdownOk();
    virtual void notifyInferiorShutdownFailed();
hjk's avatar
hjk committed
318

319 320 321
    virtual void notifyEngineSpontaneousShutdown();
    virtual void notifyEngineShutdownOk();
    virtual void notifyEngineShutdownFailed();
322

323 324
    virtual void notifyInferiorIll();
    virtual void notifyEngineIll();
325

hjk's avatar
hjk committed
326 327 328 329 330
    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
331

hjk's avatar
hjk committed
332
    void setState(DebuggerState state, bool forced = false);
333
    void setSlaveEngine(bool value);
334

335
protected:
336
    DebuggerRunControl *runControl() const;
hjk's avatar
hjk committed
337

338 339 340 341 342 343 344 345 346 347 348
    static QString msgWatchpointTriggered(BreakpointId id, int number, quint64 address);
    static QString msgWatchpointTriggered(BreakpointId id, int number, quint64 address,
                                          const QString &threadId);
    static QString msgBreakpointTriggered(BreakpointId id, int number, const QString &threadId);
    static QString msgStopped(const QString &reason = QString());
    static QString msgStoppedBySignal(const QString &meaning, const QString &name);
    static QString msgStoppedByException(const QString &description, const QString &threadId);
    static QString msgInterrupted();
    void showStoppedBySignalMessageBox(QString meaning, QString name);
    void showStoppedByExceptionMessageBox(const QString &description);

hjk's avatar
hjk committed
349
private:
350 351 352
    // wrapper engine needs access to state of its subengines
    friend class QmlCppEngine;

hjk's avatar
hjk committed
353
    friend class DebuggerEnginePrivate;
354 355 356 357 358 359
    DebuggerEnginePrivate *d;
};

} // namespace Debugger

#endif // DEBUGGER_DEBUGGERENGINE_H