qmlengine.h 7.04 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29

Kai Koehne's avatar
Kai Koehne committed
30 31
#ifndef QMLENGINE_H
#define QMLENGINE_H
32

33
#include "debuggerengine.h"
Kai Koehne's avatar
Kai Koehne committed
34 35 36 37 38
#include "interactiveinterpreter.h"
#include "qmladapter.h"
#include "qmlinspectoradapter.h"

#include <projectexplorer/applicationlauncher.h>
39
#include <qmldebug/qdebugmessageclient.h>
Kai Koehne's avatar
Kai Koehne committed
40
#include <qmldebug/qmloutputparser.h>
41
#include <qmljs/iscriptevaluator.h>
hjk's avatar
hjk committed
42

Kai Koehne's avatar
Kai Koehne committed
43
#include <QTextDocument>
44 45

namespace Core {
46
class IDocument;
47 48
}

49
namespace Debugger {
50
namespace Internal {
51

52
class QmlAdapter;
53
class WatchTreeView;
54

55
class QmlEngine : public DebuggerEngine, QmlJS::IScriptEvaluator
56 57 58 59
{
    Q_OBJECT

public:
Aurindam Jana's avatar
Aurindam Jana committed
60 61
    explicit QmlEngine(const DebuggerStartParameters &startParameters,
                       DebuggerEngine *masterEngine = 0);
62
    ~QmlEngine();
63

Aurindam Jana's avatar
Aurindam Jana committed
64
    void notifyInferiorSetupOk();
65 66
    void notifyEngineRemoteSetupDone(int gdbServerPort, int qmlPort);
    void notifyEngineRemoteSetupFailed(const QString &message);
Aurindam Jana's avatar
Aurindam Jana committed
67
    void notifyEngineRemoteServerRunning(const QByteArray &, int pid);
68

69
    bool canDisplayTooltip() const;
70

71 72
    void showMessage(const QString &msg, int channel = LogDebug,
                     int timeout = -1) const;
73 74
    void gotoLocation(const Internal::Location &location);

75
    void filterApplicationMessage(const QString &msg, int channel);
76 77
    void inferiorSpontaneousStop();

Kai Koehne's avatar
Kai Koehne committed
78 79 80 81 82 83 84
    enum LogDirection {
        LogSend,
        LogReceive
    };

    void logMessage(const QString &service, LogDirection direction,
                    const QString &str);
85

86
    void setSourceFiles(const QStringList &fileNames);
Kai Koehne's avatar
Kai Koehne committed
87 88
    void updateScriptSource(const QString &fileName, int lineOffset,
                            int columnOffset, const QString &source);
89

90 91
    void insertBreakpoint(BreakpointModelId id);

Kai Koehne's avatar
Kai Koehne committed
92 93 94
signals:
    void tooltipRequested(const QPoint &mousePos,
        TextEditor::ITextEditor *editor, int cursorPos);
Aurindam Jana's avatar
Aurindam Jana committed
95
    void aboutToNotifyInferiorSetupOk();
Kai Koehne's avatar
Kai Koehne committed
96 97

private slots:
98
    void disconnected();
99
    void documentUpdated(QmlJS::Document::Ptr doc);
100
    void expressionEvaluated(quint32 queryId, const QVariant &result);
101

102
    void errorMessageBoxFinished(int result);
103
    void updateCurrentContext();
104
    void appendDebugOutput(QtMsgType type, const QString &message,
105
                           const QmlDebug::QDebugContextInfo &info);
106

Kai Koehne's avatar
Kai Koehne committed
107 108 109 110 111 112 113 114 115 116 117
    void tryToConnect(quint16 port = 0);
    void beginConnection(quint16 port = 0);
    void connectionEstablished();
    void connectionStartupFailed();
    void appStartupFailed(const QString &errorMessage);
    void connectionError(QAbstractSocket::SocketError error);
    void serviceConnectionError(const QString &service);
    void appendMessage(const QString &msg, Utils::OutputFormat);

    void synchronizeWatchers();

118
private:
119
    // DebuggerEngine implementation.
hjk's avatar
hjk committed
120
    bool isSynchronous() const { return false; }
121 122 123 124 125 126
    void executeStep();
    void executeStepOut();
    void executeNext();
    void executeStepI();
    void executeNextI();

hjk's avatar
hjk committed
127
    void setupEngine();
hjk's avatar
hjk committed
128 129 130 131 132
    void setupInferior();
    void runEngine();
    void shutdownInferior();
    void shutdownEngine();

133
    bool setToolTipExpression(const QPoint &mousePos,
134
        TextEditor::ITextEditor *editor, const DebuggerToolTipContext &);
135 136 137 138

    void continueInferior();
    void interruptInferior();

139
    void executeRunToLine(const ContextData &data);
140
    void executeRunToFunction(const QString &functionName);
141
    void executeJumpToLine(const ContextData &data);
142 143

    void activateFrame(int index);
hjk's avatar
hjk committed
144
    void selectThread(ThreadId threadId);
145 146

    void attemptBreakpointSynchronization();
147 148
    void removeBreakpoint(BreakpointModelId id);
    void changeBreakpoint(BreakpointModelId id);
149
    bool acceptsBreakpoint(BreakpointModelId id) const;
150

151
    void assignValueInDebugger(const WatchData *data,
hjk's avatar
hjk committed
152
        const QString &expr, const QVariant &value);
153 154


155 156 157 158 159
    void loadSymbols(const QString &moduleName);
    void loadAllSymbols();
    void requestModuleSymbols(const QString &moduleName);
    void reloadModules();
    void reloadRegisters() {}
160
    void reloadSourceFiles();
161 162
    void reloadFullStack() {}

Olivier Goffart's avatar
Olivier Goffart committed
163
    bool supportsThreads() const { return false; }
164 165
    void updateWatchData(const WatchData &data,
        const WatchUpdateFlags &flags);
166
    void watchDataSelected(const QByteArray &iname);
167
    void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
168
    bool evaluateScript(const QString &expression);
169

170
    bool hasCapability(unsigned) const;
171
    void quitDebugger();
172

173
private:
174 175 176 177
    void closeConnection();
    void startApplicationLauncher();
    void stopApplicationLauncher();

178 179
    bool isShadowBuildProject() const;
    QString fromShadowBuildFilename(const QString &filename) const;
hjk's avatar
hjk committed
180 181
    QString mangleFilenamePaths(const QString &filename,
        const QString &oldBasePath, const QString &newBasePath) const;
182 183
    QString qmlImportPath() const;

184
    void updateDocument(Core::IDocument *document, const QTextDocument *textDocument);
185
    bool canEvaluateScript(const QString &script);
186 187
    bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line,
                                       quint32 *column, bool *valid);
188

189 190
    WatchTreeView *inspectorTreeView() const;

Kai Koehne's avatar
Kai Koehne committed
191 192 193 194
    QmlAdapter m_adapter;
    QmlInspectorAdapter m_inspectorAdapter;
    ProjectExplorer::ApplicationLauncher m_applicationLauncher;
    QTimer m_noDebugOutputTimer;
Kai Koehne's avatar
Kai Koehne committed
195
    QmlDebug::QmlOutputParser m_outputParser;
Kai Koehne's avatar
Kai Koehne committed
196 197 198 199 200 201 202 203
    QHash<QString, QTextDocument*> m_sourceDocuments;
    QHash<QString, QWeakPointer<TextEditor::ITextEditor> > m_sourceEditors;
    InteractiveInterpreter m_interpreter;
    QHash<QString,BreakpointModelId> pendingBreakpoints;
    QList<quint32> queryIds;
    bool m_retryOnConnectFail;
    bool m_automaticConnect;

204
    friend class QmlCppEngine;
205 206
};

207
} // namespace Internal
208 209
} // namespace Debugger

Kai Koehne's avatar
Kai Koehne committed
210
#endif // QMLENGINE_H