2011-06-16 17:03:43 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** 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, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
#include "remotelinuxdebugsupport.h"
|
|
|
|
|
|
2011-07-20 11:50:01 +02:00
|
|
|
#include "linuxdeviceconfiguration.h"
|
2011-06-16 17:03:43 +02:00
|
|
|
#include "remotelinuxapplicationrunner.h"
|
2011-08-02 12:20:16 +02:00
|
|
|
#include "remotelinuxrunconfiguration.h"
|
2011-07-22 16:04:55 +02:00
|
|
|
#include "remotelinuxusedportsgatherer.h"
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
#include <debugger/debuggerengine.h>
|
2011-08-02 12:20:16 +02:00
|
|
|
#include <debugger/debuggerstartparameters.h>
|
2011-06-16 17:03:43 +02:00
|
|
|
#include <projectexplorer/abi.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>
|
2011-07-27 18:04:43 +02:00
|
|
|
#include <qt4projectmanager/qt4buildconfiguration.h>
|
2011-07-20 11:50:01 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
#include <QtCore/QPointer>
|
|
|
|
|
#include <QtCore/QSharedPointer>
|
|
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
using namespace Debugger;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
2011-08-02 12:20:16 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
namespace {
|
|
|
|
|
enum State { Inactive, StartingRunner, StartingRemoteProcess, Debugging };
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
class AbstractRemoteLinuxDebugSupportPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AbstractRemoteLinuxDebugSupportPrivate(RemoteLinuxRunConfiguration *runConfig,
|
|
|
|
|
DebuggerEngine *engine)
|
2011-09-07 14:57:35 +02:00
|
|
|
: engine(engine), deviceConfig(runConfig->deviceConfig()),
|
2011-11-11 02:52:34 +01:00
|
|
|
qmlDebugging(runConfig->useQmlDebugger()),
|
|
|
|
|
cppDebugging(runConfig->useCppDebugger()),
|
|
|
|
|
state(Inactive),
|
2011-08-02 12:20:16 +02:00
|
|
|
gdbServerPort(-1), qmlPort(-1)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QPointer<Debugger::DebuggerEngine> engine;
|
|
|
|
|
const LinuxDeviceConfiguration::ConstPtr deviceConfig;
|
2011-11-11 02:52:34 +01:00
|
|
|
bool qmlDebugging;
|
|
|
|
|
bool cppDebugging;
|
2011-08-02 12:20:16 +02:00
|
|
|
QByteArray gdbserverOutput;
|
|
|
|
|
State state;
|
|
|
|
|
int gdbServerPort;
|
|
|
|
|
int qmlPort;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RemoteLinuxDebugSupportPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
RemoteLinuxDebugSupportPrivate(RemoteLinuxRunConfiguration *runConfig) : runner(runConfig) {}
|
|
|
|
|
|
|
|
|
|
GenericRemoteLinuxApplicationRunner runner;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
using namespace Internal;
|
|
|
|
|
|
|
|
|
|
DebuggerStartParameters AbstractRemoteLinuxDebugSupport::startParameters(const RemoteLinuxRunConfiguration *runConfig)
|
|
|
|
|
{
|
|
|
|
|
DebuggerStartParameters params;
|
|
|
|
|
const LinuxDeviceConfiguration::ConstPtr &devConf = runConfig->deviceConfig();
|
2011-11-11 02:52:34 +01:00
|
|
|
if (runConfig->useQmlDebugger()) {
|
2011-06-16 17:03:43 +02:00
|
|
|
params.qmlServerAddress = runConfig->deviceConfig()->sshParameters().host;
|
|
|
|
|
params.qmlServerPort = -1;
|
|
|
|
|
}
|
2011-11-11 02:52:34 +01:00
|
|
|
if (runConfig->useCppDebugger()) {
|
2011-06-16 17:03:43 +02:00
|
|
|
params.processArgs = runConfig->arguments();
|
|
|
|
|
if (runConfig->activeQt4BuildConfiguration()->qtVersion())
|
|
|
|
|
params.sysroot = runConfig->activeQt4BuildConfiguration()->qtVersion()->systemRoot();
|
|
|
|
|
params.toolChainAbi = runConfig->abi();
|
2011-09-16 11:04:11 +02:00
|
|
|
params.startMode = AttachToRemoteServer;
|
2011-06-16 17:03:43 +02:00
|
|
|
params.executable = runConfig->localExecutableFilePath();
|
|
|
|
|
params.debuggerCommand = runConfig->gdbCmd();
|
|
|
|
|
params.remoteChannel = devConf->sshParameters().host + QLatin1String(":-1");
|
2012-01-23 14:57:51 +01:00
|
|
|
params.requestRemoteSetup = true;
|
2011-06-16 17:03:43 +02:00
|
|
|
|
|
|
|
|
// TODO: This functionality should be inside the debugger.
|
|
|
|
|
const ProjectExplorer::Abi &abi = runConfig->target()
|
|
|
|
|
->activeBuildConfiguration()->toolChain()->targetAbi();
|
|
|
|
|
params.remoteArchitecture = abi.toString();
|
|
|
|
|
params.gnuTarget = QLatin1String(abi.architecture() == ProjectExplorer::Abi::ArmArchitecture
|
|
|
|
|
? "arm-none-linux-gnueabi": "i386-unknown-linux-gnu");
|
|
|
|
|
} else {
|
2011-09-16 11:04:11 +02:00
|
|
|
params.startMode = AttachToRemoteServer;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
params.displayName = runConfig->displayName();
|
|
|
|
|
|
|
|
|
|
if (const ProjectExplorer::Project *project = runConfig->target()->project()) {
|
|
|
|
|
params.projectSourceDirectory = project->projectDirectory();
|
|
|
|
|
if (const ProjectExplorer::BuildConfiguration *buildConfig = runConfig->target()->activeBuildConfiguration()) {
|
|
|
|
|
params.projectBuildDirectory = buildConfig->buildDirectory();
|
|
|
|
|
}
|
|
|
|
|
params.projectSourceFiles = project->files(Project::ExcludeGeneratedFiles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return params;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
AbstractRemoteLinuxDebugSupport::AbstractRemoteLinuxDebugSupport(RemoteLinuxRunConfiguration *runConfig,
|
|
|
|
|
DebuggerEngine *engine)
|
2011-09-15 09:10:10 +02:00
|
|
|
: QObject(engine), d(new AbstractRemoteLinuxDebugSupportPrivate(runConfig, engine))
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
connect(d->engine, SIGNAL(requestRemoteSetup()), this, SLOT(handleAdapterSetupRequested()));
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractRemoteLinuxDebugSupport::~AbstractRemoteLinuxDebugSupport()
|
|
|
|
|
{
|
2011-08-02 12:20:16 +02:00
|
|
|
setFinished();
|
2011-09-15 09:10:10 +02:00
|
|
|
delete d;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::showMessage(const QString &msg, int channel)
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->engine)
|
|
|
|
|
d->engine->showMessage(msg, channel);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::handleAdapterSetupRequested()
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == Inactive, return);
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = StartingRunner;
|
2011-06-16 17:03:43 +02:00
|
|
|
showMessage(tr("Preparing remote side ...\n"), AppStuff);
|
|
|
|
|
disconnect(runner(), 0, this, 0);
|
|
|
|
|
connect(runner(), SIGNAL(error(QString)), this, SLOT(handleSshError(QString)));
|
|
|
|
|
connect(runner(), SIGNAL(readyForExecution()), this, SLOT(startExecution()));
|
|
|
|
|
connect(runner(), SIGNAL(reportProgress(QString)), this, SLOT(handleProgressReport(QString)));
|
|
|
|
|
runner()->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::handleSshError(const QString &error)
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->state == Debugging) {
|
2011-06-16 17:03:43 +02:00
|
|
|
showMessage(error, AppError);
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->engine)
|
|
|
|
|
d->engine->notifyInferiorIll();
|
|
|
|
|
} else if (d->state != Inactive) {
|
2011-06-16 17:03:43 +02:00
|
|
|
handleAdapterSetupFailed(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::startExecution()
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->state == Inactive)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == StartingRunner, 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;
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = StartingRemoteProcess;
|
|
|
|
|
d->gdbserverOutput.clear();
|
2011-06-16 17:03:43 +02:00
|
|
|
connect(runner(), SIGNAL(remoteErrorOutput(QByteArray)), this,
|
|
|
|
|
SLOT(handleRemoteErrorOutput(QByteArray)));
|
|
|
|
|
connect(runner(), SIGNAL(remoteOutput(QByteArray)), this,
|
|
|
|
|
SLOT(handleRemoteOutput(QByteArray)));
|
2011-11-11 02:52:34 +01:00
|
|
|
if (d->qmlDebugging && !d->cppDebugging) {
|
2011-06-16 17:03:43 +02:00
|
|
|
connect(runner(), SIGNAL(remoteProcessStarted()),
|
|
|
|
|
SLOT(handleRemoteProcessStarted()));
|
|
|
|
|
}
|
|
|
|
|
const QString &remoteExe = runner()->remoteExecutable();
|
|
|
|
|
QString args = runner()->arguments();
|
2011-11-11 02:52:34 +01:00
|
|
|
if (d->qmlDebugging) {
|
2012-01-30 16:39:10 +02:00
|
|
|
args += QString::fromLatin1(" -qmljsdebugger=port:%1,block")
|
2011-09-15 09:10:10 +02:00
|
|
|
.arg(d->qmlPort);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-11 02:52:34 +01:00
|
|
|
const QString remoteCommandLine = (d->qmlDebugging && !d->cppDebugging)
|
2012-01-30 16:39:10 +02:00
|
|
|
? QString::fromLatin1("%1 %2 %3").arg(runner()->commandPrefix()).arg(remoteExe).arg(args)
|
|
|
|
|
: QString::fromLatin1("%1 gdbserver :%2 %3 %4").arg(runner()->commandPrefix())
|
2011-09-15 09:10:10 +02:00
|
|
|
.arg(d->gdbServerPort).arg(remoteExe).arg(args);
|
2011-06-16 17:03:43 +02:00
|
|
|
connect(runner(), SIGNAL(remoteProcessFinished(qint64)),
|
|
|
|
|
SLOT(handleRemoteProcessFinished(qint64)));
|
|
|
|
|
runner()->startExecution(remoteCommandLine.toUtf8());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::handleRemoteProcessFinished(qint64 exitCode)
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
if (!d->engine || d->state == Inactive)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->state == Debugging) {
|
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();
|
2011-07-05 16:15:05 +02:00
|
|
|
else if (exitCode != 0)
|
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 {
|
2011-11-11 02:52:34 +01:00
|
|
|
const QString errorMsg = (d->qmlDebugging && !d->cppDebugging)
|
2011-06-16 17:03:43 +02:00
|
|
|
? tr("Remote application failed with exit code %1.").arg(exitCode)
|
|
|
|
|
: tr("The gdbserver process closed unexpectedly.");
|
2011-09-15 09:10:10 +02:00
|
|
|
d->engine->handleRemoteSetupFailed(errorMsg);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::handleDebuggingFinished()
|
|
|
|
|
{
|
2011-08-02 12:20:16 +02:00
|
|
|
setFinished();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::handleRemoteOutput(const QByteArray &output)
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == Inactive || d->state == Debugging, return);
|
2011-07-20 11:50:01 +02:00
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
showMessage(QString::fromUtf8(output), AppOutput);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::handleRemoteErrorOutput(const QByteArray &output)
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == Inactive || d->state == StartingRemoteProcess || d->state == Debugging,
|
2011-07-20 11:50:01 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
showMessage(QString::fromUtf8(output), AppOutput);
|
2011-11-11 02:52:34 +01:00
|
|
|
if (d->state == StartingRemoteProcess && 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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::handleProgressReport(const QString &progressOutput)
|
|
|
|
|
{
|
|
|
|
|
showMessage(progressOutput + QLatin1Char('\n'), AppStuff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::handleAdapterSetupFailed(const QString &error)
|
|
|
|
|
{
|
2011-08-02 12:20:16 +02:00
|
|
|
setFinished();
|
2011-09-15 09:10:10 +02:00
|
|
|
d->engine->handleRemoteSetupFailed(tr("Initial setup failed: %1").arg(error));
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::handleAdapterSetupDone()
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = Debugging;
|
|
|
|
|
d->engine->handleRemoteSetupDone(d->gdbServerPort, d->qmlPort);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDebugSupport::handleRemoteProcessStarted()
|
|
|
|
|
{
|
2011-11-11 02:52:34 +01:00
|
|
|
Q_ASSERT(d->qmlDebugging && !d->cppDebugging);
|
2011-09-15 09:10:10 +02:00
|
|
|
QTC_ASSERT(d->state == StartingRemoteProcess, return);
|
2011-07-20 11:50:01 +02:00
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
handleAdapterSetupDone();
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-02 12:20:16 +02:00
|
|
|
void AbstractRemoteLinuxDebugSupport::setFinished()
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->state == Inactive)
|
2011-06-16 17:03:43 +02:00
|
|
|
return;
|
2011-09-15 09:10:10 +02:00
|
|
|
d->state = Inactive;
|
2011-08-02 12:20:16 +02:00
|
|
|
runner()->stop();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AbstractRemoteLinuxDebugSupport::setPort(int &port)
|
|
|
|
|
{
|
|
|
|
|
port = runner()->usedPortsGatherer()->getNextFreePort(runner()->freePorts());
|
|
|
|
|
if (port == -1) {
|
|
|
|
|
handleAdapterSetupFailed(tr("Not enough free ports on device for debugging."));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RemoteLinuxDebugSupport::RemoteLinuxDebugSupport(RemoteLinuxRunConfiguration *runConfig,
|
|
|
|
|
DebuggerEngine *engine)
|
|
|
|
|
: AbstractRemoteLinuxDebugSupport(runConfig, engine),
|
2011-09-15 09:10:10 +02:00
|
|
|
d(new RemoteLinuxDebugSupportPrivate(runConfig))
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RemoteLinuxDebugSupport::~RemoteLinuxDebugSupport()
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
delete d;
|
2011-08-02 12:20:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AbstractRemoteLinuxApplicationRunner *RemoteLinuxDebugSupport::runner() const
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
return &d->runner;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|