forked from qt-creator/qt-creator
ProjectExplorer: Split Target and ToolRunners into smaller tasks
This increases re-usability of activities like 'port gathering', and makes their use less dependent on actual device implementations. Change-Id: I017cb74874f2b38c487ba2d03906a675d5618647 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -28,182 +28,123 @@
|
||||
#include "qnxdevice.h"
|
||||
#include "qnxrunconfiguration.h"
|
||||
#include "slog2inforunner.h"
|
||||
#include "qnxqtversion.h"
|
||||
#include "qnxutils.h"
|
||||
|
||||
#include <debugger/debuggerrunconfigurationaspect.h>
|
||||
#include <debugger/debuggerruncontrol.h>
|
||||
#include <debugger/debuggerstartparameters.h>
|
||||
|
||||
#include <projectexplorer/applicationlauncher.h>
|
||||
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/runnables.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
#include <qmldebug/qmldebugcommandlinearguments.h>
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <qmldebug/qmldebugcommandlinearguments.h>
|
||||
|
||||
using namespace Debugger;
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace Qnx {
|
||||
namespace Internal {
|
||||
|
||||
QnxDebugSupport::QnxDebugSupport(RunControl *runControl)
|
||||
: QnxAbstractRunSupport(runControl)
|
||||
// QnxDebuggeeRunner
|
||||
|
||||
class QnxDebuggeeRunner : public ProjectExplorer::SimpleTargetRunner
|
||||
{
|
||||
auto runConfig = runControl->runConfiguration();
|
||||
m_useCppDebugger = runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>()->useCppDebugger();
|
||||
m_useQmlDebugger = runConfig->extraAspect<Debugger::DebuggerRunConfigurationAspect>()->useQmlDebugger();
|
||||
m_runnable = runConfig->runnable().as<StandardRunnable>();
|
||||
public:
|
||||
QnxDebuggeeRunner(ProjectExplorer::RunControl *runControl)
|
||||
: SimpleTargetRunner(runControl)
|
||||
{
|
||||
setDisplayName("QnxDebuggeeRunner");
|
||||
}
|
||||
|
||||
const ApplicationLauncher *runner = appRunner();
|
||||
connect(runner, &ApplicationLauncher::reportError, this, &QnxDebugSupport::handleError);
|
||||
connect(runner, &ApplicationLauncher::remoteProcessStarted, this, &QnxDebugSupport::handleRemoteProcessStarted);
|
||||
connect(runner, &ApplicationLauncher::finished, this, &QnxDebugSupport::handleRemoteProcessFinished);
|
||||
connect(runner, &ApplicationLauncher::reportProgress, this, &QnxDebugSupport::handleProgressReport);
|
||||
connect(runner, &ApplicationLauncher::remoteStdout, this, &QnxDebugSupport::handleRemoteOutput);
|
||||
connect(runner, &ApplicationLauncher::remoteStderr, this, &QnxDebugSupport::handleRemoteOutput);
|
||||
private:
|
||||
void start() override
|
||||
{
|
||||
auto portsGatherer = runControl()->worker<GdbServerPortsGatherer>();
|
||||
|
||||
connect(toolRunner(), &Debugger::DebuggerRunTool::requestRemoteSetup,
|
||||
this, &QnxDebugSupport::handleAdapterSetupRequested);
|
||||
connect(runControl, &RunControl::finished,
|
||||
this, &QnxDebugSupport::handleDebuggingFinished);
|
||||
|
||||
auto qnxRunConfig = qobject_cast<QnxRunConfiguration *>(runControl->runConfiguration());
|
||||
const QString applicationId = Utils::FileName::fromString(qnxRunConfig->remoteExecutableFilePath()).fileName();
|
||||
IDevice::ConstPtr dev = DeviceKitInformation::device(runConfig->target()->kit());
|
||||
QnxDevice::ConstPtr qnxDevice = dev.dynamicCast<const QnxDevice>();
|
||||
|
||||
m_slog2Info = new Slog2InfoRunner(applicationId, qnxDevice, this);
|
||||
connect(m_slog2Info, &Slog2InfoRunner::output, this, &QnxDebugSupport::handleApplicationOutput);
|
||||
connect(runner, &ApplicationLauncher::remoteProcessStarted, m_slog2Info, &Slog2InfoRunner::start);
|
||||
if (qnxDevice->qnxVersion() > 0x060500)
|
||||
connect(m_slog2Info, &Slog2InfoRunner::commandMissing, this, &QnxDebugSupport::printMissingWarning);
|
||||
}
|
||||
|
||||
void QnxDebugSupport::handleAdapterSetupRequested()
|
||||
{
|
||||
QTC_ASSERT(state() == Inactive, return);
|
||||
|
||||
toolRunner()->showMessage(tr("Preparing remote side...") + '\n', Debugger::AppStuff);
|
||||
QnxAbstractRunSupport::handleAdapterSetupRequested();
|
||||
}
|
||||
|
||||
void QnxDebugSupport::startExecution()
|
||||
{
|
||||
if (state() == Inactive)
|
||||
return;
|
||||
|
||||
if (m_useCppDebugger && !setPort(m_pdebugPort))
|
||||
return;
|
||||
if (m_useQmlDebugger && !setPort(m_qmlPort))
|
||||
return;
|
||||
|
||||
setState(StartingRemoteProcess);
|
||||
|
||||
StandardRunnable r = m_runnable;
|
||||
QStringList arguments;
|
||||
if (m_useCppDebugger)
|
||||
arguments << QString::number(m_pdebugPort.number());
|
||||
else {
|
||||
if (m_useQmlDebugger) {
|
||||
StandardRunnable r = runnable().as<StandardRunnable>();
|
||||
QStringList arguments;
|
||||
if (portsGatherer->useGdbServer()) {
|
||||
Utils::Port pdebugPort = portsGatherer->gdbServerPort();
|
||||
r.executable = Constants::QNX_DEBUG_EXECUTABLE;
|
||||
arguments.append(pdebugPort.toString());
|
||||
}
|
||||
if (portsGatherer->useQmlServer()) {
|
||||
arguments.append(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices,
|
||||
m_qmlPort));
|
||||
portsGatherer->qmlServerPort()));
|
||||
}
|
||||
arguments.append(Utils::QtcProcess::splitArgs(r.commandLineArguments));
|
||||
r.commandLineArguments = Utils::QtcProcess::joinArgs(arguments);
|
||||
|
||||
SimpleTargetRunner::start();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// QnxDebugSupport
|
||||
|
||||
QnxDebugSupport::QnxDebugSupport(RunControl *runControl)
|
||||
: DebuggerRunTool(runControl)
|
||||
{
|
||||
setDisplayName("QnxDebugSupport");
|
||||
appendMessage(tr("Preparing remote side..."), Utils::LogMessageFormat);
|
||||
|
||||
auto portsGatherer = new GdbServerPortsGatherer(runControl);
|
||||
portsGatherer->setUseGdbServer(isCppDebugging());
|
||||
portsGatherer->setUseQmlServer(isQmlDebugging());
|
||||
|
||||
auto debuggeeRunner = new QnxDebuggeeRunner(runControl);
|
||||
debuggeeRunner->addDependency(portsGatherer);
|
||||
|
||||
auto slog2InfoRunner = new Slog2InfoRunner(runControl);
|
||||
slog2InfoRunner->addDependency(debuggeeRunner);
|
||||
|
||||
addDependency(slog2InfoRunner);
|
||||
}
|
||||
|
||||
void QnxDebugSupport::start()
|
||||
{
|
||||
auto portsGatherer = runControl()->worker<GdbServerPortsGatherer>();
|
||||
Utils::Port pdebugPort = portsGatherer->gdbServerPort();
|
||||
|
||||
auto runConfig = qobject_cast<QnxRunConfiguration *>(runControl()->runConfiguration());
|
||||
QTC_ASSERT(runConfig, return);
|
||||
Target *target = runConfig->target();
|
||||
Kit *k = target->kit();
|
||||
|
||||
DebuggerStartParameters params;
|
||||
params.startMode = AttachToRemoteServer;
|
||||
params.useCtrlCStub = true;
|
||||
params.inferior.executable = runConfig->remoteExecutableFilePath();
|
||||
params.symbolFile = runConfig->localExecutableFilePath();
|
||||
params.remoteChannel = QString("%1:%2").arg(device()->sshParameters().host).arg(pdebugPort.number());
|
||||
params.closeMode = KillAtClose;
|
||||
params.inferior.commandLineArguments = runConfig->arguments();
|
||||
|
||||
if (isQmlDebugging()) {
|
||||
params.qmlServer.host = device()->sshParameters().host;
|
||||
params.qmlServer.port = portsGatherer->qmlServerPort();
|
||||
params.inferior.commandLineArguments.replace("%qml_port%", params.qmlServer.port.toString());
|
||||
}
|
||||
|
||||
r.executable = processExecutable();
|
||||
r.commandLineArguments = Utils::QtcProcess::joinArgs(arguments);
|
||||
r.environment = m_runnable.environment;
|
||||
r.workingDirectory = m_runnable.workingDirectory;
|
||||
appRunner()->start(r, device());
|
||||
auto qtVersion = dynamic_cast<QnxQtVersion *>(QtSupport::QtKitInformation::qtVersion(k));
|
||||
if (qtVersion)
|
||||
params.solibSearchPath = QnxUtils::searchPaths(qtVersion);
|
||||
|
||||
reportStarted();
|
||||
}
|
||||
|
||||
void QnxDebugSupport::handleRemoteProcessStarted()
|
||||
void QnxDebugSupport::stop()
|
||||
{
|
||||
QnxAbstractRunSupport::handleRemoteProcessStarted();
|
||||
Debugger::RemoteSetupResult result;
|
||||
result.success = true;
|
||||
result.gdbServerPort = m_pdebugPort;
|
||||
result.qmlServerPort = m_qmlPort;
|
||||
toolRunner()->notifyEngineRemoteSetupFinished(result);
|
||||
}
|
||||
|
||||
void QnxDebugSupport::handleRemoteProcessFinished(bool success)
|
||||
{
|
||||
if (state() == Inactive)
|
||||
return;
|
||||
|
||||
if (state() == Running) {
|
||||
if (!success)
|
||||
toolRunner()->notifyInferiorIll();
|
||||
|
||||
} else {
|
||||
Debugger::RemoteSetupResult result;
|
||||
result.success = false;
|
||||
result.reason = tr("The %1 process closed unexpectedly.").arg(processExecutable());
|
||||
toolRunner()->notifyEngineRemoteSetupFinished(result);
|
||||
}
|
||||
}
|
||||
|
||||
void QnxDebugSupport::handleDebuggingFinished()
|
||||
{
|
||||
// setFinished() will kill "pdebug", but we also have to kill
|
||||
// the inferior process, as invoking "kill" in gdb doesn't work
|
||||
// on QNX gdb
|
||||
setFinished();
|
||||
m_slog2Info->stop();
|
||||
killInferiorProcess();
|
||||
}
|
||||
|
||||
QString QnxDebugSupport::processExecutable() const
|
||||
{
|
||||
return m_useCppDebugger? QLatin1String(Constants::QNX_DEBUG_EXECUTABLE) : m_runnable.executable;
|
||||
}
|
||||
|
||||
void QnxDebugSupport::killInferiorProcess()
|
||||
{
|
||||
device()->signalOperation()->killProcess(m_runnable.executable);
|
||||
}
|
||||
|
||||
void QnxDebugSupport::handleProgressReport(const QString &progressOutput)
|
||||
{
|
||||
toolRunner()->showMessage(progressOutput + QLatin1Char('\n'), Debugger::AppStuff);
|
||||
}
|
||||
|
||||
void QnxDebugSupport::handleRemoteOutput(const QByteArray &output)
|
||||
{
|
||||
QTC_ASSERT(state() == Inactive || state() == Running, return);
|
||||
toolRunner()->showMessage(QString::fromUtf8(output), Debugger::AppOutput);
|
||||
}
|
||||
|
||||
void QnxDebugSupport::handleError(const QString &error)
|
||||
{
|
||||
if (state() == Running) {
|
||||
toolRunner()->showMessage(error, Debugger::AppError);
|
||||
toolRunner()->notifyInferiorIll();
|
||||
} else if (state() != Inactive) {
|
||||
setFinished();
|
||||
Debugger::RemoteSetupResult result;
|
||||
result.success = false;
|
||||
result.reason = tr("Initial setup failed: %1").arg(error);
|
||||
toolRunner()->notifyEngineRemoteSetupFinished(result);
|
||||
}
|
||||
}
|
||||
|
||||
void QnxDebugSupport::printMissingWarning()
|
||||
{
|
||||
toolRunner()->showMessage(tr("Warning: \"slog2info\" is not found "
|
||||
"on the device, debug output not available."), Debugger::AppError);
|
||||
}
|
||||
|
||||
void QnxDebugSupport::handleApplicationOutput(const QString &msg, Utils::OutputFormat outputFormat)
|
||||
{
|
||||
Q_UNUSED(outputFormat);
|
||||
toolRunner()->showMessage(msg, Debugger::AppOutput);
|
||||
}
|
||||
|
||||
Debugger::DebuggerRunTool *QnxDebugSupport::toolRunner()
|
||||
{
|
||||
return qobject_cast<Debugger::DebuggerRunTool *>(runControl()->toolRunner());
|
||||
// We have to kill the inferior process, as invoking "kill" in
|
||||
// gdb doesn't work on QNX gdb.
|
||||
auto stdRunnable = runnable().as<StandardRunnable>();
|
||||
device()->signalOperation()->killProcess(stdRunnable.executable);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user