Commit afc39c4c authored by hjk's avatar hjk

Qnx: Merge debug support related files

The attach part has not been active for a while, but there's code
now easier to reuse. So move participants of a potential solution
to a suitable place before attempting to fix functionality.

Change-Id: I9a7d4a6637e8ef214c22ee5683103e464109210d
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent 890c1906
......@@ -23,8 +23,6 @@ SOURCES += qnxplugin.cpp \
qnxdeviceprocesslist.cpp \
qnxtoolchain.cpp \
slog2inforunner.cpp \
qnxattachdebugsupport.cpp \
qnxattachdebugdialog.cpp \
qnxconfiguration.cpp \
qnxsettingswidget.cpp \
qnxconfigurationmanager.cpp \
......@@ -55,8 +53,6 @@ HEADERS += qnxplugin.h\
qnxdeviceprocesslist.h \
qnxtoolchain.h \
slog2inforunner.h \
qnxattachdebugsupport.h \
qnxattachdebugdialog.h \
qnxconfiguration.h \
qnxsettingswidget.h \
qnxconfigurationmanager.h \
......
......@@ -24,10 +24,6 @@ QtcPlugin {
"qnxtoolchain.cpp",
"qnxtoolchain.h",
"qnx.qrc",
"qnxattachdebugsupport.cpp",
"qnxattachdebugsupport.h",
"qnxattachdebugdialog.cpp",
"qnxattachdebugdialog.h",
"qnxbaseqtconfigwidget.cpp",
"qnxbaseqtconfigwidget.h",
"qnxconstants.h",
......
/****************************************************************************
**
** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company
** 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
** 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.
**
** 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.
**
****************************************************************************/
#include "qnxattachdebugdialog.h"
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
#include <QFormLayout>
#include <QLabel>
#include <QVBoxLayout>
using namespace Qnx;
using namespace Qnx::Internal;
QnxAttachDebugDialog::QnxAttachDebugDialog(ProjectExplorer::KitChooser *kitChooser, QWidget *parent)
: ProjectExplorer::DeviceProcessesDialog(kitChooser, parent)
{
auto sourceLabel = new QLabel(tr("Project source directory:"), this);
m_projectSource = new Utils::PathChooser(this);
m_projectSource->setExpectedKind(Utils::PathChooser::ExistingDirectory);
auto binaryLabel = new QLabel(tr("Local executable:"), this);
m_localExecutable = new Utils::PathChooser(this);
m_localExecutable->setExpectedKind(Utils::PathChooser::File);
auto formLayout = new QFormLayout;
formLayout->addRow(sourceLabel, m_projectSource);
formLayout->addRow(binaryLabel, m_localExecutable);
auto mainLayout = dynamic_cast<QVBoxLayout*>(layout());
QTC_ASSERT(mainLayout, return);
mainLayout->insertLayout(mainLayout->count() - 2, formLayout);
}
QString QnxAttachDebugDialog::projectSource() const
{
return m_projectSource->path();
}
QString QnxAttachDebugDialog::localExecutable() const
{
return m_localExecutable->path();
}
/****************************************************************************
**
** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company
** 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
** 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
namespace Utils { class PathChooser; }
namespace Qnx {
namespace Internal {
class QnxAttachDebugDialog : public ProjectExplorer::DeviceProcessesDialog
{
Q_OBJECT
public:
explicit QnxAttachDebugDialog(ProjectExplorer::KitChooser *kitChooser, QWidget *parent = 0);
QString projectSource() const;
QString localExecutable() const;
private:
Utils::PathChooser *m_projectSource;
Utils::PathChooser *m_localExecutable;
};
} // namespace Internal
} // namespace Qnx
/****************************************************************************
**
** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company
** 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
** 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.
**
** 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.
**
****************************************************************************/
#include "qnxattachdebugsupport.h"
#include "qnxattachdebugdialog.h"
#include "qnxconstants.h"
#include "qnxqtversion.h"
#include "qnxutils.h"
#include <debugger/debuggerkitinformation.h>
#include <debugger/debuggerruncontrol.h>
#include <debugger/debuggerstartparameters.h>
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
#include <projectexplorer/devicesupport/deviceprocesslist.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/kitchooser.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/runnables.h>
#include <projectexplorer/toolchain.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/portlist.h>
#include <utils/qtcassert.h>
using namespace ProjectExplorer;
namespace Qnx {
namespace Internal {
QnxAttachDebugSupport::QnxAttachDebugSupport(QObject *parent)
: QObject(parent)
{
m_launcher = new ApplicationLauncher(this);
m_portsGatherer = new DeviceUsedPortsGatherer(this);
connect(m_portsGatherer, &DeviceUsedPortsGatherer::portListReady,
this, &QnxAttachDebugSupport::launchPDebug);
connect(m_portsGatherer, &DeviceUsedPortsGatherer::error,
this, &QnxAttachDebugSupport::handleError);
connect(m_launcher, &ApplicationLauncher::remoteProcessStarted,
this, &QnxAttachDebugSupport::attachToProcess);
connect(m_launcher, &ApplicationLauncher::reportError,
this, &QnxAttachDebugSupport::handleError);
connect(m_launcher, &ApplicationLauncher::reportProgress,
this, &QnxAttachDebugSupport::handleProgressReport);
connect(m_launcher, &ApplicationLauncher::remoteStdout,
this, &QnxAttachDebugSupport::handleRemoteOutput);
connect(m_launcher, &ApplicationLauncher::remoteStderr,
this, &QnxAttachDebugSupport::handleRemoteOutput);
}
void QnxAttachDebugSupport::showProcessesDialog()
{
auto kitChooser = new KitChooser;
kitChooser->setKitPredicate([](const Kit *k){
return k->isValid() && DeviceTypeKitInformation::deviceTypeId(k) == Core::Id(Constants::QNX_QNX_OS_TYPE);
});
QnxAttachDebugDialog dlg(kitChooser, 0);
dlg.addAcceptButton(DeviceProcessesDialog::tr("&Attach to Process"));
dlg.showAllDevices();
if (dlg.exec() == QDialog::Rejected)
return;
m_kit = kitChooser->currentKit();
if (!m_kit)
return;
m_device = DeviceKitInformation::device(m_kit);
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);
if (!m_pdebugPort.isValid()) {
handleError(tr("No free ports for debugging."));
return;
}
StandardRunnable r;
r.executable = QLatin1String("pdebug");
r.commandLineArguments = QString::number(m_pdebugPort.number());
m_launcher->start(r, m_device);
}
void QnxAttachDebugSupport::attachToProcess()
{
Debugger::DebuggerStartParameters sp;
sp.attachPID = Utils::ProcessHandle(m_process.pid);
sp.startMode = Debugger::AttachToRemoteServer;
sp.closeMode = Debugger::DetachAtClose;
sp.remoteChannel = QString("%1:%2").arg(m_device->sshParameters().host).arg(m_pdebugPort.number());
sp.displayName = tr("Remote: \"%1\" - Process %2").arg(sp.remoteChannel).arg(m_process.pid);
sp.inferior.executable = m_localExecutablePath;
sp.useCtrlCStub = true;
QnxQtVersion *qtVersion = dynamic_cast<QnxQtVersion *>(QtSupport::QtKitInformation::qtVersion(m_kit));
if (qtVersion)
sp.solibSearchPath = QnxUtils::searchPaths(qtVersion);
auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE);
auto debugger = new Debugger::DebuggerRunTool(runControl);
debugger->setRunParameters(sp);
// connect(qobject_cast<Debugger::DebuggerRunTool *>(runControl->toolRunner()),
// &Debugger::DebuggerRunTool::stateChanged,
// this, &QnxAttachDebugSupport::handleDebuggerStateChanged);
debugger->startRunControl();
}
void QnxAttachDebugSupport::handleDebuggerStateChanged(Debugger::DebuggerState state)
{
if (state == Debugger::DebuggerFinished)
stopPDebug();
}
void QnxAttachDebugSupport::handleError(const QString &message)
{
if (m_runTool)
m_runTool->showMessage(message, Debugger::AppError);
}
void QnxAttachDebugSupport::handleProgressReport(const QString &message)
{
if (m_runTool)
m_runTool->showMessage(message + QLatin1Char('\n'), Debugger::AppStuff);
}
void QnxAttachDebugSupport::handleRemoteOutput(const QString &output)
{
if (m_runTool)
m_runTool->showMessage(output, Debugger::AppOutput);
}
void QnxAttachDebugSupport::stopPDebug()
{
m_launcher->stop();
}
} // namespace Internal
} // namespace Qnx
/****************************************************************************
**
** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company
** 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
** 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include <debugger/debuggerconstants.h>
#include <projectexplorer/devicesupport/deviceprocesslist.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <utils/port.h>
#include <QObject>
namespace Debugger { class DebuggerRunTool; }
namespace ProjectExplorer {
class ApplicationLauncher;
class DeviceUsedPortsGatherer;
class Kit;
}
namespace Qnx {
namespace Internal {
class QnxAttachDebugSupport : public QObject
{
Q_OBJECT
public:
explicit QnxAttachDebugSupport(QObject *parent = 0);
public slots:
void showProcessesDialog();
private slots:
void launchPDebug();
void attachToProcess();
void handleDebuggerStateChanged(Debugger::DebuggerState state);
void handleError(const QString &message);
void handleProgressReport(const QString &message);
void handleRemoteOutput(const QString &output);
private:
void stopPDebug();
ProjectExplorer::Kit *m_kit = 0;
ProjectExplorer::IDevice::ConstPtr m_device;
ProjectExplorer::DeviceProcessItem m_process;
ProjectExplorer::ApplicationLauncher *m_launcher;
ProjectExplorer::DeviceUsedPortsGatherer *m_portsGatherer;
Debugger::DebuggerRunTool *m_runTool = 0;
Utils::Port m_pdebugPort;
QString m_projectSourceDirectory;
QString m_localExecutablePath;
};
} // namespace Internal
} // namespace Qnx
This diff is collapsed.
......@@ -27,6 +27,8 @@
#include <debugger/debuggerruncontrol.h>
#include <utils/port.h>
namespace Qnx {
namespace Internal {
......@@ -43,5 +45,35 @@ private:
Debugger::GdbServerPortsGatherer *m_portsGatherer;
};
class QnxAttachDebugSupport : public Debugger::DebuggerRunTool
{
Q_OBJECT
public:
explicit QnxAttachDebugSupport(ProjectExplorer::RunControl *runControl);
static void showProcessesDialog();
private:
void start() final;
void launchPDebug();
void attachToProcess();
void handleDebuggerStateChanged(Debugger::DebuggerState state);
void handleError(const QString &message);
void handleProgressReport(const QString &message);
void handleRemoteOutput(const QString &output);
void stopPDebug();
Debugger::GdbServerPortsGatherer *m_portsGatherer;
ProjectExplorer::SimpleTargetRunner *m_pdebugRunner;
Utils::Port m_pdebugPort;
QString m_projectSourceDirectory;
QString m_localExecutablePath;
};
} // namespace Internal
} // namespace Qnx
......@@ -26,7 +26,6 @@
#include "qnxplugin.h"
#include "qnxanalyzesupport.h"
#include "qnxattachdebugsupport.h"
#include "qnxconfigurationmanager.h"
#include "qnxconstants.h"
#include "qnxdebugsupport.h"
......@@ -108,12 +107,10 @@ bool QnxPlugin::initialize(const QStringList &arguments, QString *errorString)
void QnxPlugin::extensionsInitialized()
{
// Debug support
QnxAttachDebugSupport *debugSupport = new QnxAttachDebugSupport(this);
// Attach support
m_attachToQnxApplication = new QAction(this);
m_attachToQnxApplication->setText(tr("Attach to remote QNX application..."));
connect(m_attachToQnxApplication, &QAction::triggered, debugSupport, &QnxAttachDebugSupport::showProcessesDialog);
connect(m_attachToQnxApplication, &QAction::triggered, this, [] { QnxAttachDebugSupport::showProcessesDialog(); });
Core::ActionContainer *mstart = Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_DEBUG_STARTDEBUGGING);
mstart->appendGroup(Constants::QNX_DEBUGGING_GROUP);
......
......@@ -73,27 +73,6 @@ QString QnxUtils::cpuDirShortDescription(const QString &cpuDir)
return cpuDir;
}
QStringList QnxUtils::searchPaths(QnxQtVersion *qtVersion)
{
const QDir pluginDir(qtVersion->qmakeProperty("QT_INSTALL_PLUGINS"));
const QStringList pluginSubDirs = pluginDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
QStringList searchPaths;
Q_FOREACH (const QString &dir, pluginSubDirs) {
searchPaths << qtVersion->qmakeProperty("QT_INSTALL_PLUGINS")
+ QLatin1Char('/') + dir;
}
searchPaths << qtVersion->qmakeProperty("QT_INSTALL_LIBS");
searchPaths << qtVersion->qnxTarget() + QLatin1Char('/') + qtVersion->cpuDir()
+ QLatin1String("/lib");
searchPaths << qtVersion->qnxTarget() + QLatin1Char('/') + qtVersion->cpuDir()
+ QLatin1String("/usr/lib");
return searchPaths;
}
QList<Utils::EnvironmentItem> QnxUtils::qnxEnvironmentFromEnvFile(const QString &fileName)
{
QList <Utils::EnvironmentItem> items;
......
......@@ -70,7 +70,6 @@ class QnxUtils
public:
static QString addQuotes(const QString &string);
static QString cpuDirShortDescription(const QString &cpuDir);
static QStringList searchPaths(Qnx::Internal::QnxQtVersion *qtVersion);
static QList<Utils::EnvironmentItem> qnxEnvironmentFromEnvFile(const QString &fileName);
static QString envFilePath(const QString &sdpPath);
static QString defaultTargetVersion(const QString &sdpPath);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment