2011-04-13 08:42:33 +02:00
|
|
|
/**************************************************************************
|
2010-07-15 16:43:56 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file is part of Qt Creator
|
2010-07-15 16:43:56 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-07-15 16:43:56 +02:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-07-15 16:43:56 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-04-13 08:42:33 +02:00
|
|
|
**
|
|
|
|
|
** 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.
|
2010-07-15 16:43:56 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-07-15 16:43:56 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
|
|
|
|
**
|
2010-07-15 16:43:56 +02:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
**************************************************************************/
|
2010-07-15 16:43:56 +02:00
|
|
|
|
|
|
|
|
#include "maemodebugsupport.h"
|
|
|
|
|
|
|
|
|
|
#include "maemodeployables.h"
|
|
|
|
|
#include "maemoglobal.h"
|
|
|
|
|
#include "maemosshrunner.h"
|
2010-11-02 10:24:50 +01:00
|
|
|
#include "maemousedportsgatherer.h"
|
2011-01-31 17:46:19 +01:00
|
|
|
#include "qt4maemotarget.h"
|
2010-07-15 16:43:56 +02:00
|
|
|
|
|
|
|
|
#include <debugger/debuggerplugin.h>
|
2011-01-10 10:14:23 +01:00
|
|
|
#include <debugger/debuggerstartparameters.h>
|
2010-07-15 16:43:56 +02:00
|
|
|
#include <debugger/debuggerrunner.h>
|
2010-09-13 11:08:08 +02:00
|
|
|
#include <debugger/debuggerengine.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
#include <projectexplorer/abi.h>
|
2010-07-15 16:43:56 +02:00
|
|
|
|
2010-07-30 12:14:54 +02:00
|
|
|
#include <QtCore/QDir>
|
2010-07-15 16:43:56 +02:00
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
|
2010-10-29 16:19:56 +02:00
|
|
|
#define ASSERT_STATE(state) ASSERT_STATE_GENERIC(State, state, m_state)
|
|
|
|
|
|
2011-02-14 16:34:17 +01:00
|
|
|
using namespace Utils;
|
2010-07-15 16:43:56 +02:00
|
|
|
using namespace Debugger;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
RunControl *MaemoDebugSupport::createDebugRunControl(MaemoRunConfiguration *runConfig)
|
|
|
|
|
{
|
|
|
|
|
DebuggerStartParameters params;
|
2011-01-13 13:49:23 +01:00
|
|
|
const MaemoDeviceConfig::ConstPtr &devConf = runConfig->deviceConfig();
|
2010-09-08 16:51:53 +02:00
|
|
|
|
2010-10-06 16:26:19 +02:00
|
|
|
const MaemoRunConfiguration::DebuggingType debuggingType
|
|
|
|
|
= runConfig->debuggingType();
|
|
|
|
|
if (debuggingType != MaemoRunConfiguration::DebugCppOnly) {
|
2011-01-13 13:49:23 +01:00
|
|
|
params.qmlServerAddress = runConfig->deviceConfig()->sshParameters().host;
|
2010-11-02 10:24:50 +01:00
|
|
|
params.qmlServerPort = -1;
|
2010-09-08 16:51:53 +02:00
|
|
|
}
|
2010-10-06 16:26:19 +02:00
|
|
|
if (debuggingType != MaemoRunConfiguration::DebugQmlOnly) {
|
2010-09-16 17:08:07 +02:00
|
|
|
params.processArgs = runConfig->arguments();
|
|
|
|
|
params.sysRoot = runConfig->sysRoot();
|
2011-02-01 18:36:00 +01:00
|
|
|
params.toolChainAbi = runConfig->abi();
|
2010-09-16 17:08:07 +02:00
|
|
|
if (runConfig->useRemoteGdb()) {
|
|
|
|
|
params.startMode = StartRemoteGdb;
|
|
|
|
|
params.executable = runConfig->remoteExecutableFilePath();
|
2011-04-01 08:54:56 +02:00
|
|
|
params.debuggerCommand = MaemoGlobal::remoteCommandPrefix(runConfig->deviceConfig()->osVersion(),
|
2011-04-04 16:21:53 +02:00
|
|
|
runConfig->deviceConfig()->sshParameters().userName,
|
2011-04-01 08:54:56 +02:00
|
|
|
runConfig->remoteExecutableFilePath())
|
|
|
|
|
+ MaemoGlobal::remoteEnvironment(runConfig->userEnvironmentChanges())
|
|
|
|
|
+ QLatin1String(" /usr/bin/gdb");
|
2011-01-13 13:49:23 +01:00
|
|
|
params.connParams = devConf->sshParameters();
|
2010-09-16 17:08:07 +02:00
|
|
|
params.localMountDir = runConfig->localDirToMountForRemoteGdb();
|
2010-11-02 15:08:30 +01:00
|
|
|
params.remoteMountPoint
|
|
|
|
|
= runConfig->remoteProjectSourcesMountPoint();
|
2010-09-16 17:08:07 +02:00
|
|
|
const QString execDirAbs
|
|
|
|
|
= QDir::fromNativeSeparators(QFileInfo(runConfig->localExecutableFilePath()).path());
|
|
|
|
|
const QString execDirRel
|
|
|
|
|
= QDir(params.localMountDir).relativeFilePath(execDirAbs);
|
|
|
|
|
params.remoteSourcesDir = QString(params.remoteMountPoint
|
|
|
|
|
+ QLatin1Char('/') + execDirRel).toUtf8();
|
|
|
|
|
} else {
|
|
|
|
|
params.startMode = AttachToRemote;
|
|
|
|
|
params.executable = runConfig->localExecutableFilePath();
|
|
|
|
|
params.debuggerCommand = runConfig->gdbCmd();
|
2011-01-13 13:49:23 +01:00
|
|
|
params.remoteChannel
|
|
|
|
|
= devConf->sshParameters().host + QLatin1String(":-1");
|
2010-09-16 17:08:07 +02:00
|
|
|
params.useServerStartScript = true;
|
2011-01-31 17:46:19 +01:00
|
|
|
const AbstractQt4MaemoTarget::DebugArchitecture &debugArch
|
|
|
|
|
= runConfig->maemoTarget()->debugArchitecture();
|
|
|
|
|
params.remoteArchitecture = debugArch.architecture;
|
|
|
|
|
params.gnuTarget = debugArch.gnuTarget;
|
2010-09-16 17:08:07 +02:00
|
|
|
}
|
2010-07-30 12:14:54 +02:00
|
|
|
} else {
|
|
|
|
|
params.startMode = AttachToRemote;
|
|
|
|
|
}
|
2011-02-10 12:15:33 +01:00
|
|
|
params.displayName = runConfig->displayName();
|
2010-09-08 16:51:53 +02:00
|
|
|
|
2011-01-06 19:33:59 +01:00
|
|
|
DebuggerRunControl * const runControl =
|
|
|
|
|
DebuggerPlugin::createDebugger(params, runConfig);
|
2011-01-06 19:41:09 +01:00
|
|
|
bool useGdb = params.startMode == StartRemoteGdb
|
|
|
|
|
&& debuggingType != MaemoRunConfiguration::DebugQmlOnly;
|
2011-01-06 19:33:59 +01:00
|
|
|
MaemoDebugSupport *debugSupport =
|
2011-01-06 19:41:09 +01:00
|
|
|
new MaemoDebugSupport(runConfig, runControl->engine(), useGdb);
|
2011-01-06 19:33:59 +01:00
|
|
|
connect(runControl, SIGNAL(finished()),
|
|
|
|
|
debugSupport, SLOT(handleDebuggingFinished()));
|
|
|
|
|
return runControl;
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoDebugSupport::MaemoDebugSupport(MaemoRunConfiguration *runConfig,
|
2011-01-06 19:41:09 +01:00
|
|
|
DebuggerEngine *engine, bool useGdb)
|
2011-01-06 19:33:59 +01:00
|
|
|
: QObject(engine), m_engine(engine), m_runConfig(runConfig),
|
2011-01-13 13:49:23 +01:00
|
|
|
m_deviceConfig(m_runConfig->deviceConfig()),
|
2010-11-11 12:08:13 +01:00
|
|
|
m_runner(new MaemoSshRunner(this, runConfig, true)),
|
|
|
|
|
m_debuggingType(runConfig->debuggingType()),
|
2011-01-10 17:22:27 +01:00
|
|
|
m_userEnvChanges(runConfig->userEnvironmentChanges()),
|
2011-01-06 19:41:09 +01:00
|
|
|
m_state(Inactive), m_gdbServerPort(-1), m_qmlPort(-1),
|
|
|
|
|
m_useGdb(useGdb)
|
2010-07-15 16:43:56 +02:00
|
|
|
{
|
2011-01-06 19:33:59 +01:00
|
|
|
connect(m_engine, SIGNAL(requestRemoteSetup()), this,
|
2010-09-16 17:08:07 +02:00
|
|
|
SLOT(handleAdapterSetupRequested()));
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-30 12:14:54 +02:00
|
|
|
MaemoDebugSupport::~MaemoDebugSupport()
|
|
|
|
|
{
|
2010-10-29 16:19:56 +02:00
|
|
|
setState(Inactive);
|
2010-07-30 12:14:54 +02:00
|
|
|
}
|
2010-07-15 16:43:56 +02:00
|
|
|
|
2011-01-06 19:26:57 +01:00
|
|
|
void MaemoDebugSupport::showMessage(const QString &msg, int channel)
|
|
|
|
|
{
|
2011-01-06 19:33:59 +01:00
|
|
|
if (m_engine)
|
|
|
|
|
m_engine->showMessage(msg, channel);
|
2011-01-06 19:26:57 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 16:43:56 +02:00
|
|
|
void MaemoDebugSupport::handleAdapterSetupRequested()
|
|
|
|
|
{
|
2010-10-29 16:19:56 +02:00
|
|
|
ASSERT_STATE(Inactive);
|
|
|
|
|
|
|
|
|
|
setState(StartingRunner);
|
2011-04-21 14:03:38 +02:00
|
|
|
showMessage(tr("Preparing remote side ...\n"), AppStuff);
|
2010-07-15 16:43:56 +02:00
|
|
|
disconnect(m_runner, 0, this, 0);
|
|
|
|
|
connect(m_runner, SIGNAL(error(QString)), this,
|
|
|
|
|
SLOT(handleSshError(QString)));
|
|
|
|
|
connect(m_runner, SIGNAL(readyForExecution()), this,
|
|
|
|
|
SLOT(startExecution()));
|
2010-08-10 16:26:41 +02:00
|
|
|
connect(m_runner, SIGNAL(reportProgress(QString)), this,
|
|
|
|
|
SLOT(handleProgressReport(QString)));
|
2010-07-15 16:43:56 +02:00
|
|
|
m_runner->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDebugSupport::handleSshError(const QString &error)
|
|
|
|
|
{
|
2010-10-29 16:19:56 +02:00
|
|
|
if (m_state == Debugging) {
|
2011-04-21 09:37:52 +02:00
|
|
|
showMessage(error, AppError);
|
2011-02-11 14:20:23 +01:00
|
|
|
if (m_engine)
|
|
|
|
|
m_engine->notifyInferiorIll();
|
2010-10-29 16:19:56 +02:00
|
|
|
} else if (m_state != Inactive) {
|
2010-07-15 16:43:56 +02:00
|
|
|
handleAdapterSetupFailed(error);
|
2010-10-29 16:19:56 +02:00
|
|
|
}
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDebugSupport::startExecution()
|
|
|
|
|
{
|
2010-10-29 16:19:56 +02:00
|
|
|
if (m_state == Inactive)
|
2010-07-15 16:43:56 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-10-29 16:19:56 +02:00
|
|
|
ASSERT_STATE(StartingRunner);
|
|
|
|
|
|
2010-11-02 10:24:50 +01:00
|
|
|
if (!useGdb() && m_debuggingType != MaemoRunConfiguration::DebugQmlOnly) {
|
|
|
|
|
if (!setPort(m_gdbServerPort))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (m_debuggingType != MaemoRunConfiguration::DebugCppOnly) {
|
|
|
|
|
if (!setPort(m_qmlPort))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-21 14:03:38 +02:00
|
|
|
if (useGdb()) {
|
|
|
|
|
handleAdapterSetupDone();
|
2010-07-15 16:43:56 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2010-10-29 16:19:56 +02:00
|
|
|
|
2011-04-21 14:03:38 +02:00
|
|
|
setState(StartingRemoteProcess);
|
|
|
|
|
m_gdbserverOutput.clear();
|
|
|
|
|
connect(m_runner, SIGNAL(remoteErrorOutput(QByteArray)), this,
|
|
|
|
|
SLOT(handleRemoteErrorOutput(QByteArray)));
|
|
|
|
|
connect(m_runner, SIGNAL(remoteOutput(QByteArray)), this,
|
|
|
|
|
SLOT(handleRemoteOutput(QByteArray)));
|
|
|
|
|
if (m_debuggingType == MaemoRunConfiguration::DebugQmlOnly) {
|
|
|
|
|
connect(m_runner, SIGNAL(remoteProcessStarted()),
|
|
|
|
|
SLOT(handleRemoteProcessStarted()));
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
2011-04-21 14:03:38 +02:00
|
|
|
const QString &remoteExe = m_runner->remoteExecutable();
|
|
|
|
|
const QString cmdPrefix = MaemoGlobal::remoteCommandPrefix(m_deviceConfig->osVersion(),
|
|
|
|
|
m_deviceConfig->sshParameters().userName, remoteExe);
|
|
|
|
|
const QString env = MaemoGlobal::remoteEnvironment(m_userEnvChanges);
|
|
|
|
|
QString args = m_runner->arguments();
|
|
|
|
|
if (m_debuggingType != MaemoRunConfiguration::DebugCppOnly) {
|
|
|
|
|
args += QString(QLatin1String(" -qmljsdebugger=port:%1,block"))
|
|
|
|
|
.arg(m_qmlPort);
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-21 14:03:38 +02:00
|
|
|
const QString remoteCommandLine = m_debuggingType == MaemoRunConfiguration::DebugQmlOnly
|
|
|
|
|
? QString::fromLocal8Bit("%1 %2 %3 %4").arg(cmdPrefix).arg(env)
|
|
|
|
|
.arg(remoteExe).arg(args)
|
|
|
|
|
: QString::fromLocal8Bit("%1 %2 gdbserver :%3 %4 %5")
|
|
|
|
|
.arg(cmdPrefix).arg(env).arg(m_gdbServerPort)
|
|
|
|
|
.arg(remoteExe).arg(args);
|
|
|
|
|
connect(m_runner, SIGNAL(remoteProcessFinished(qint64)),
|
|
|
|
|
SLOT(handleRemoteProcessFinished(qint64)));
|
|
|
|
|
m_runner->startExecution(remoteCommandLine.toUtf8());
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-21 09:38:58 +02:00
|
|
|
void MaemoDebugSupport::handleRemoteProcessFinished(qint64 exitCode)
|
2011-04-15 14:20:04 +02:00
|
|
|
{
|
|
|
|
|
if (!m_engine || m_state == Inactive || exitCode == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-04-21 09:38:58 +02:00
|
|
|
if (m_state == Debugging) {
|
|
|
|
|
if (m_debuggingType != MaemoRunConfiguration::DebugQmlOnly)
|
|
|
|
|
m_engine->notifyInferiorIll();
|
|
|
|
|
} else {
|
|
|
|
|
const QString errorMsg = m_debuggingType == MaemoRunConfiguration::DebugQmlOnly
|
|
|
|
|
? tr("Remote application failed with exit code %1.").arg(exitCode)
|
|
|
|
|
: tr("The gdbserver process closed unexpectedly.");
|
|
|
|
|
m_engine->handleRemoteSetupFailed(errorMsg);
|
|
|
|
|
}
|
2011-04-15 14:20:04 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 16:43:56 +02:00
|
|
|
void MaemoDebugSupport::handleDebuggingFinished()
|
|
|
|
|
{
|
2010-10-29 16:19:56 +02:00
|
|
|
setState(Inactive);
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDebugSupport::handleRemoteOutput(const QByteArray &output)
|
|
|
|
|
{
|
2010-10-29 16:19:56 +02:00
|
|
|
ASSERT_STATE(QList<State>() << Inactive << Debugging);
|
2011-01-06 19:26:57 +01:00
|
|
|
showMessage(QString::fromUtf8(output), AppOutput);
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDebugSupport::handleRemoteErrorOutput(const QByteArray &output)
|
|
|
|
|
{
|
2010-10-29 16:19:56 +02:00
|
|
|
ASSERT_STATE(QList<State>() << Inactive << StartingRemoteProcess << Debugging);
|
|
|
|
|
|
2011-01-06 19:33:59 +01:00
|
|
|
if (!m_engine)
|
2010-10-29 16:19:56 +02:00
|
|
|
return;
|
|
|
|
|
|
2011-01-06 19:26:57 +01:00
|
|
|
showMessage(QString::fromUtf8(output), AppOutput);
|
2010-11-02 10:24:50 +01:00
|
|
|
if (m_state == StartingRemoteProcess
|
|
|
|
|
&& m_debuggingType != MaemoRunConfiguration::DebugQmlOnly) {
|
2010-10-21 11:35:18 +02:00
|
|
|
m_gdbserverOutput += output;
|
|
|
|
|
if (m_gdbserverOutput.contains("Listening on port")) {
|
|
|
|
|
handleAdapterSetupDone();
|
|
|
|
|
m_gdbserverOutput.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-10 16:26:41 +02:00
|
|
|
void MaemoDebugSupport::handleProgressReport(const QString &progressOutput)
|
|
|
|
|
{
|
2011-04-01 10:24:20 +02:00
|
|
|
showMessage(progressOutput + QLatin1Char('\n'), AppStuff);
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDebugSupport::handleAdapterSetupFailed(const QString &error)
|
|
|
|
|
{
|
2010-10-29 16:19:56 +02:00
|
|
|
setState(Inactive);
|
2011-01-06 19:33:59 +01:00
|
|
|
m_engine->handleRemoteSetupFailed(tr("Initial setup failed: %1").arg(error));
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoDebugSupport::handleAdapterSetupDone()
|
|
|
|
|
{
|
2010-10-29 16:19:56 +02:00
|
|
|
setState(Debugging);
|
2011-01-06 19:33:59 +01:00
|
|
|
m_engine->handleRemoteSetupDone(m_gdbServerPort, m_qmlPort);
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-11 16:02:41 +01:00
|
|
|
void MaemoDebugSupport::handleRemoteProcessStarted()
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(m_debuggingType == MaemoRunConfiguration::DebugQmlOnly);
|
|
|
|
|
ASSERT_STATE(StartingRemoteProcess);
|
|
|
|
|
handleAdapterSetupDone();
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-29 16:19:56 +02:00
|
|
|
void MaemoDebugSupport::setState(State newState)
|
|
|
|
|
{
|
|
|
|
|
if (m_state == newState)
|
|
|
|
|
return;
|
|
|
|
|
m_state = newState;
|
2011-04-21 14:03:38 +02:00
|
|
|
if (m_state == Inactive)
|
2010-10-29 16:19:56 +02:00
|
|
|
m_runner->stop();
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-30 12:14:54 +02:00
|
|
|
bool MaemoDebugSupport::useGdb() const
|
|
|
|
|
{
|
2011-01-06 19:41:09 +01:00
|
|
|
return m_useGdb;
|
2010-11-02 10:24:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoDebugSupport::setPort(int &port)
|
|
|
|
|
{
|
|
|
|
|
port = m_runner->usedPortsGatherer()->getNextFreePort(m_runner->freePorts());
|
|
|
|
|
if (port == -1) {
|
|
|
|
|
handleAdapterSetupFailed(tr("Not enough free ports on device for debugging."));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2010-07-30 12:14:54 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-15 16:43:56 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qt4ProjectManager
|