qnxruncontrolfactory.cpp 6.83 KB
Newer Older
Tobias Nätterlund's avatar
Tobias Nätterlund committed
1 2
/**************************************************************************
**
3
** Copyright (C) 2012 - 2014 BlackBerry Limited. All rights reserved.
Tobias Nätterlund's avatar
Tobias Nätterlund committed
4
**
5
** Contact: BlackBerry (qt@blackberry.com)
Tobias Nätterlund's avatar
Tobias Nätterlund committed
6 7
** Contact: KDAB (info@kdab.com)
**
hjk's avatar
hjk committed
8
** This file is part of Qt Creator.
Tobias Nätterlund's avatar
Tobias Nätterlund committed
9
**
hjk's avatar
hjk committed
10 11 12 13
** 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
14 15
** 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
16
** use the contact form at http://www.qt.io/contact-us.
Tobias Nätterlund's avatar
Tobias Nätterlund committed
17
**
hjk's avatar
hjk committed
18 19
** 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
20 21 22 23 24 25
** 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.
hjk's avatar
hjk committed
26
**
Eike Ziller's avatar
Eike Ziller committed
27 28
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
Tobias Nätterlund's avatar
Tobias Nätterlund committed
29 30
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
31
****************************************************************************/
Tobias Nätterlund's avatar
Tobias Nätterlund committed
32 33 34 35 36

#include "qnxruncontrolfactory.h"
#include "qnxconstants.h"
#include "qnxrunconfiguration.h"
#include "qnxdebugsupport.h"
37
#include "qnxanalyzesupport.h"
Tobias Nätterlund's avatar
Tobias Nätterlund committed
38 39 40 41 42
#include "qnxqtversion.h"
#include "qnxruncontrol.h"
#include "qnxutils.h"
#include "qnxdeviceconfiguration.h"

43
#include <debugger/debuggerruncontrol.h>
44
#include <debugger/debuggerrunconfigurationaspect.h>
Tobias Nätterlund's avatar
Tobias Nätterlund committed
45
#include <debugger/debuggerstartparameters.h>
Tobias Hunger's avatar
Tobias Hunger committed
46
#include <debugger/debuggerkitinformation.h>
47 48 49
#include <analyzerbase/analyzerstartparameters.h>
#include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerruncontrol.h>
50
#include <analyzerbase/ianalyzertool.h>
51
#include <projectexplorer/environmentaspect.h>
52 53
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/project.h>
Tobias Nätterlund's avatar
Tobias Nätterlund committed
54 55
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
Tobias Hunger's avatar
Tobias Hunger committed
56
#include <qtsupport/qtkitinformation.h>
Tobias Nätterlund's avatar
Tobias Nätterlund committed
57 58
#include <utils/portlist.h>

59
using namespace Analyzer;
60 61
using namespace Debugger;
using namespace ProjectExplorer;
Tobias Nätterlund's avatar
Tobias Nätterlund committed
62 63 64
using namespace Qnx;
using namespace Qnx::Internal;

65
static DebuggerStartParameters createDebuggerStartParameters(QnxRunConfiguration *runConfig)
Tobias Nätterlund's avatar
Tobias Nätterlund committed
66
{
67 68
    DebuggerStartParameters params;
    Target *target = runConfig->target();
Tobias Hunger's avatar
Tobias Hunger committed
69
    Kit *k = target->kit();
70

Tobias Hunger's avatar
Tobias Hunger committed
71
    const IDevice::ConstPtr device = DeviceKitInformation::device(k);
72
    if (device.isNull())
73 74 75
        return params;

    params.startMode = AttachToRemoteServer;
76
    params.useCtrlCStub = true;
77
    params.executable = runConfig->localExecutableFilePath();
78
    params.remoteExecutable = runConfig->remoteExecutableFilePath();
79
    params.remoteChannel = device->sshParameters().host + QLatin1String(":-1");
80
    params.remoteSetupNeeded = true;
81
    params.closeMode = KillAtClose;
hjk's avatar
hjk committed
82
    params.processArgs = runConfig->arguments().join(QLatin1Char(' '));
83

84
    auto aspect = runConfig->extraAspect<DebuggerRunConfigurationAspect>();
85 86 87 88 89
    if (aspect->useQmlDebugger()) {
        params.qmlServerAddress = device->sshParameters().host;
        params.qmlServerPort = 0; // QML port is handed out later
    }

90
    auto qtVersion = dynamic_cast<QnxQtVersion *>(QtSupport::QtKitInformation::qtVersion(k));
91 92 93 94
    if (qtVersion)
        params.solibSearchPath = QnxUtils::searchPaths(qtVersion);

    return params;
Tobias Nätterlund's avatar
Tobias Nätterlund committed
95 96
}

97
static AnalyzerStartParameters createAnalyzerStartParameters(const QnxRunConfiguration *runConfig)
98 99 100 101 102 103 104 105 106 107
{
    AnalyzerStartParameters params;
    Target *target = runConfig->target();
    Kit *k = target->kit();

    const IDevice::ConstPtr device = DeviceKitInformation::device(k);
    if (device.isNull())
        return params;

    params.debuggee = runConfig->remoteExecutableFilePath();
hjk's avatar
hjk committed
108
    params.debuggeeArgs = runConfig->arguments().join(QLatin1Char(' '));
109 110 111 112 113 114
    params.connParams = DeviceKitInformation::device(runConfig->target()->kit())->sshParameters();
    params.analyzerHost = params.connParams.host;
    params.analyzerPort = params.connParams.port;

    return params;
}
115 116 117

QnxRunControlFactory::QnxRunControlFactory(QObject *parent)
    : IRunControlFactory(parent)
Tobias Nätterlund's avatar
Tobias Nätterlund committed
118 119 120
{
}

121
bool QnxRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id mode) const
Tobias Nätterlund's avatar
Tobias Nätterlund committed
122
{
123 124 125
    if (mode != ProjectExplorer::Constants::NORMAL_RUN_MODE
            && mode != ProjectExplorer::Constants::DEBUG_RUN_MODE
            && mode != ProjectExplorer::Constants::QML_PROFILER_RUN_MODE) {
Tobias Nätterlund's avatar
Tobias Nätterlund committed
126
        return false;
127
    }
Tobias Nätterlund's avatar
Tobias Nätterlund committed
128 129

    if (!runConfiguration->isEnabled()
hjk's avatar
hjk committed
130
            || !runConfiguration->id().name().startsWith(Constants::QNX_QNX_RUNCONFIGURATION_PREFIX)) {
Tobias Nätterlund's avatar
Tobias Nätterlund committed
131 132 133 134
        return false;
    }

    const QnxRunConfiguration * const rc = qobject_cast<QnxRunConfiguration *>(runConfiguration);
135 136 137 138 139
    const QnxDeviceConfiguration::ConstPtr dev = DeviceKitInformation::device(runConfiguration->target()->kit())
            .dynamicCast<const QnxDeviceConfiguration>();
    if (dev.isNull())
        return false;

140
    if (mode == ProjectExplorer::Constants::DEBUG_RUN_MODE || mode == ProjectExplorer::Constants::QML_PROFILER_RUN_MODE)
Tobias Nätterlund's avatar
Tobias Nätterlund committed
141
        return rc->portsUsedByDebuggers() <= dev->freePorts().count();
142

Tobias Nätterlund's avatar
Tobias Nätterlund committed
143 144 145
    return true;
}

146
RunControl *QnxRunControlFactory::create(RunConfiguration *runConfig, Core::Id mode, QString *errorMessage)
Tobias Nätterlund's avatar
Tobias Nätterlund committed
147 148 149 150 151
{
    Q_ASSERT(canRun(runConfig, mode));

    QnxRunConfiguration *rc = qobject_cast<QnxRunConfiguration *>(runConfig);
    Q_ASSERT(rc);
152
    if (mode == ProjectExplorer::Constants::NORMAL_RUN_MODE)
Tobias Nätterlund's avatar
Tobias Nätterlund committed
153
        return new QnxRunControl(rc);
154 155

    if (mode == ProjectExplorer::Constants::DEBUG_RUN_MODE) {
156
        const DebuggerStartParameters params = createDebuggerStartParameters(rc);
157
        DebuggerRunControl *runControl = createDebuggerRunControl(params, runConfig, errorMessage);
158 159
        if (!runControl)
            return 0;
Tobias Nätterlund's avatar
Tobias Nätterlund committed
160

hjk's avatar
hjk committed
161
        QnxDebugSupport *debugSupport = new QnxDebugSupport(rc, runControl);
162
        connect(runControl, SIGNAL(finished()), debugSupport, SLOT(handleDebuggingFinished()));
Tobias Nätterlund's avatar
Tobias Nätterlund committed
163

164 165
        return runControl;
    }
166
    if (mode == ProjectExplorer::Constants::QML_PROFILER_RUN_MODE) {
167 168
        const AnalyzerStartParameters params = createAnalyzerStartParameters(rc);
        AnalyzerRunControl *runControl = AnalyzerManager::createRunControl(params, runConfig, mode);
169
        QnxAnalyzeSupport * const analyzeSupport = new QnxAnalyzeSupport(rc, runControl);
170 171 172
        connect(runControl, SIGNAL(finished()), analyzeSupport, SLOT(handleProfilingFinished()));
        return runControl;
    }
173 174

    QTC_CHECK(false);
175
    return 0;
Tobias Nätterlund's avatar
Tobias Nätterlund committed
176
}