Boot2Qt: Inline QdbDeviceInferiorRunner

Task-number: QTCREATORBUG-29168
Change-Id: I92e133106f3fd851088d01e9bed0bb7ee3cf6171
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-11-21 09:22:12 +01:00
parent bfbe49f81a
commit 076d6581a9

View File

@@ -26,54 +26,38 @@ using namespace Utils;
namespace Qdb::Internal { namespace Qdb::Internal {
class QdbDeviceInferiorRunner : public RunWorker static RunWorker *createQdbDeviceInferiorWorker(RunControl *runControl,
QmlDebugServicesPreset qmlServices)
{ {
public: auto worker = new SimpleTargetRunner(runControl);
QdbDeviceInferiorRunner(RunControl *runControl, QmlDebugServicesPreset qmlServices) worker->setId("QdbDeviceInferiorWorker");
: RunWorker(runControl),
m_qmlServices(qmlServices)
{
setId("QdbDebuggeeRunner");
connect(&m_launcher, &Process::started, this, &RunWorker::reportStarted); worker->setStartModifier([worker, runControl, qmlServices] {
connect(&m_launcher, &Process::done, this, &RunWorker::reportStopped); CommandLine cmd{worker->device()->filePath(Constants::AppcontrollerFilepath)};
connect(&m_launcher, &Process::readyReadStandardOutput, this, [this] {
appendMessage(m_launcher.readAllStandardOutput(), StdOutFormat);
});
connect(&m_launcher, &Process::readyReadStandardError, this, [this] {
appendMessage(m_launcher.readAllStandardError(), StdErrFormat);
});
}
void start() override
{
int lowerPort = 0; int lowerPort = 0;
int upperPort = 0; int upperPort = 0;
CommandLine cmd; if (worker->usesDebugChannel()) {
cmd.setExecutable(device()->filePath(Constants::AppcontrollerFilepath));
if (usesDebugChannel()) {
cmd.addArg("--debug-gdb"); cmd.addArg("--debug-gdb");
lowerPort = upperPort = debugChannel().port(); lowerPort = upperPort = worker->debugChannel().port();
} }
if (usesQmlChannel()) { if (worker->usesQmlChannel()) {
cmd.addArg("--debug-qml"); cmd.addArg("--debug-qml");
cmd.addArg("--qml-debug-services"); cmd.addArg("--qml-debug-services");
cmd.addArg(qmlDebugServices(m_qmlServices)); cmd.addArg(qmlDebugServices(qmlServices));
lowerPort = upperPort = qmlChannel().port(); lowerPort = upperPort = worker->qmlChannel().port();
} }
if (usesDebugChannel() && usesQmlChannel()) { if (worker->usesDebugChannel() && worker->usesQmlChannel()) {
lowerPort = debugChannel().port(); lowerPort = worker->debugChannel().port();
upperPort = qmlChannel().port(); upperPort = worker->qmlChannel().port();
if (lowerPort + 1 != upperPort) { if (lowerPort + 1 != upperPort) {
reportFailure("Need adjacent free ports for combined C++/QML debugging"); worker->reportFailure("Need adjacent free ports for combined C++/QML debugging");
return; return;
} }
} }
if (usesPerfChannel()) { if (worker->usesPerfChannel()) {
const Store perfArgs = runControl()->settingsData(PerfProfiler::Constants::PerfSettingsId); const Store perfArgs = runControl->settingsData(PerfProfiler::Constants::PerfSettingsId);
// appcontroller is not very clear about this, but it expects a comma-separated list of arguments. // appcontroller is not very clear about this, but it expects a comma-separated list of arguments.
// Any literal commas that apper in the args should be escaped by additional commas. // Any literal commas that apper in the args should be escaped by additional commas.
// See the source at // See the source at
@@ -86,24 +70,19 @@ public:
.join(','); .join(',');
cmd.addArg("--profile-perf"); cmd.addArg("--profile-perf");
cmd.addArgs(recordArgs, CommandLine::Raw); cmd.addArgs(recordArgs, CommandLine::Raw);
lowerPort = upperPort = perfChannel().port(); lowerPort = upperPort = worker->perfChannel().port();
} }
cmd.addArg("--port-range"); cmd.addArg("--port-range");
cmd.addArg(QString("%1-%2").arg(lowerPort).arg(upperPort)); cmd.addArg(QString("%1-%2").arg(lowerPort).arg(upperPort));
cmd.addCommandLineAsArgs(runControl()->commandLine()); cmd.addCommandLineAsArgs(runControl->commandLine());
m_launcher.setCommand(cmd); worker->setCommandLine(cmd);
m_launcher.setWorkingDirectory(runControl()->workingDirectory()); worker->setWorkingDirectory(runControl->workingDirectory());
m_launcher.setEnvironment(runControl()->environment()); worker->setEnvironment(runControl->environment());
m_launcher.start(); });
} return worker;
}
void stop() override { m_launcher.close(); }
private:
QmlDebugServicesPreset m_qmlServices;
Process m_launcher;
};
// QdbDeviceDebugSupport // QdbDeviceDebugSupport
@@ -126,7 +105,7 @@ QdbDeviceDebugSupport::QdbDeviceDebugSupport(RunControl *runControl)
if (isQmlDebugging()) if (isQmlDebugging())
runControl->requestQmlChannel(); runControl->requestQmlChannel();
auto debuggee = new QdbDeviceInferiorRunner(runControl, QmlDebuggerServices); auto debuggee = createQdbDeviceInferiorWorker(runControl, QmlDebuggerServices);
addStartDependency(debuggee); addStartDependency(debuggee);
debuggee->addStopDependency(this); debuggee->addStopDependency(this);
@@ -190,7 +169,7 @@ public:
runControl->requestQmlChannel(); runControl->requestQmlChannel();
const QmlDebugServicesPreset services = servicesForRunMode(runControl->runMode()); const QmlDebugServicesPreset services = servicesForRunMode(runControl->runMode());
auto runner = new QdbDeviceInferiorRunner(runControl, services); auto runner = createQdbDeviceInferiorWorker(runControl, services);
worker->addStartDependency(runner); worker->addStartDependency(runner);
worker->addStopDependency(runner); worker->addStopDependency(runner);
@@ -214,7 +193,7 @@ public:
{ {
setProducer([](RunControl *runControl) { setProducer([](RunControl *runControl) {
runControl->requestPerfChannel(); runControl->requestPerfChannel();
auto worker = new QdbDeviceInferiorRunner(runControl, NoQmlDebugServices); auto worker = createQdbDeviceInferiorWorker(runControl, NoQmlDebugServices);
return worker; return worker;
}); });
addSupportedRunMode("PerfRecorder"); addSupportedRunMode("PerfRecorder");