2012-06-29 07:23:13 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2012 - 2014 BlackBerry Limited. All rights reserved.
|
2012-06-29 07:23:13 +02:00
|
|
|
**
|
2013-10-11 17:44:13 +02:00
|
|
|
** Contact: BlackBerry (qt@blackberry.com)
|
2012-06-29 07:23:13 +02:00
|
|
|
** Contact: KDAB (info@kdab.com)
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-06-29 07:23:13 +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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2012-06-29 07:23:13 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-06-29 07:23:13 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
#include "qnxdebugsupport.h"
|
|
|
|
|
#include "qnxconstants.h"
|
2013-11-05 14:29:05 +01:00
|
|
|
#include "qnxdeviceconfiguration.h"
|
2012-07-26 09:02:34 +02:00
|
|
|
#include "qnxrunconfiguration.h"
|
2013-11-05 14:29:05 +01:00
|
|
|
#include "slog2inforunner.h"
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
#include <debugger/debuggerengine.h>
|
2013-03-28 08:14:09 +01:00
|
|
|
#include <debugger/debuggerrunconfigurationaspect.h>
|
2014-10-17 13:40:04 +02:00
|
|
|
#include <debugger/debuggerruncontrol.h>
|
2013-03-28 08:14:09 +01:00
|
|
|
#include <debugger/debuggerstartparameters.h>
|
2012-07-26 09:02:34 +02:00
|
|
|
#include <projectexplorer/devicesupport/deviceapplicationrunner.h>
|
|
|
|
|
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2012-07-26 09:02:34 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2012-06-29 07:23:13 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2013-08-08 14:05:11 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2012-06-29 07:23:13 +02:00
|
|
|
|
2013-11-05 14:29:05 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
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)
|
2013-05-07 11:05:22 +02:00
|
|
|
: QnxAbstractRunSupport(runConfig, engine)
|
2012-06-29 07:23:13 +02:00
|
|
|
, m_engine(engine)
|
2013-03-28 08:14:09 +01:00
|
|
|
, m_pdebugPort(-1)
|
|
|
|
|
, m_qmlPort(-1)
|
|
|
|
|
, m_useCppDebugger(runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>()->useCppDebugger())
|
|
|
|
|
, m_useQmlDebugger(runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>()->useQmlDebugger())
|
2012-06-29 07:23:13 +02:00
|
|
|
{
|
2013-05-07 11:05:22 +02:00
|
|
|
const DeviceApplicationRunner *runner = appRunner();
|
|
|
|
|
connect(runner, SIGNAL(reportError(QString)), SLOT(handleError(QString)));
|
|
|
|
|
connect(runner, SIGNAL(remoteProcessStarted()), SLOT(handleRemoteProcessStarted()));
|
|
|
|
|
connect(runner, SIGNAL(finished(bool)), SLOT(handleRemoteProcessFinished(bool)));
|
|
|
|
|
connect(runner, SIGNAL(reportProgress(QString)), SLOT(handleProgressReport(QString)));
|
|
|
|
|
connect(runner, SIGNAL(remoteStdout(QByteArray)), SLOT(handleRemoteOutput(QByteArray)));
|
|
|
|
|
connect(runner, SIGNAL(remoteStderr(QByteArray)), SLOT(handleRemoteOutput(QByteArray)));
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
connect(m_engine, SIGNAL(requestRemoteSetup()), this, SLOT(handleAdapterSetupRequested()));
|
2013-11-05 14:29:05 +01:00
|
|
|
|
|
|
|
|
const QString applicationId = QFileInfo(runConfig->remoteExecutableFilePath()).fileName();
|
|
|
|
|
ProjectExplorer::IDevice::ConstPtr dev = ProjectExplorer::DeviceKitInformation::device(runConfig->target()->kit());
|
|
|
|
|
QnxDeviceConfiguration::ConstPtr qnxDevice = dev.dynamicCast<const QnxDeviceConfiguration>();
|
|
|
|
|
|
|
|
|
|
m_slog2Info = new Slog2InfoRunner(applicationId, qnxDevice, this);
|
|
|
|
|
connect(m_slog2Info, SIGNAL(output(QString,Utils::OutputFormat)), this, SLOT(handleApplicationOutput(QString,Utils::OutputFormat)));
|
|
|
|
|
connect(runner, SIGNAL(remoteProcessStarted()), m_slog2Info, SLOT(start()));
|
|
|
|
|
if (qnxDevice->qnxVersion() > 0x060500)
|
|
|
|
|
connect(m_slog2Info, SIGNAL(commandMissing()), this, SLOT(printMissingWarning()));
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::handleAdapterSetupRequested()
|
|
|
|
|
{
|
2013-05-07 11:05:22 +02:00
|
|
|
QTC_ASSERT(state() == Inactive, return);
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
if (m_engine)
|
2013-10-17 13:48:04 +02:00
|
|
|
m_engine->showMessage(tr("Preparing remote side...") + QLatin1Char('\n'), Debugger::AppStuff);
|
2013-05-07 11:05:22 +02:00
|
|
|
QnxAbstractRunSupport::handleAdapterSetupRequested();
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::startExecution()
|
|
|
|
|
{
|
2013-05-07 11:05:22 +02:00
|
|
|
if (state() == Inactive)
|
2012-06-29 07:23:13 +02:00
|
|
|
return;
|
|
|
|
|
|
2013-05-07 11:05:22 +02:00
|
|
|
if (m_useCppDebugger && !setPort(m_pdebugPort))
|
|
|
|
|
return;
|
|
|
|
|
if (m_useQmlDebugger && !setPort(m_qmlPort))
|
2013-03-28 08:14:09 +01:00
|
|
|
return;
|
|
|
|
|
|
2013-05-07 11:05:22 +02:00
|
|
|
setState(StartingRemoteProcess);
|
2013-03-28 08:14:09 +01:00
|
|
|
|
|
|
|
|
if (m_useQmlDebugger)
|
2013-11-05 14:45:35 +01:00
|
|
|
m_engine->startParameters().processArgs += QString::fromLatin1(" -qmljsdebugger=port:%1,block").arg(m_qmlPort);
|
2013-03-28 08:14:09 +01:00
|
|
|
|
2013-08-08 14:05:11 +02:00
|
|
|
QStringList arguments;
|
2013-03-28 08:14:09 +01:00
|
|
|
if (m_useCppDebugger)
|
2013-08-08 14:05:11 +02:00
|
|
|
arguments << QString::number(m_pdebugPort);
|
2013-03-28 08:14:09 +01:00
|
|
|
else if (m_useQmlDebugger && !m_useCppDebugger)
|
2013-08-08 14:05:11 +02:00
|
|
|
arguments = Utils::QtcProcess::splitArgs(m_engine->startParameters().processArgs);
|
|
|
|
|
appRunner()->setEnvironment(environment());
|
|
|
|
|
appRunner()->setWorkingDirectory(workingDirectory());
|
|
|
|
|
appRunner()->start(device(), executable(), arguments);
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::handleRemoteProcessStarted()
|
|
|
|
|
{
|
2013-05-07 11:05:22 +02:00
|
|
|
QnxAbstractRunSupport::handleRemoteProcessStarted();
|
2014-09-18 19:21:27 +02:00
|
|
|
if (m_engine) {
|
|
|
|
|
Debugger::RemoteSetupResult result;
|
|
|
|
|
result.success = true;
|
|
|
|
|
result.gdbServerPort = m_pdebugPort;
|
|
|
|
|
result.qmlServerPort = m_qmlPort;
|
|
|
|
|
m_engine->notifyEngineRemoteSetupFinished(result);
|
|
|
|
|
}
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-26 09:02:34 +02:00
|
|
|
void QnxDebugSupport::handleRemoteProcessFinished(bool success)
|
2012-06-29 07:23:13 +02:00
|
|
|
{
|
2013-05-07 11:05:22 +02:00
|
|
|
if (m_engine || state() == Inactive)
|
2012-06-29 07:23:13 +02:00
|
|
|
return;
|
|
|
|
|
|
2013-05-07 11:05:22 +02:00
|
|
|
if (state() == Running) {
|
2012-07-26 09:02:34 +02:00
|
|
|
if (!success)
|
2012-06-29 07:23:13 +02:00
|
|
|
m_engine->notifyInferiorIll();
|
|
|
|
|
|
|
|
|
|
} else {
|
2014-09-18 19:21:27 +02:00
|
|
|
Debugger::RemoteSetupResult result;
|
|
|
|
|
result.success = false;
|
|
|
|
|
result.reason = tr("The %1 process closed unexpectedly.").arg(executable());
|
|
|
|
|
m_engine->notifyEngineRemoteSetupFinished(result);
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::handleDebuggingFinished()
|
|
|
|
|
{
|
2013-11-01 15:39:59 +01:00
|
|
|
// setFinished() will kill "pdebug", but we also have to kill
|
|
|
|
|
// the inferior process, as invoking "kill" in gdb doesn't work
|
|
|
|
|
// on QNX gdb
|
2012-06-29 07:23:13 +02:00
|
|
|
setFinished();
|
2013-11-05 14:29:05 +01:00
|
|
|
m_slog2Info->stop();
|
2013-11-01 15:39:59 +01:00
|
|
|
killInferiorProcess();
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-28 08:14:09 +01:00
|
|
|
QString QnxDebugSupport::executable() const
|
|
|
|
|
{
|
2013-05-07 11:05:22 +02:00
|
|
|
return m_useCppDebugger? QLatin1String(Constants::QNX_DEBUG_EXECUTABLE) : QnxAbstractRunSupport::executable();
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-01 15:39:59 +01:00
|
|
|
void QnxDebugSupport::killInferiorProcess()
|
|
|
|
|
{
|
|
|
|
|
device()->signalOperation()->killProcess(QnxAbstractRunSupport::executable());
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2013-05-07 11:05:22 +02:00
|
|
|
QTC_ASSERT(state() == Inactive || state() == Running, return);
|
2012-06-29 07:23:13 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2013-05-07 11:05:22 +02:00
|
|
|
if (state() == Running) {
|
2012-06-29 07:23:13 +02:00
|
|
|
if (m_engine) {
|
|
|
|
|
m_engine->showMessage(error, Debugger::AppError);
|
|
|
|
|
m_engine->notifyInferiorIll();
|
|
|
|
|
}
|
2013-05-07 11:05:22 +02:00
|
|
|
} else if (state() != Inactive) {
|
2012-06-29 07:23:13 +02:00
|
|
|
setFinished();
|
2014-09-18 19:21:27 +02:00
|
|
|
if (m_engine) {
|
|
|
|
|
Debugger::RemoteSetupResult result;
|
|
|
|
|
result.success = false;
|
|
|
|
|
result.reason = tr("Initial setup failed: %1").arg(error);
|
|
|
|
|
m_engine->notifyEngineRemoteSetupFinished(result);
|
|
|
|
|
}
|
2012-06-29 07:23:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-05 14:29:05 +01:00
|
|
|
|
|
|
|
|
void QnxDebugSupport::printMissingWarning()
|
|
|
|
|
{
|
|
|
|
|
if (m_engine)
|
2014-08-22 13:26:36 +02:00
|
|
|
m_engine->showMessage(tr("Warning: \"slog2info\" is not found on the device, debug output not available."), Debugger::AppError);
|
2013-11-05 14:29:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QnxDebugSupport::handleApplicationOutput(const QString &msg, Utils::OutputFormat outputFormat)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(outputFormat);
|
|
|
|
|
if (m_engine)
|
|
|
|
|
m_engine->showMessage(msg, Debugger::AppOutput);
|
|
|
|
|
}
|