forked from qt-creator/qt-creator
		
	QML Debugger: Mangle shadow build filenames
Without doing some magic for the filenames, we go to shadow build files instead of the real ones, resulting in confusion. The user should never see the shadow build files while debugging. Reviewed-by: hjk
This commit is contained in:
		@@ -80,7 +80,10 @@ public:
 | 
			
		||||
    // for qml debugging
 | 
			
		||||
    QString qmlServerAddress;
 | 
			
		||||
    quint16 qmlServerPort;
 | 
			
		||||
    DebuggerEngineType cppEngineType; // for cpp+qml debugging
 | 
			
		||||
    QString projectBuildDir;
 | 
			
		||||
    QString projectDir;
 | 
			
		||||
    // for cpp+qml debugging
 | 
			
		||||
    DebuggerEngineType cppEngineType;
 | 
			
		||||
 | 
			
		||||
    // for remote debugging
 | 
			
		||||
    QString remoteChannel;
 | 
			
		||||
@@ -274,8 +277,8 @@ public:
 | 
			
		||||
 | 
			
		||||
    void resetLocation();
 | 
			
		||||
    void openFile(const QString &fileName, int lineNumber = -1);
 | 
			
		||||
    void gotoLocation(const QString &fileName, int lineNumber, bool setMarker);
 | 
			
		||||
    void gotoLocation(const StackFrame &frame, bool setMarker);
 | 
			
		||||
    virtual void gotoLocation(const QString &fileName, int lineNumber, bool setMarker);
 | 
			
		||||
    virtual void gotoLocation(const StackFrame &frame, bool setMarker);
 | 
			
		||||
    virtual void quitDebugger(); // called by DebuggerRunControl
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 
 | 
			
		||||
@@ -156,6 +156,10 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu
 | 
			
		||||
        sp.qmlServerAddress = QLatin1String("127.0.0.1");
 | 
			
		||||
        sp.qmlServerPort = runConfiguration->qmlDebugServerPort();
 | 
			
		||||
 | 
			
		||||
        sp.projectDir = runConfiguration->target()->project()->projectDirectory();
 | 
			
		||||
        if (runConfiguration->target()->activeBuildConfiguration())
 | 
			
		||||
            sp.projectBuildDir = runConfiguration->target()->activeBuildConfiguration()->buildDirectory();
 | 
			
		||||
 | 
			
		||||
        sp.environment << QString(Constants::E_QML_DEBUG_SERVER_PORT)
 | 
			
		||||
                        + QLatin1Char('=') + QString::number(sp.qmlServerPort);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -126,6 +126,25 @@ void QmlEngine::pauseConnection()
 | 
			
		||||
    m_adapter->pauseConnection();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void QmlEngine::gotoLocation(const QString &fileName, int lineNumber, bool setMarker)
 | 
			
		||||
{
 | 
			
		||||
    QString processedFilename = fileName;
 | 
			
		||||
 | 
			
		||||
    if (isShadowBuildProject())
 | 
			
		||||
        processedFilename = fromShadowBuildFilename(fileName);
 | 
			
		||||
 | 
			
		||||
    DebuggerEngine::gotoLocation(processedFilename, lineNumber, setMarker);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void QmlEngine::gotoLocation(const StackFrame &frame, bool setMarker)
 | 
			
		||||
{
 | 
			
		||||
    StackFrame adjustedFrame = frame;
 | 
			
		||||
    if (isShadowBuildProject())
 | 
			
		||||
        adjustedFrame.file = fromShadowBuildFilename(frame.file);
 | 
			
		||||
 | 
			
		||||
    DebuggerEngine::gotoLocation(adjustedFrame, setMarker);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void QmlEngine::setupInferior()
 | 
			
		||||
{
 | 
			
		||||
    QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
 | 
			
		||||
@@ -380,7 +399,10 @@ void QmlEngine::attemptBreakpointSynchronization()
 | 
			
		||||
    QSet< QPair<QString, qint32> > breakList;
 | 
			
		||||
    for (int index = 0; index != handler->size(); ++index) {
 | 
			
		||||
        BreakpointData *data = handler->at(index);
 | 
			
		||||
        breakList << qMakePair(data->fileName, data->lineNumber.toInt());
 | 
			
		||||
        QString processedFilename = data->fileName;
 | 
			
		||||
        if (isShadowBuildProject())
 | 
			
		||||
            processedFilename = toShadowBuildFilename(data->fileName);
 | 
			
		||||
        breakList << qMakePair(processedFilename, data->lineNumber.toInt());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    {
 | 
			
		||||
@@ -677,6 +699,73 @@ void QmlEngine::executeDebuggerCommand(const QString& command)
 | 
			
		||||
    sendMessage(reply);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool QmlEngine::isShadowBuildProject() const
 | 
			
		||||
{
 | 
			
		||||
    if (!startParameters().projectBuildDir.isEmpty()
 | 
			
		||||
        && (startParameters().projectDir != startParameters().projectBuildDir))
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QmlEngine::qmlImportPath() const
 | 
			
		||||
{
 | 
			
		||||
    QString result;
 | 
			
		||||
    const QString qmlImportPathPrefix("QML_IMPORT_PATH=");
 | 
			
		||||
    QStringList env = startParameters().environment;
 | 
			
		||||
    foreach(const QString &envStr, env) {
 | 
			
		||||
        if (envStr.startsWith(qmlImportPathPrefix)) {
 | 
			
		||||
            result = envStr.mid(qmlImportPathPrefix.length());
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QmlEngine::toShadowBuildFilename(const QString &filename) const
 | 
			
		||||
{
 | 
			
		||||
    QString newFilename = filename;
 | 
			
		||||
    QString importPath = qmlImportPath();
 | 
			
		||||
 | 
			
		||||
    newFilename = mangleFilenamePaths(filename, startParameters().projectDir, startParameters().projectBuildDir);
 | 
			
		||||
    if (newFilename == filename && !importPath.isEmpty()) {
 | 
			
		||||
        newFilename = mangleFilenamePaths(filename, startParameters().projectDir, importPath);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return newFilename;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QmlEngine::mangleFilenamePaths(const QString &filename, const QString &oldBasePath, const QString &newBasePath) const
 | 
			
		||||
{
 | 
			
		||||
    QDir oldBaseDir(oldBasePath);
 | 
			
		||||
    QDir newBaseDir(newBasePath);
 | 
			
		||||
    QFileInfo fileInfo(filename);
 | 
			
		||||
 | 
			
		||||
    if (oldBaseDir.exists() && newBaseDir.exists() && fileInfo.exists()) {
 | 
			
		||||
        if (fileInfo.absoluteFilePath().startsWith(oldBaseDir.canonicalPath())) {
 | 
			
		||||
            QString fileRelativePath = fileInfo.canonicalFilePath().mid(oldBasePath.length());
 | 
			
		||||
            QFileInfo projectFile(newBaseDir.canonicalPath() + QLatin1Char('/') + fileRelativePath);
 | 
			
		||||
 | 
			
		||||
            if (projectFile.exists())
 | 
			
		||||
                return projectFile.canonicalFilePath();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return filename;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QmlEngine::fromShadowBuildFilename(const QString &filename) const
 | 
			
		||||
{
 | 
			
		||||
    QString newFilename = filename;
 | 
			
		||||
    QString importPath = qmlImportPath();
 | 
			
		||||
 | 
			
		||||
    newFilename = mangleFilenamePaths(filename, startParameters().projectBuildDir, startParameters().projectDir);
 | 
			
		||||
    if (newFilename == filename && !importPath.isEmpty()) {
 | 
			
		||||
        newFilename = mangleFilenamePaths(filename, startParameters().projectBuildDir, importPath);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return newFilename;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace Internal
 | 
			
		||||
} // namespace Debugger
 | 
			
		||||
 
 | 
			
		||||
@@ -67,6 +67,8 @@ public:
 | 
			
		||||
    void shutdownInferiorAsSlave();
 | 
			
		||||
    void shutdownEngineAsSlave();
 | 
			
		||||
    void pauseConnection();
 | 
			
		||||
    void gotoLocation(const QString &fileName, int lineNumber, bool setMarker);
 | 
			
		||||
    void gotoLocation(const StackFrame &frame, bool setMarker);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void messageReceived(const QByteArray &message);
 | 
			
		||||
@@ -130,6 +132,12 @@ private:
 | 
			
		||||
    void expandObject(const QByteArray &iname, quint64 objectId);
 | 
			
		||||
    void sendPing();
 | 
			
		||||
 | 
			
		||||
    bool isShadowBuildProject() const;
 | 
			
		||||
    QString fromShadowBuildFilename(const QString &filename) const;
 | 
			
		||||
    QString mangleFilenamePaths(const QString &filename, const QString &oldBasePath, const QString &newBasePath) const;
 | 
			
		||||
    QString toShadowBuildFilename(const QString &filename) const;
 | 
			
		||||
    QString qmlImportPath() const;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    friend class QmlCppEngine;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user