iosanalyzesupport.cpp 6.12 KB
Newer Older
Fawzi Mohamed's avatar
Fawzi Mohamed committed
1 2
/****************************************************************************
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
Fawzi Mohamed's avatar
Fawzi Mohamed committed
5 6 7 8 9 10 11
**
** This file is part of Qt Creator.
**
** 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
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
Fawzi Mohamed's avatar
Fawzi Mohamed committed
15 16 17
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
Fawzi Mohamed's avatar
Fawzi Mohamed committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
Fawzi Mohamed's avatar
Fawzi Mohamed committed
27 28 29 30 31 32 33 34 35 36 37 38
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "iosanalyzesupport.h"

#include "iosrunner.h"
#include "iosmanager.h"
#include "iosdevice.h"

#include <debugger/debuggerplugin.h>
#include <debugger/debuggerkitinformation.h>
39
#include <debugger/debuggerruncontrol.h>
Fawzi Mohamed's avatar
Fawzi Mohamed committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#include <debugger/debuggerstartparameters.h>
#include <debugger/debuggerrunconfigurationaspect.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/target.h>
#include <projectexplorer/taskhub.h>
#include <qmakeprojectmanager/qmakebuildconfiguration.h>
#include <qmakeprojectmanager/qmakenodes.h>
#include <qmakeprojectmanager/qmakeproject.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/fileutils.h>
#include <analyzerbase/ianalyzertool.h>
#include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerruncontrol.h>
#include <analyzerbase/analyzerstartparameters.h>
#include <utils/outputformat.h>
#include <utils/qtcprocess.h>

#include <QDir>
#include <QTcpServer>
#include <QSettings>

#include <stdio.h>
#include <fcntl.h>
#ifdef Q_OS_UNIX
#include <unistd.h>
#else
#include <io.h>
#endif

using namespace Analyzer;
using namespace ProjectExplorer;
using namespace QmakeProjectManager;

namespace Ios {
namespace Internal {

RunControl *IosAnalyzeSupport::createAnalyzeRunControl(IosRunConfiguration *runConfig,
                                                       QString *errorMessage)
{
    Q_UNUSED(errorMessage);
    Target *target = runConfig->target();
    if (!target)
        return 0;
83
    IDevice::ConstPtr device = DeviceKitInformation::device(target->kit());
Fawzi Mohamed's avatar
Fawzi Mohamed committed
84 85 86
    if (device.isNull())
        return 0;
    AnalyzerStartParameters params;
87
    params.runMode = ProjectExplorer::Constants::QML_PROFILER_RUN_MODE;
Fawzi Mohamed's avatar
Fawzi Mohamed committed
88
    params.sysroot = SysRootKitInformation::sysRoot(target->kit()).toString();
89
    params.debuggee = runConfig->localExecutable().toUserOutput();
Fawzi Mohamed's avatar
Fawzi Mohamed committed
90 91 92 93 94 95 96
    params.debuggeeArgs = Utils::QtcProcess::joinArgs(runConfig->commandLineArguments());
    params.analyzerHost = QLatin1String("localhost");
    if (device->type() == Core::Id(Ios::Constants::IOS_DEVICE_TYPE)) {
        IosDevice::ConstPtr iosDevice = device.dynamicCast<const IosDevice>();
        if (iosDevice.isNull())
                return 0;
    }
97
    params.displayName = runConfig->applicationName();
Fawzi Mohamed's avatar
Fawzi Mohamed committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

    AnalyzerRunControl *analyzerRunControl = AnalyzerManager::createRunControl(params, runConfig);
    (void) new IosAnalyzeSupport(runConfig, analyzerRunControl, false, true);
    return analyzerRunControl;
}

IosAnalyzeSupport::IosAnalyzeSupport(IosRunConfiguration *runConfig,
    AnalyzerRunControl *runControl, bool cppDebug, bool qmlDebug)
    : QObject(runControl), m_runControl(runControl),
      m_runner(new IosRunner(this, runConfig, cppDebug, qmlDebug))
{
    connect(m_runControl, SIGNAL(starting(const Analyzer::AnalyzerRunControl*)),
            m_runner, SLOT(start()));
    connect(m_runControl, SIGNAL(finished()),
            m_runner, SLOT(stop()));
    connect(&m_outputParser, SIGNAL(waitingForConnectionOnPort(quint16)),
            SLOT(qmlServerReady()));

    connect(m_runner, SIGNAL(gotServerPorts(int,int)),
        SLOT(handleServerPorts(int,int)));
Robert Loehning's avatar
Robert Loehning committed
118 119
    connect(m_runner, SIGNAL(gotInferiorPid(Q_PID,int)),
        SLOT(handleGotInferiorPid(Q_PID,int)));
Fawzi Mohamed's avatar
Fawzi Mohamed committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    connect(m_runner, SIGNAL(finished(bool)),
        SLOT(handleRemoteProcessFinished(bool)));

    connect(m_runner, SIGNAL(errorMsg(QString)),
        SLOT(handleRemoteErrorOutput(QString)));
    connect(m_runner, SIGNAL(appOutput(QString)),
        SLOT(handleRemoteOutput(QString)));
}

IosAnalyzeSupport::~IosAnalyzeSupport()
{
}

void IosAnalyzeSupport::qmlServerReady()
{
    m_runControl->notifyRemoteSetupDone(m_qmlPort);
}

void IosAnalyzeSupport::handleServerPorts(int gdbServerPort, int qmlPort)
{
    Q_UNUSED(gdbServerPort);
    m_qmlPort = qmlPort;
}

void IosAnalyzeSupport::handleGotInferiorPid(Q_PID pid, int qmlPort)
{
    Q_UNUSED(pid);
    m_qmlPort = qmlPort;
}

void IosAnalyzeSupport::handleRemoteProcessFinished(bool cleanEnd)
{
    if (m_runControl) {
153 154 155 156
        if (!cleanEnd)
            m_runControl->logApplicationMessage(tr("Run ended with error."), Utils::ErrorMessageFormat);
        else
            m_runControl->logApplicationMessage(tr("Run ended."), Utils::NormalMessageFormat);
Fawzi Mohamed's avatar
Fawzi Mohamed committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
        m_runControl->notifyRemoteFinished();
    }
}

void IosAnalyzeSupport::handleRemoteOutput(const QString &output)
{
    if (m_runControl) {
        m_runControl->logApplicationMessage(output, Utils::StdOutFormat);
        m_outputParser.processOutput(output);
    }
}

void IosAnalyzeSupport::handleRemoteErrorOutput(const QString &output)
{
    if (m_runControl)
        m_runControl->logApplicationMessage(output, Utils::StdErrFormat);
}

} // namespace Internal
} // namespace Ios