2012-06-29 07:23:13 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2011 - 2012 Research In Motion
|
|
|
|
|
**
|
|
|
|
|
** Contact: Research In Motion (blackberry-qt@qnx.com)
|
|
|
|
|
** Contact: KDAB (info@kdab.com)
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** 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
|
|
|
|
|
** Nokia at info@qt.nokia.com.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qnxdebugsupport.h"
|
|
|
|
|
#include "qnxconstants.h"
|
2012-07-26 09:02:34 +02:00
|
|
|
#include "qnxrunconfiguration.h"
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
#include <debugger/debuggerengine.h>
|
2012-07-26 09:02:34 +02:00
|
|
|
#include <projectexplorer/devicesupport/deviceapplicationrunner.h>
|
|
|
|
|
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
|
|
|
|
|
#include <projectexplorer/profileinformation.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
#include <utils/portlist.h>
|
2012-06-29 07:23:13 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace RemoteLinux;
|
|
|
|
|
|
|
|
|
|
using namespace Qnx;
|
2012-06-29 07:23:13 +02:00
|
|
|
using namespace Qnx::Internal;
|
|
|
|
|
|
|
|
|
|
QnxDebugSupport::QnxDebugSupport(QnxRunConfiguration *runConfig, Debugger::DebuggerEngine *engine)
|
|
|
|
|
: QObject(engine)
|
2012-07-26 09:02:34 +02:00
|
|
|
, m_executable(QLatin1String(Constants::QNX_DEBUG_EXECUTABLE))
|
|
|
|
|
, m_commandPrefix(runConfig->commandPrefix())
|
|
|
|
|
, m_arguments(runConfig->arguments())
|
|
|
|
|
, m_device(DeviceProfileInformation::device(runConfig->target()->profile()))
|
2012-06-29 07:23:13 +02:00
|
|
|
, m_engine(engine)
|
|
|
|
|
, m_port(-1)
|
|
|
|
|
, m_state(Inactive)
|
|
|
|
|
{
|
2012-07-26 09:02:34 +02:00
|
|
|
m_runner = new DeviceApplicationRunner(this);
|
|
|
|
|
m_portsGatherer = new DeviceUsedPortsGatherer(this);
|
|
|
|
|
|
|
|
|
|
connect(m_portsGatherer, SIGNAL(error(QString)), SLOT(handleError(QString)));
|
|
|
|
|
connect(m_portsGatherer, SIGNAL(portListReady()), SLOT(handlePortListReady()));
|
|
|
|
|
|
|
|
|
|
connect(m_runner, SIGNAL(reportError(QString)), SLOT(handleError(QString)));
|
|
|
|
|
connect(m_runner, SIGNAL(remoteProcessStarted()), this, SLOT(handleRemoteProcessStarted()));
|
|
|
|
|
connect(m_runner, SIGNAL(finished(bool)), SLOT(handleRemoteProcessFinished(qint64)));
|
|
|
|
|
connect(m_runner, SIGNAL(reportProgress(QString)), this, SLOT(handleProgressReport(QString)));
|
|
|
|
|
connect(m_runner, SIGNAL(remoteStdout(QByteArray)), this, SLOT(handleRemoteOutput(QByteArray)));
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
connect(m_engine, SIGNAL(requestRemoteSetup()), this, SLOT(handleAdapterSetupRequested()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::handleAdapterSetupRequested()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_state == Inactive, return);
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
m_state = GatheringPorts;
|
2012-06-29 07:23:13 +02:00
|
|
|
if (m_engine)
|
|
|
|
|
m_engine->showMessage(tr("Preparing remote side...\n"), Debugger::AppStuff);
|
2012-07-26 09:02:34 +02:00
|
|
|
m_portsGatherer->start(m_device);
|
|
|
|
|
}
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void QnxDebugSupport::handlePortListReady()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_state == GatheringPorts, return);
|
|
|
|
|
startExecution();
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::startExecution()
|
|
|
|
|
{
|
|
|
|
|
if (m_state == Inactive)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_state = StartingRemoteProcess;
|
2012-07-26 09:02:34 +02:00
|
|
|
Utils::PortList portList = m_device->freePorts();
|
|
|
|
|
m_port = m_portsGatherer->getNextFreePort(&portList);
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
const QString remoteCommandLine = QString::fromLatin1("%1 %2 %3")
|
|
|
|
|
.arg(m_commandPrefix, m_executable).arg(m_port);
|
|
|
|
|
m_runner->start(m_device, remoteCommandLine.toUtf8());
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::handleRemoteProcessStarted()
|
|
|
|
|
{
|
|
|
|
|
if (m_engine)
|
|
|
|
|
m_engine->notifyEngineRemoteSetupDone(m_port, -1);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void QnxDebugSupport::handleRemoteProcessFinished(bool success)
|
2012-06-29 07:23:13 +02:00
|
|
|
{
|
|
|
|
|
if (m_engine || m_state == Inactive)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_state == Debugging) {
|
2012-07-26 09:02:34 +02:00
|
|
|
if (!success)
|
2012-06-29 07:23:13 +02:00
|
|
|
m_engine->notifyInferiorIll();
|
|
|
|
|
|
|
|
|
|
} else {
|
2012-07-26 09:02:34 +02:00
|
|
|
const QString errorMsg = tr("The %1 process closed unexpectedly.").arg(m_executable);
|
2012-06-29 07:23:13 +02:00
|
|
|
m_engine->notifyEngineRemoteSetupFailed(errorMsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::handleDebuggingFinished()
|
|
|
|
|
{
|
|
|
|
|
setFinished();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::setFinished()
|
|
|
|
|
{
|
|
|
|
|
m_state = Inactive;
|
2012-08-01 16:26:27 +02:00
|
|
|
m_runner->stop(m_device->processSupport()->killProcessByNameCommandLine(m_executable).toUtf8());
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::handleProgressReport(const QString &progressOutput)
|
|
|
|
|
{
|
|
|
|
|
if (m_engine)
|
|
|
|
|
m_engine->showMessage(progressOutput + QLatin1Char('\n'), Debugger::AppStuff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::handleRemoteOutput(const QByteArray &output)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_state == Inactive || m_state == Debugging, return);
|
|
|
|
|
|
|
|
|
|
if (m_engine)
|
|
|
|
|
m_engine->showMessage(QString::fromUtf8(output), Debugger::AppOutput);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void QnxDebugSupport::handleError(const QString &error)
|
2012-06-29 07:23:13 +02:00
|
|
|
{
|
|
|
|
|
if (m_state == Debugging) {
|
|
|
|
|
if (m_engine) {
|
|
|
|
|
m_engine->showMessage(error, Debugger::AppError);
|
|
|
|
|
m_engine->notifyInferiorIll();
|
|
|
|
|
}
|
|
|
|
|
} else if (m_state != Inactive) {
|
|
|
|
|
setFinished();
|
|
|
|
|
if (m_engine)
|
|
|
|
|
m_engine->notifyEngineRemoteSetupFailed(tr("Initial setup failed: %1").arg(error));
|
|
|
|
|
}
|
|
|
|
|
}
|