2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
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
|
|
|
|
2013-03-27 13:03:15 +01:00
|
|
|
#include <debugger/debuggerrunconfigurationaspect.h>
|
2014-12-12 15:33:16 +01:00
|
|
|
#include <debugger/debuggerruncontrol.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>
|
2014-12-12 15:33:16 +01:00
|
|
|
|
2012-07-25 17:41:01 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2016-01-26 15:53:26 +01:00
|
|
|
#include <projectexplorer/devicesupport/deviceapplicationrunner.h>
|
2011-06-27 10:11:17 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2016-01-26 15:53:26 +01:00
|
|
|
#include <projectexplorer/runnables.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>
|
2016-01-06 16:50:36 +01:00
|
|
|
|
2015-08-10 17:43:58 +02:00
|
|
|
#include <qmldebug/qmldebugcommandlinearguments.h>
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2016-01-26 15:53:26 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
|
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;
|
2016-01-26 15:53:26 +01:00
|
|
|
using namespace Utils;
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
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:
|
2016-01-26 15:53:26 +01:00
|
|
|
LinuxDeviceDebugSupportPrivate(const RunConfiguration *runConfig, DebuggerRunControl *runControl)
|
2014-12-12 15:33:16 +01:00
|
|
|
: runControl(runControl),
|
2015-02-03 23:51:02 +02:00
|
|
|
qmlDebugging(runConfig->extraAspect<DebuggerRunConfigurationAspect>()->useQmlDebugger()),
|
|
|
|
|
cppDebugging(runConfig->extraAspect<DebuggerRunConfigurationAspect>()->useCppDebugger()),
|
2013-05-06 09:10:22 +02:00
|
|
|
gdbServerPort(-1), qmlPort(-1)
|
2011-08-02 12:20:16 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-12 15:33:16 +01:00
|
|
|
const QPointer<DebuggerRunControl> runControl;
|
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;
|
|
|
|
|
|
2016-01-26 15:53:26 +01:00
|
|
|
LinuxDeviceDebugSupport::LinuxDeviceDebugSupport(RunConfiguration *runConfig,
|
2014-12-12 15:33:16 +01:00
|
|
|
DebuggerRunControl *runControl)
|
|
|
|
|
: AbstractRemoteLinuxRunSupport(runConfig, runControl),
|
2016-01-26 15:53:26 +01:00
|
|
|
d(new LinuxDeviceDebugSupportPrivate(runConfig, runControl))
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2014-12-12 15:33:16 +01:00
|
|
|
connect(runControl, &DebuggerRunControl::requestRemoteSetup,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::handleRemoteSetupRequested);
|
2016-01-26 15:53:26 +01:00
|
|
|
connect(runControl, &RunControl::finished,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::handleDebuggingFinished);
|
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)
|
|
|
|
|
{
|
2014-12-12 15:33:16 +01:00
|
|
|
if (state() != Inactive && d->runControl)
|
|
|
|
|
d->runControl->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
|
|
|
|
2013-10-17 13:48:04 +02:00
|
|
|
showMessage(tr("Checking available ports...") + QLatin1Char('\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();
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(runner, &DeviceApplicationRunner::remoteStderr,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::handleRemoteErrorOutput);
|
|
|
|
|
connect(runner, &DeviceApplicationRunner::remoteStdout,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::handleRemoteOutput);
|
2012-07-26 09:02:34 +02:00
|
|
|
if (d->qmlDebugging && !d->cppDebugging)
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(runner, &DeviceApplicationRunner::remoteProcessStarted,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::handleRemoteProcessStarted);
|
2013-06-28 13:56:42 +02:00
|
|
|
|
2016-01-26 15:53:26 +01:00
|
|
|
QStringList args = QtcProcess::splitArgs(runnable().commandLineArguments, OsTypeLinux);
|
2013-06-28 13:56:42 +02:00
|
|
|
QString command;
|
2014-02-27 14:03:25 +01:00
|
|
|
|
|
|
|
|
if (d->qmlDebugging)
|
2015-11-17 16:40:27 +01:00
|
|
|
args.prepend(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices, d->qmlPort));
|
2014-02-27 14:03:25 +01:00
|
|
|
|
2013-08-08 14:05:11 +02:00
|
|
|
if (d->qmlDebugging && !d->cppDebugging) {
|
2016-01-26 15:53:26 +01:00
|
|
|
command = runnable().executable;
|
2013-08-08 14:05:11 +02:00
|
|
|
} else {
|
2013-06-28 13:56:42 +02:00
|
|
|
command = device()->debugServerPath();
|
|
|
|
|
if (command.isEmpty())
|
|
|
|
|
command = QLatin1String("gdbserver");
|
2014-07-23 17:25:41 +02:00
|
|
|
args.clear();
|
|
|
|
|
args.append(QString::fromLatin1("--multi"));
|
|
|
|
|
args.append(QString::fromLatin1(":%1").arg(d->gdbServerPort));
|
2013-08-08 14:05:11 +02:00
|
|
|
}
|
2013-06-28 13:56:42 +02:00
|
|
|
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(runner, &DeviceApplicationRunner::finished,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::handleAppRunnerFinished);
|
|
|
|
|
connect(runner, &DeviceApplicationRunner::reportProgress,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::handleProgressReport);
|
|
|
|
|
connect(runner, &DeviceApplicationRunner::reportError,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::handleAppRunnerError);
|
2016-01-26 15:53:26 +01:00
|
|
|
runner->setEnvironment(runnable().environment);
|
|
|
|
|
runner->setWorkingDirectory(runnable().workingDirectory);
|
2013-08-08 14:05:11 +02:00
|
|
|
runner->start(device(), command, args);
|
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);
|
2014-12-12 15:33:16 +01:00
|
|
|
if (d->runControl)
|
|
|
|
|
d->runControl->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
|
|
|
{
|
2014-12-12 15:33:16 +01:00
|
|
|
if (!d->runControl || 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)
|
2014-12-12 15:33:16 +01:00
|
|
|
d->runControl->quitDebugger();
|
2012-07-26 09:02:34 +02:00
|
|
|
else if (!success)
|
2014-12-12 15:33:16 +01:00
|
|
|
d->runControl->notifyInferiorIll();
|
2011-07-05 16:15:05 +02:00
|
|
|
|
2014-09-18 19:21:27 +02:00
|
|
|
} else if (state() == StartingRunner) {
|
|
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.success = false;
|
|
|
|
|
result.reason = tr("Debugging failed.");
|
2014-12-12 15:33:16 +01:00
|
|
|
d->runControl->notifyEngineRemoteSetupFinished(result);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
2013-07-19 10:15:47 +02:00
|
|
|
reset();
|
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();
|
2013-07-19 10:15:47 +02:00
|
|
|
reset();
|
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
|
|
|
|
2014-12-12 15:33:16 +01:00
|
|
|
if (!d->runControl)
|
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);
|
2014-09-18 19:21:27 +02:00
|
|
|
|
|
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.success = false;
|
|
|
|
|
result.reason = tr("Initial setup failed: %1").arg(error);
|
2014-12-12 15:33:16 +01:00
|
|
|
d->runControl->notifyEngineRemoteSetupFinished(result);
|
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();
|
2014-09-18 19:21:27 +02:00
|
|
|
|
|
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.success = true;
|
|
|
|
|
result.gdbServerPort = d->gdbServerPort;
|
|
|
|
|
result.qmlServerPort = d->qmlPort;
|
2014-12-12 15:33:16 +01:00
|
|
|
d->runControl->notifyEngineRemoteSetupFinished(result);
|
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
|