2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2011-06-16 17:03:43 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-07-25 17:41:01 +02:00
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
#include "remotelinuxdebugsupport.h"
|
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
#include "remotelinuxrunconfiguration.h"
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
#include <debugger/debuggerengine.h>
|
2013-03-27 13:03:15 +01:00
|
|
|
#include <debugger/debuggerrunconfigurationaspect.h>
|
2011-08-02 12:20:16 +02:00
|
|
|
#include <debugger/debuggerstartparameters.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <debugger/debuggerkitinformation.h>
|
2012-07-25 17:41:01 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2011-06-27 10:11:17 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2011-07-27 18:04:43 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2011-06-16 17:03:43 +02:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2012-07-26 09:02:34 +02:00
|
|
|
#include <projectexplorer/devicesupport/deviceapplicationrunner.h>
|
2013-05-06 09:10:22 +02:00
|
|
|
|
2011-07-20 11:50:01 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPointer>
|
2011-08-02 12:20:16 +02:00
|
|
|
|
2012-05-18 10:49:35 +02:00
|
|
|
using namespace QSsh;
|
2011-06-16 17:03:43 +02:00
|
|
|
using namespace Debugger;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
2011-08-02 12:20:16 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
class LinuxDeviceDebugSupportPrivate
|
2011-08-02 12:20:16 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2012-07-26 09:02:34 +02:00
|
|
|
LinuxDeviceDebugSupportPrivate(const RemoteLinuxRunConfiguration *runConfig,
|
2011-08-02 12:20:16 +02:00
|
|
|
DebuggerEngine *engine)
|
2012-06-05 15:36:38 +02:00
|
|
|
: engine(engine),
|
2013-03-27 13:03:15 +01:00
|
|
|
qmlDebugging(runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>()->useQmlDebugger()),
|
|
|
|
|
cppDebugging(runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>()->useCppDebugger()),
|
2013-05-06 09:10:22 +02:00
|
|
|
gdbServerPort(-1), qmlPort(-1)
|
2011-08-02 12:20:16 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-27 15:58:47 +02:00
|
|
|
const QPointer<DebuggerEngine> engine;
|
2011-11-11 02:52:34 +01:00
|
|
|
bool qmlDebugging;
|
|
|
|
|
bool cppDebugging;
|
2011-08-02 12:20:16 +02:00
|
|
|
QByteArray gdbserverOutput;
|
|
|
|
|
int gdbServerPort;
|
|
|
|
|
int qmlPort;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
using namespace Internal;
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
DebuggerStartParameters LinuxDeviceDebugSupport::startParameters(const RemoteLinuxRunConfiguration *runConfig)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
|
|
|
|
DebuggerStartParameters params;
|
2012-06-28 10:00:04 +02:00
|
|
|
Target *target = runConfig->target();
|
2012-09-03 18:31:44 +02:00
|
|
|
Kit *k = target->kit();
|
|
|
|
|
const IDevice::ConstPtr device = DeviceKitInformation::device(k);
|
2013-03-28 13:45:15 +01:00
|
|
|
QTC_ASSERT(device, return params);
|
2012-06-28 10:00:04 +02:00
|
|
|
|
2012-09-03 18:31:44 +02:00
|
|
|
params.sysRoot = SysRootKitInformation::sysRoot(k).toString();
|
|
|
|
|
params.debuggerCommand = DebuggerKitInformation::debuggerCommand(k).toString();
|
|
|
|
|
if (ToolChain *tc = ToolChainKitInformation::toolChain(k))
|
2012-06-28 10:00:04 +02:00
|
|
|
params.toolChainAbi = tc->targetAbi();
|
|
|
|
|
|
2013-03-27 13:03:15 +01:00
|
|
|
Debugger::DebuggerRunConfigurationAspect *aspect
|
|
|
|
|
= runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>();
|
2013-03-26 17:03:57 +01:00
|
|
|
if (aspect->useQmlDebugger()) {
|
2012-02-01 09:03:05 +01:00
|
|
|
params.languages |= QmlLanguage;
|
2012-07-27 13:31:13 +02:00
|
|
|
params.qmlServerAddress = device->sshParameters().host;
|
2012-02-21 15:47:55 +01:00
|
|
|
params.qmlServerPort = 0; // port is selected later on
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
2013-03-26 17:03:57 +01:00
|
|
|
if (aspect->useCppDebugger()) {
|
2012-02-01 09:03:05 +01:00
|
|
|
params.languages |= CppLanguage;
|
2011-06-16 17:03:43 +02:00
|
|
|
params.processArgs = runConfig->arguments();
|
2011-09-16 11:04:11 +02:00
|
|
|
params.startMode = AttachToRemoteServer;
|
2011-06-16 17:03:43 +02:00
|
|
|
params.executable = runConfig->localExecutableFilePath();
|
2012-07-27 13:31:13 +02:00
|
|
|
params.remoteChannel = device->sshParameters().host + QLatin1String(":-1");
|
2011-06-16 17:03:43 +02:00
|
|
|
} else {
|
2011-09-16 11:04:11 +02:00
|
|
|
params.startMode = AttachToRemoteServer;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
2012-06-13 11:29:26 +02:00
|
|
|
params.remoteSetupNeeded = true;
|
2011-06-16 17:03:43 +02:00
|
|
|
params.displayName = runConfig->displayName();
|
|
|
|
|
|
2012-06-28 10:00:04 +02:00
|
|
|
if (const Project *project = target->project()) {
|
2011-06-16 17:03:43 +02:00
|
|
|
params.projectSourceDirectory = project->projectDirectory();
|
2012-06-28 10:00:04 +02:00
|
|
|
if (const BuildConfiguration *buildConfig = target->activeBuildConfiguration())
|
2011-06-16 17:03:43 +02:00
|
|
|
params.projectBuildDirectory = buildConfig->buildDirectory();
|
|
|
|
|
params.projectSourceFiles = project->files(Project::ExcludeGeneratedFiles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return params;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 09:10:22 +02:00
|
|
|
LinuxDeviceDebugSupport::LinuxDeviceDebugSupport(RemoteLinuxRunConfiguration *runConfig,
|
2011-08-02 12:20:16 +02:00
|
|
|
DebuggerEngine *engine)
|
2013-05-07 14:35:02 +02:00
|
|
|
: AbstractRemoteLinuxRunSupport(runConfig, engine),
|
2012-07-26 09:02:34 +02:00
|
|
|
d(new LinuxDeviceDebugSupportPrivate(static_cast<RemoteLinuxRunConfiguration *>(runConfig), engine))
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2012-06-13 11:29:26 +02:00
|
|
|
connect(d->engine, SIGNAL(requestRemoteSetup()), this, SLOT(handleRemoteSetupRequested()));
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
LinuxDeviceDebugSupport::~LinuxDeviceDebugSupport()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
delete d;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::showMessage(const QString &msg, int channel)
|
|
|
|
|
{
|
2013-05-06 09:10:22 +02:00
|
|
|
if (state() != Inactive && d->engine)
|
2011-09-15 09:10:10 +02:00
|
|
|
d->engine->showMessage(msg, channel);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::handleRemoteSetupRequested()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2013-05-06 09:10:22 +02:00
|
|
|
QTC_ASSERT(state() == Inactive, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
showMessage(tr("Checking available ports...\n"), LogStatus);
|
2013-05-07 14:35:02 +02:00
|
|
|
AbstractRemoteLinuxRunSupport::handleRemoteSetupRequested();
|
2012-07-26 09:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LinuxDeviceDebugSupport::startExecution()
|
|
|
|
|
{
|
2013-05-06 09:10:22 +02:00
|
|
|
QTC_ASSERT(state() == GatheringPorts, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-11-11 02:52:34 +01:00
|
|
|
if (d->cppDebugging && !setPort(d->gdbServerPort))
|
|
|
|
|
return;
|
|
|
|
|
if (d->qmlDebugging && !setPort(d->qmlPort))
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2013-05-06 09:10:22 +02:00
|
|
|
setState(StartingRunner);
|
2011-09-15 09:10:10 +02:00
|
|
|
d->gdbserverOutput.clear();
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2013-05-06 09:10:22 +02:00
|
|
|
DeviceApplicationRunner *runner = appRunner();
|
|
|
|
|
connect(runner, SIGNAL(remoteStderr(QByteArray)), SLOT(handleRemoteErrorOutput(QByteArray)));
|
|
|
|
|
connect(runner, SIGNAL(remoteStdout(QByteArray)), SLOT(handleRemoteOutput(QByteArray)));
|
2012-07-26 09:02:34 +02:00
|
|
|
if (d->qmlDebugging && !d->cppDebugging)
|
2013-05-06 09:10:22 +02:00
|
|
|
connect(runner, SIGNAL(remoteProcessStarted()), SLOT(handleRemoteProcessStarted()));
|
|
|
|
|
QString args = arguments();
|
2012-07-26 09:02:34 +02:00
|
|
|
if (d->qmlDebugging)
|
|
|
|
|
args += QString::fromLocal8Bit(" -qmljsdebugger=port:%1,block").arg(d->qmlPort);
|
2011-11-11 02:52:34 +01:00
|
|
|
const QString remoteCommandLine = (d->qmlDebugging && !d->cppDebugging)
|
2013-05-06 09:10:22 +02:00
|
|
|
? QString::fromLatin1("%1 %2 %3").arg(commandPrefix()).arg(remoteFilePath()).arg(args)
|
|
|
|
|
: QString::fromLatin1("%1 gdbserver :%2 %3 %4").arg(commandPrefix())
|
|
|
|
|
.arg(d->gdbServerPort).arg(remoteFilePath()).arg(args);
|
|
|
|
|
connect(runner, SIGNAL(finished(bool)), SLOT(handleAppRunnerFinished(bool)));
|
|
|
|
|
connect(runner, SIGNAL(reportProgress(QString)), SLOT(handleProgressReport(QString)));
|
|
|
|
|
connect(runner, SIGNAL(reportError(QString)), SLOT(handleAppRunnerError(QString)));
|
|
|
|
|
runner->start(device(), remoteCommandLine.toUtf8());
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::handleAppRunnerError(const QString &error)
|
|
|
|
|
{
|
2013-05-06 09:10:22 +02:00
|
|
|
if (state() == Running) {
|
2012-07-26 09:02:34 +02:00
|
|
|
showMessage(error, AppError);
|
|
|
|
|
if (d->engine)
|
|
|
|
|
d->engine->notifyInferiorIll();
|
2013-05-06 09:10:22 +02:00
|
|
|
} else if (state() != Inactive) {
|
2012-07-26 09:02:34 +02:00
|
|
|
handleAdapterSetupFailed(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LinuxDeviceDebugSupport::handleAppRunnerFinished(bool success)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2013-05-06 09:10:22 +02:00
|
|
|
if (!d->engine || state() == Inactive)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2013-05-06 09:10:22 +02:00
|
|
|
if (state() == Running) {
|
2011-07-05 16:15:05 +02:00
|
|
|
// The QML engine does not realize on its own that the application has finished.
|
2011-11-11 02:52:34 +01:00
|
|
|
if (d->qmlDebugging && !d->cppDebugging)
|
2011-09-15 09:10:10 +02:00
|
|
|
d->engine->quitDebugger();
|
2012-07-26 09:02:34 +02:00
|
|
|
else if (!success)
|
2011-09-15 09:10:10 +02:00
|
|
|
d->engine->notifyInferiorIll();
|
2011-07-05 16:15:05 +02:00
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
} else {
|
2012-07-26 09:02:34 +02:00
|
|
|
d->engine->notifyEngineRemoteSetupFailed(tr("Debugging failed."));
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::handleDebuggingFinished()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-08-02 12:20:16 +02:00
|
|
|
setFinished();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::handleRemoteOutput(const QByteArray &output)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2013-05-06 09:10:22 +02:00
|
|
|
QTC_ASSERT(state() == Inactive || state() == Running, return);
|
2011-07-20 11:50:01 +02:00
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
showMessage(QString::fromUtf8(output), AppOutput);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::handleRemoteErrorOutput(const QByteArray &output)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2013-05-06 09:10:22 +02:00
|
|
|
QTC_ASSERT(state() != GatheringPorts, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
if (!d->engine)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
showMessage(QString::fromUtf8(output), AppError);
|
2013-05-06 09:10:22 +02:00
|
|
|
if (state() == StartingRunner && d->cppDebugging) {
|
2011-09-15 09:10:10 +02:00
|
|
|
d->gdbserverOutput += output;
|
|
|
|
|
if (d->gdbserverOutput.contains("Listening on port")) {
|
2011-06-16 17:03:43 +02:00
|
|
|
handleAdapterSetupDone();
|
2011-09-15 09:10:10 +02:00
|
|
|
d->gdbserverOutput.clear();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::handleProgressReport(const QString &progressOutput)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2012-07-26 09:02:34 +02:00
|
|
|
showMessage(progressOutput + QLatin1Char('\n'), LogStatus);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::handleAdapterSetupFailed(const QString &error)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2013-05-07 14:35:02 +02:00
|
|
|
AbstractRemoteLinuxRunSupport::handleAdapterSetupFailed(error);
|
2012-06-13 11:29:26 +02:00
|
|
|
d->engine->notifyEngineRemoteSetupFailed(tr("Initial setup failed: %1").arg(error));
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::handleAdapterSetupDone()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2013-05-07 14:35:02 +02:00
|
|
|
AbstractRemoteLinuxRunSupport::handleAdapterSetupDone();
|
2012-06-13 11:29:26 +02:00
|
|
|
d->engine->notifyEngineRemoteSetupDone(d->gdbServerPort, d->qmlPort);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::handleRemoteProcessStarted()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2012-07-26 09:02:34 +02:00
|
|
|
QTC_ASSERT(d->qmlDebugging && !d->cppDebugging, return);
|
2013-05-06 09:10:22 +02:00
|
|
|
QTC_ASSERT(state() == StartingRunner, return);
|
2011-07-20 11:50:01 +02:00
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
handleAdapterSetupDone();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|