2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2014-02-12 05:58:56 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company
|
2014-02-12 05:58:56 +01:00
|
|
|
** Contact: info@kdab.com
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
**
|
|
|
|
** 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.
|
2014-02-12 05:58:56 +01: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.
|
2014-02-12 05:58:56 +01:00
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "qnxattachdebugsupport.h"
|
|
|
|
|
|
|
|
#include "qnxattachdebugdialog.h"
|
|
|
|
#include "qnxconstants.h"
|
|
|
|
#include "qnxqtversion.h"
|
|
|
|
#include "qnxutils.h"
|
|
|
|
|
|
|
|
#include <debugger/debuggerkitinformation.h>
|
2014-10-17 13:40:04 +02:00
|
|
|
#include <debugger/debuggerruncontrol.h>
|
2014-02-12 05:58:56 +01:00
|
|
|
#include <debugger/debuggerstartparameters.h>
|
|
|
|
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
|
|
|
|
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
|
|
|
|
#include <projectexplorer/devicesupport/deviceprocesslist.h>
|
|
|
|
#include <projectexplorer/kit.h>
|
2015-07-20 12:40:28 +03:00
|
|
|
#include <projectexplorer/kitchooser.h>
|
2014-02-12 05:58:56 +01:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2016-01-27 18:25:13 +01:00
|
|
|
#include <projectexplorer/runnables.h>
|
2014-02-12 05:58:56 +01:00
|
|
|
#include <projectexplorer/toolchain.h>
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
#include <utils/portlist.h>
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
2016-01-23 10:37:02 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
namespace Qnx {
|
|
|
|
namespace Internal {
|
2014-02-12 05:58:56 +01:00
|
|
|
|
|
|
|
QnxAttachDebugSupport::QnxAttachDebugSupport(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
2017-03-09 14:13:13 +01:00
|
|
|
m_launcher = new ApplicationLauncher(this);
|
2016-01-23 10:37:02 +01:00
|
|
|
m_portsGatherer = new DeviceUsedPortsGatherer(this);
|
|
|
|
|
|
|
|
connect(m_portsGatherer, &DeviceUsedPortsGatherer::portListReady,
|
|
|
|
this, &QnxAttachDebugSupport::launchPDebug);
|
|
|
|
connect(m_portsGatherer, &DeviceUsedPortsGatherer::error,
|
|
|
|
this, &QnxAttachDebugSupport::handleError);
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(m_launcher, &ApplicationLauncher::remoteProcessStarted,
|
2016-01-23 10:37:02 +01:00
|
|
|
this, &QnxAttachDebugSupport::attachToProcess);
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(m_launcher, &ApplicationLauncher::reportError,
|
2016-01-23 10:37:02 +01:00
|
|
|
this, &QnxAttachDebugSupport::handleError);
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(m_launcher, &ApplicationLauncher::reportProgress,
|
2016-01-23 10:37:02 +01:00
|
|
|
this, &QnxAttachDebugSupport::handleProgressReport);
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(m_launcher, &ApplicationLauncher::remoteStdout,
|
2016-01-23 10:37:02 +01:00
|
|
|
this, &QnxAttachDebugSupport::handleRemoteOutput);
|
2017-03-09 14:13:13 +01:00
|
|
|
connect(m_launcher, &ApplicationLauncher::remoteStderr,
|
2016-01-23 10:37:02 +01:00
|
|
|
this, &QnxAttachDebugSupport::handleRemoteOutput);
|
2014-02-12 05:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QnxAttachDebugSupport::showProcessesDialog()
|
|
|
|
{
|
2016-01-23 10:37:02 +01:00
|
|
|
auto kitChooser = new KitChooser;
|
2017-01-11 17:25:58 +01:00
|
|
|
kitChooser->setKitPredicate([](const Kit *k){
|
2016-01-23 10:37:02 +01:00
|
|
|
return k->isValid() && DeviceTypeKitInformation::deviceTypeId(k) == Core::Id(Constants::QNX_QNX_OS_TYPE);
|
2015-07-20 12:40:28 +03:00
|
|
|
});
|
|
|
|
|
2014-02-12 05:58:56 +01:00
|
|
|
QnxAttachDebugDialog dlg(kitChooser, 0);
|
2016-01-23 10:37:02 +01:00
|
|
|
dlg.addAcceptButton(DeviceProcessesDialog::tr("&Attach to Process"));
|
2014-02-12 05:58:56 +01:00
|
|
|
dlg.showAllDevices();
|
|
|
|
if (dlg.exec() == QDialog::Rejected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_kit = kitChooser->currentKit();
|
|
|
|
if (!m_kit)
|
|
|
|
return;
|
|
|
|
|
2016-01-23 10:37:02 +01:00
|
|
|
m_device = DeviceKitInformation::device(m_kit);
|
2014-02-12 05:58:56 +01:00
|
|
|
QTC_ASSERT(m_device, return);
|
|
|
|
m_process = dlg.currentProcess();
|
|
|
|
|
|
|
|
m_projectSourceDirectory = dlg.projectSource();
|
|
|
|
m_localExecutablePath = dlg.localExecutable();
|
|
|
|
|
|
|
|
m_portsGatherer->start(m_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QnxAttachDebugSupport::launchPDebug()
|
|
|
|
{
|
|
|
|
Utils::PortList portList = m_device->freePorts();
|
|
|
|
m_pdebugPort = m_portsGatherer->getNextFreePort(&portList);
|
2016-04-19 16:43:30 +02:00
|
|
|
if (!m_pdebugPort.isValid()) {
|
2014-02-12 05:58:56 +01:00
|
|
|
handleError(tr("No free ports for debugging."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-27 18:25:13 +01:00
|
|
|
StandardRunnable r;
|
|
|
|
r.executable = QLatin1String("pdebug");
|
2016-04-19 16:43:30 +02:00
|
|
|
r.commandLineArguments = QString::number(m_pdebugPort.number());
|
2017-03-09 14:13:13 +01:00
|
|
|
m_launcher->start(r, m_device);
|
2014-02-12 05:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QnxAttachDebugSupport::attachToProcess()
|
|
|
|
{
|
|
|
|
Debugger::DebuggerStartParameters sp;
|
2017-02-27 13:30:08 +01:00
|
|
|
sp.attachPID = Utils::ProcessHandle(m_process.pid);
|
2014-02-12 05:58:56 +01:00
|
|
|
sp.startMode = Debugger::AttachToRemoteServer;
|
|
|
|
sp.closeMode = Debugger::DetachAtClose;
|
2016-04-19 16:43:30 +02:00
|
|
|
sp.connParams.port = m_pdebugPort.number();
|
|
|
|
sp.remoteChannel = m_device->sshParameters().host + QLatin1Char(':') +
|
|
|
|
QString::number(m_pdebugPort.number());
|
|
|
|
sp.displayName = tr("Remote: \"%1:%2\" - Process %3").arg(sp.connParams.host)
|
|
|
|
.arg(m_pdebugPort.number()).arg(m_process.pid);
|
2016-01-28 10:31:24 +01:00
|
|
|
sp.inferior.executable = m_localExecutablePath;
|
2014-02-12 05:58:56 +01:00
|
|
|
sp.useCtrlCStub = true;
|
|
|
|
|
|
|
|
QnxQtVersion *qtVersion = dynamic_cast<QnxQtVersion *>(QtSupport::QtKitInformation::qtVersion(m_kit));
|
|
|
|
if (qtVersion)
|
|
|
|
sp.solibSearchPath = QnxUtils::searchPaths(qtVersion);
|
|
|
|
|
|
|
|
QString errorMessage;
|
2015-06-26 13:06:08 +02:00
|
|
|
Debugger::DebuggerRunControl *runControl = Debugger::createDebuggerRunControl(sp, 0, &errorMessage);
|
2014-02-12 05:58:56 +01:00
|
|
|
if (!errorMessage.isEmpty()) {
|
|
|
|
handleError(errorMessage);
|
|
|
|
stopPDebug();
|
|
|
|
return;
|
|
|
|
}
|
2016-07-15 13:48:24 +02:00
|
|
|
if (!runControl) {
|
|
|
|
handleError(tr("Attaching failed."));
|
|
|
|
stopPDebug();
|
|
|
|
return;
|
|
|
|
}
|
2014-12-12 15:33:16 +01:00
|
|
|
connect(runControl, &Debugger::DebuggerRunControl::stateChanged,
|
|
|
|
this, &QnxAttachDebugSupport::handleDebuggerStateChanged);
|
2017-04-11 14:36:03 +02:00
|
|
|
ProjectExplorerPlugin::startRunControl(runControl);
|
2014-02-12 05:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QnxAttachDebugSupport::handleDebuggerStateChanged(Debugger::DebuggerState state)
|
|
|
|
{
|
|
|
|
if (state == Debugger::DebuggerFinished)
|
|
|
|
stopPDebug();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QnxAttachDebugSupport::handleError(const QString &message)
|
|
|
|
{
|
2014-12-12 15:33:16 +01:00
|
|
|
if (m_runControl)
|
|
|
|
m_runControl->showMessage(message, Debugger::AppError);
|
2014-02-12 05:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QnxAttachDebugSupport::handleProgressReport(const QString &message)
|
|
|
|
{
|
2014-12-12 15:33:16 +01:00
|
|
|
if (m_runControl)
|
|
|
|
m_runControl->showMessage(message + QLatin1Char('\n'), Debugger::AppStuff);
|
2014-02-12 05:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QnxAttachDebugSupport::handleRemoteOutput(const QByteArray &output)
|
|
|
|
{
|
2014-12-12 15:33:16 +01:00
|
|
|
if (m_runControl)
|
|
|
|
m_runControl->showMessage(QString::fromUtf8(output), Debugger::AppOutput);
|
2014-02-12 05:58:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QnxAttachDebugSupport::stopPDebug()
|
|
|
|
{
|
2017-03-09 14:13:13 +01:00
|
|
|
m_launcher->stop();
|
2014-02-12 05:58:56 +01:00
|
|
|
}
|
2016-01-23 10:37:02 +01:00
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
} // namespace Qnx
|