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>
|
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:
|
2017-03-28 09:07:29 +02:00
|
|
|
LinuxDeviceDebugSupportPrivate(const RunConfiguration *runConfig)
|
|
|
|
|
: qmlDebugging(runConfig->extraAspect<DebuggerRunConfigurationAspect>()->useQmlDebugger()),
|
2016-04-19 16:43:30 +02:00
|
|
|
cppDebugging(runConfig->extraAspect<DebuggerRunConfigurationAspect>()->useCppDebugger())
|
2011-08-02 12:20:16 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-11 02:52:34 +01:00
|
|
|
bool qmlDebugging;
|
|
|
|
|
bool cppDebugging;
|
2011-08-02 12:20:16 +02:00
|
|
|
QByteArray gdbserverOutput;
|
2016-04-19 16:43:30 +02:00
|
|
|
Port gdbServerPort;
|
|
|
|
|
Port qmlPort;
|
2011-08-02 12:20:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
using namespace Internal;
|
|
|
|
|
|
2017-04-21 11:39:01 +02:00
|
|
|
LinuxDeviceDebugSupport::LinuxDeviceDebugSupport(RunControl *runControl,
|
|
|
|
|
const Debugger::DebuggerStartParameters &sp,
|
|
|
|
|
QString *errorMessage)
|
|
|
|
|
: DebuggerRunTool(runControl, sp, errorMessage),
|
2017-03-28 09:07:29 +02:00
|
|
|
d(new LinuxDeviceDebugSupportPrivate(runControl->runConfiguration()))
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2017-04-26 14:23:39 +02:00
|
|
|
connect(this, &DebuggerRunTool::requestRemoteSetup,
|
2014-12-12 15:33:16 +01:00
|
|
|
this, &LinuxDeviceDebugSupport::handleRemoteSetupRequested);
|
2016-01-26 15:53:26 +01:00
|
|
|
connect(runControl, &RunControl::finished,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::handleDebuggingFinished);
|
2017-04-21 11:39:01 +02:00
|
|
|
|
|
|
|
|
connect(qobject_cast<AbstractRemoteLinuxRunSupport *>(runControl->targetRunner()),
|
|
|
|
|
&AbstractRemoteLinuxRunSupport::executionStartRequested,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::startExecution);
|
|
|
|
|
connect(qobject_cast<AbstractRemoteLinuxRunSupport *>(runControl->targetRunner()),
|
|
|
|
|
&AbstractRemoteLinuxRunSupport::adapterSetupFailed,
|
|
|
|
|
this, &LinuxDeviceDebugSupport::handleAdapterSetupFailed);
|
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
|
|
|
}
|
|
|
|
|
|
2017-03-24 11:26:33 +01:00
|
|
|
bool LinuxDeviceDebugSupport::isCppDebugging() const
|
|
|
|
|
{
|
|
|
|
|
return d->cppDebugging;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LinuxDeviceDebugSupport::isQmlDebugging() const
|
|
|
|
|
{
|
|
|
|
|
return d->qmlDebugging;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::showMessage(const QString &msg, int channel)
|
|
|
|
|
{
|
2017-04-21 11:39:01 +02:00
|
|
|
if (state() != AbstractRemoteLinuxRunSupport::Inactive)
|
2017-04-21 17:20:57 +02:00
|
|
|
runControl()->toolRunner()->showMessage(msg, channel);
|
2017-03-28 09:07:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-21 11:39:01 +02:00
|
|
|
AbstractRemoteLinuxRunSupport *LinuxDeviceDebugSupport::targetRunner() const
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<AbstractRemoteLinuxRunSupport *>(runControl()->targetRunner());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractRemoteLinuxRunSupport::State LinuxDeviceDebugSupport::state() const
|
|
|
|
|
{
|
|
|
|
|
AbstractRemoteLinuxRunSupport *runner = targetRunner();
|
|
|
|
|
return runner ? runner->state() : AbstractRemoteLinuxRunSupport::Inactive;
|
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
|
|
|
{
|
2017-04-21 11:39:01 +02:00
|
|
|
QTC_ASSERT(state() == AbstractRemoteLinuxRunSupport::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);
|
2017-04-21 11:39:01 +02:00
|
|
|
targetRunner()->startPortsGathering();
|
2012-07-26 09:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LinuxDeviceDebugSupport::startExecution()
|
|
|
|
|
{
|
2017-04-21 11:39:01 +02:00
|
|
|
QTC_ASSERT(state() == AbstractRemoteLinuxRunSupport::GatheringResources, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2016-04-20 12:03:58 +02:00
|
|
|
if (d->cppDebugging) {
|
2017-04-21 11:39:01 +02:00
|
|
|
d->gdbServerPort = targetRunner()->findPort();
|
2016-04-20 12:03:58 +02:00
|
|
|
if (!d->gdbServerPort.isValid()) {
|
|
|
|
|
handleAdapterSetupFailed(tr("Not enough free ports on device for C++ debugging."));
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
2016-04-20 12:03:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (d->qmlDebugging) {
|
2017-04-21 11:39:01 +02:00
|
|
|
d->qmlPort = targetRunner()->findPort();
|
2016-04-20 12:03:58 +02:00
|
|
|
if (!d->qmlPort.isValid()) {
|
|
|
|
|
handleAdapterSetupFailed(tr("Not enough free ports on device for QML debugging."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2017-04-21 11:39:01 +02:00
|
|
|
targetRunner()->setState(AbstractRemoteLinuxRunSupport::StartingRunner);
|
2011-09-15 09:10:10 +02:00
|
|
|
d->gdbserverOutput.clear();
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2017-04-21 11:39:01 +02:00
|
|
|
ApplicationLauncher *launcher = targetRunner()->applicationLauncher();
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(launcher, &ApplicationLauncher::remoteStderr,
|
2015-01-30 11:02:24 +01:00
|
|
|
this, &LinuxDeviceDebugSupport::handleRemoteErrorOutput);
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(launcher, &ApplicationLauncher::remoteStdout,
|
2015-01-30 11:02:24 +01:00
|
|
|
this, &LinuxDeviceDebugSupport::handleRemoteOutput);
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(launcher, &ApplicationLauncher::finished,
|
2016-01-27 18:25:13 +01:00
|
|
|
this, &LinuxDeviceDebugSupport::handleAppRunnerFinished);
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(launcher, &ApplicationLauncher::reportProgress,
|
2016-01-27 18:25:13 +01:00
|
|
|
this, &LinuxDeviceDebugSupport::handleProgressReport);
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(launcher, &ApplicationLauncher::reportError,
|
2016-01-27 18:25:13 +01:00
|
|
|
this, &LinuxDeviceDebugSupport::handleAppRunnerError);
|
2012-07-26 09:02:34 +02:00
|
|
|
if (d->qmlDebugging && !d->cppDebugging)
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(launcher, &ApplicationLauncher::remoteProcessStarted,
|
2015-01-30 11:02:24 +01:00
|
|
|
this, &LinuxDeviceDebugSupport::handleRemoteProcessStarted);
|
2013-06-28 13:56:42 +02:00
|
|
|
|
2017-03-24 11:26:33 +01:00
|
|
|
launcher->start(realRunnable(), device());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Runnable LinuxDeviceDebugSupport::realRunnable() const
|
|
|
|
|
{
|
2017-04-06 11:26:35 +02:00
|
|
|
StandardRunnable r = runControl()->runnable().as<StandardRunnable>();
|
2016-01-27 18:25:13 +01:00
|
|
|
QStringList args = QtcProcess::splitArgs(r.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-27 18:25:13 +01:00
|
|
|
command = r.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"));
|
2016-04-19 16:43:30 +02:00
|
|
|
args.append(QString::fromLatin1(":%1").arg(d->gdbServerPort.number()));
|
2013-08-08 14:05:11 +02:00
|
|
|
}
|
2016-01-27 18:25:13 +01:00
|
|
|
r.executable = command;
|
|
|
|
|
r.commandLineArguments = QtcProcess::joinArgs(args, OsTypeLinux);
|
2017-03-24 11:26:33 +01:00
|
|
|
return r;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void LinuxDeviceDebugSupport::handleAppRunnerError(const QString &error)
|
|
|
|
|
{
|
2017-04-21 11:39:01 +02:00
|
|
|
if (state() == AbstractRemoteLinuxRunSupport::Running) {
|
2012-07-26 09:02:34 +02:00
|
|
|
showMessage(error, AppError);
|
2017-04-21 17:20:57 +02:00
|
|
|
runControl()->toolRunner()->notifyInferiorIll();
|
2017-04-21 11:39:01 +02:00
|
|
|
} else if (state() != AbstractRemoteLinuxRunSupport::Inactive) {
|
2012-07-26 09:02:34 +02:00
|
|
|
handleAdapterSetupFailed(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LinuxDeviceDebugSupport::handleAppRunnerFinished(bool success)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2017-04-21 11:39:01 +02:00
|
|
|
if (state() == AbstractRemoteLinuxRunSupport::Inactive)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2017-04-21 11:39:01 +02:00
|
|
|
if (state() == AbstractRemoteLinuxRunSupport::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)
|
2017-04-21 17:20:57 +02:00
|
|
|
runControl()->toolRunner()->quitDebugger();
|
2012-07-26 09:02:34 +02:00
|
|
|
else if (!success)
|
2017-04-21 17:20:57 +02:00
|
|
|
runControl()->toolRunner()->notifyInferiorIll();
|
2011-07-05 16:15:05 +02:00
|
|
|
|
2017-04-21 11:39:01 +02:00
|
|
|
} else if (state() == AbstractRemoteLinuxRunSupport::StartingRunner) {
|
2014-09-18 19:21:27 +02:00
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.success = false;
|
|
|
|
|
result.reason = tr("Debugging failed.");
|
2017-04-21 17:20:57 +02:00
|
|
|
runControl()->toolRunner()->notifyEngineRemoteSetupFinished(result);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
2017-04-21 11:39:01 +02:00
|
|
|
targetRunner()->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
|
|
|
{
|
2017-04-21 11:39:01 +02:00
|
|
|
targetRunner()->setFinished();
|
|
|
|
|
targetRunner()->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
|
|
|
{
|
2017-04-21 11:39:01 +02:00
|
|
|
QTC_ASSERT(state() == AbstractRemoteLinuxRunSupport::Inactive
|
|
|
|
|
|| state() == AbstractRemoteLinuxRunSupport::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
|
|
|
{
|
2017-04-21 11:39:01 +02:00
|
|
|
QTC_ASSERT(state() != AbstractRemoteLinuxRunSupport::GatheringResources, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
showMessage(QString::fromUtf8(output), AppError);
|
2017-04-21 11:39:01 +02:00
|
|
|
if (state() == AbstractRemoteLinuxRunSupport::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
|
|
|
{
|
2014-09-18 19:21:27 +02:00
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.success = false;
|
|
|
|
|
result.reason = tr("Initial setup failed: %1").arg(error);
|
2017-04-21 17:20:57 +02:00
|
|
|
runControl()->toolRunner()->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
|
|
|
{
|
2017-04-21 11:39:01 +02:00
|
|
|
targetRunner()->setState(AbstractRemoteLinuxRunSupport::Running);
|
2014-09-18 19:21:27 +02:00
|
|
|
|
|
|
|
|
RemoteSetupResult result;
|
|
|
|
|
result.success = true;
|
|
|
|
|
result.gdbServerPort = d->gdbServerPort;
|
|
|
|
|
result.qmlServerPort = d->qmlPort;
|
2017-04-21 17:20:57 +02:00
|
|
|
runControl()->toolRunner()->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);
|
2017-04-21 11:39:01 +02:00
|
|
|
QTC_ASSERT(state() == AbstractRemoteLinuxRunSupport::StartingRunner, return);
|
2011-07-20 11:50:01 +02:00
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
handleAdapterSetupDone();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|