Debugger: Introduce createDebuggerWorker and reuse it

Task-number: QTCREATORBUG-29168
Change-Id: I101fdc1589d36ff996eef12308cf4165143b04af
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2025-04-16 18:20:49 +02:00
parent 4a974cb655
commit be69da2066
15 changed files with 149 additions and 120 deletions

View File

@@ -88,15 +88,12 @@ public:
AndroidDebugWorkerFactory() AndroidDebugWorkerFactory()
{ {
setProducer([](RunControl *runControl) { setProducer([](RunControl *runControl) {
DebuggerRunTool *debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
debugger->setId("AndroidDebugger");
DebuggerRunParameters &rp = debugger->runParameters();
rp.setupPortsGatherer(runControl); rp.setupPortsGatherer(runControl);
rp.setSkipDebugServer(true); rp.setSkipDebugServer(true);
rp.setLldbPlatform("remote-android"); rp.setLldbPlatform("remote-android");
auto androidRunner = new RecipeRunner(runControl, androidRecipe(runControl)); auto androidRunner = new RecipeRunner(runControl, androidRecipe(runControl));
debugger->addStartDependency(androidRunner);
BuildConfiguration *bc = runControl->buildConfiguration(); BuildConfiguration *bc = runControl->buildConfiguration();
Kit *kit = runControl->kit(); Kit *kit = runControl->kit();
@@ -161,6 +158,9 @@ public:
if (qtVersion) if (qtVersion)
rp.addSearchDirectory(qtVersion->qmlPath()); rp.addSearchDirectory(qtVersion->qmlPath());
} }
auto debugger = createDebuggerWorker(runControl, rp);
debugger->addStartDependency(androidRunner);
QObject::connect(debugger, &RunWorker::started, debugger, [runControl, packageName] { QObject::connect(debugger, &RunWorker::started, debugger, [runControl, packageName] {
qCDebug(androidDebugSupportLog) << "Starting debugger - package name: " << packageName qCDebug(androidDebugSupportLog) << "Starting debugger - package name: " << packageName
<< ", PID: " << runControl->attachPid().pid(); << ", PID: " << runControl->attachPid().pid();

View File

@@ -45,6 +45,7 @@
#include <QPushButton> #include <QPushButton>
using namespace Core; using namespace Core;
using namespace Debugger;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Tasking; using namespace Tasking;
using namespace Utils; using namespace Utils;
@@ -574,13 +575,15 @@ void TestRunner::debugTests()
.arg(config->displayName()); .arg(config->displayName());
reportResult(ResultType::MessageWarn, details); reportResult(ResultType::MessageWarn, details);
} }
auto debugger = new Debugger::DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
debugger->runParameters().setInferior(inferior); rp.setInferior(inferior);
debugger->runParameters().setDisplayName(config->displayName()); rp.setDisplayName(config->displayName());
auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
bool useOutputProcessor = true; bool useOutputProcessor = true;
if (Kit *kit = config->project()->activeKit()) { if (Kit *kit = config->project()->activeKit()) {
if (Debugger::DebuggerKitAspect::engineType(kit) == Debugger::CdbEngineType) { if (DebuggerKitAspect::engineType(kit) == CdbEngineType) {
reportResult(ResultType::MessageWarn, reportResult(ResultType::MessageWarn,
Tr::tr("Unable to display test results when using CDB.")); Tr::tr("Unable to display test results when using CDB."));
useOutputProcessor = false; useOutputProcessor = false;

View File

@@ -38,29 +38,32 @@ class BareMetalDebugSupportFactory final : public RunWorkerFactory
public: public:
BareMetalDebugSupportFactory() BareMetalDebugSupportFactory()
{ {
setProducer([](RunControl *runControl) { setProducer([](RunControl *runControl) -> RunWorker * {
DebuggerRunTool *debugger = new DebuggerRunTool(runControl);
const auto dev = std::static_pointer_cast<const BareMetalDevice>(runControl->device()); const auto dev = std::static_pointer_cast<const BareMetalDevice>(runControl->device());
if (!dev) { if (!dev) {
// TODO: reportFailure won't work from RunWorker's c'tor. // TODO: reportFailure won't work from RunWorker's c'tor.
debugger->reportFailure(Tr::tr("Cannot debug: Kit has no device.")); runControl->postMessage(Tr::tr("Cannot debug: Kit has no device."), ErrorMessageFormat);
return debugger; return nullptr;
} }
const QString providerId = dev->debugServerProviderId(); const QString providerId = dev->debugServerProviderId();
IDebugServerProvider *p = DebugServerProviderManager::findProvider(providerId); IDebugServerProvider *p = DebugServerProviderManager::findProvider(providerId);
if (!p) { if (!p) {
// TODO: reportFailure won't work from RunWorker's c'tor. // TODO: reportFailure won't work from RunWorker's c'tor.
debugger->reportFailure(Tr::tr("No debug server provider found for %1").arg(providerId)); runControl->postMessage(Tr::tr("No debug server provider found for %1").arg(providerId),
return debugger; ErrorMessageFormat);
return nullptr;
} }
DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
if (Result<> res = p->setupDebuggerRunParameters(rp, runControl); !res) {
runControl->postMessage(res.error(), ErrorMessageFormat); // TODO: reportFailure won't work from RunWorker's c'tor.
return nullptr;
}
auto debugger = createDebuggerWorker(runControl, rp);
if (RunWorker *runner = p->targetRunner(runControl)) if (RunWorker *runner = p->targetRunner(runControl))
debugger->addStartDependency(runner); debugger->addStartDependency(runner);
if (Result<> res = p->setupDebuggerRunParameters(debugger->runParameters(), runControl); !res)
debugger->reportFailure(res.error()); // TODO: reportFailure won't work from RunWorker's c'tor.
return debugger; return debugger;
}); });
addSupportedRunMode(ProjectExplorer::Constants::NORMAL_RUN_MODE); addSupportedRunMode(ProjectExplorer::Constants::NORMAL_RUN_MODE);

View File

@@ -113,10 +113,7 @@ public:
QdbDebugWorkerFactory() QdbDebugWorkerFactory()
{ {
setProducer([](RunControl *runControl) { setProducer([](RunControl *runControl) {
auto worker = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
worker->setId("QdbDeviceDebugSupport");
DebuggerRunParameters &rp = worker->runParameters();
rp.setupPortsGatherer(runControl); rp.setupPortsGatherer(runControl);
rp.setStartMode(Debugger::AttachToRemoteServer); rp.setStartMode(Debugger::AttachToRemoteServer);
rp.setCloseMode(KillAndExitMonitorAtClose); rp.setCloseMode(KillAndExitMonitorAtClose);
@@ -125,11 +122,13 @@ public:
rp.addSolibSearchDir("%{sysroot}/system/lib"); rp.addSolibSearchDir("%{sysroot}/system/lib");
rp.setSkipDebugServer(true); rp.setSkipDebugServer(true);
auto debuggee = createQdbDeviceInferiorWorker(runControl, QmlDebuggerServices); auto debugger = createDebuggerWorker(runControl, rp);
worker->addStartDependency(debuggee);
debuggee->addStopDependency(worker);
return worker; auto debuggee = createQdbDeviceInferiorWorker(runControl, QmlDebuggerServices);
debugger->addStartDependency(debuggee);
debuggee->addStopDependency(debugger);
return debugger;
}); });
addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE); addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE);
addSupportedRunConfig(Constants::QdbRunConfigurationId); addSupportedRunConfig(Constants::QdbRunConfigurationId);

View File

@@ -405,9 +405,7 @@ void StartApplicationDialog::run(bool attachRemote)
auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setKit(k); runControl->setKit(k);
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
const QString inputAddress = dialog.channelOverrideEdit->text(); const QString inputAddress = dialog.channelOverrideEdit->text();
if (!inputAddress.isEmpty()) { if (!inputAddress.isEmpty()) {
rp.setRemoteChannel(inputAddress); rp.setRemoteChannel(inputAddress);
@@ -433,7 +431,7 @@ void StartApplicationDialog::run(bool attachRemote)
rp.setInferiorEnvironment(k->runEnvironment()); rp.setInferiorEnvironment(k->runEnvironment());
if (!attachRemote) if (!attachRemote)
debugger->runParameters().setStartMode(isLocal ? StartExternal : StartRemoteProcess); rp.setStartMode(isLocal ? StartExternal : StartRemoteProcess);
if (attachRemote) { if (attachRemote) {
rp.setStartMode(AttachToRemoteServer); rp.setStartMode(AttachToRemoteServer);
@@ -442,6 +440,9 @@ void StartApplicationDialog::run(bool attachRemote)
rp.setDisplayName(Tr::tr("Attach to %1").arg(rp.remoteChannel().toDisplayString())); rp.setDisplayName(Tr::tr("Attach to %1").arg(rp.remoteChannel().toDisplayString()));
} }
auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
runControl->start(); runControl->start();
} }
@@ -574,8 +575,7 @@ void runAttachToQmlPortDialog()
auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setKit(kit); runControl->setKit(kit);
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
QUrl qmlServer = device->toolControlChannel(IDevice::QmlControlChannel); QUrl qmlServer = device->toolControlChannel(IDevice::QmlControlChannel);
qmlServer.setPort(dlg.port()); qmlServer.setPort(dlg.port());
@@ -588,6 +588,9 @@ void runAttachToQmlPortDialog()
rp.setRemoteChannel(channel); rp.setRemoteChannel(channel);
rp.setStartMode(AttachToQmlServer); rp.setStartMode(AttachToQmlServer);
auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
runControl->start(); runControl->start();
} }
@@ -721,12 +724,14 @@ void runStartRemoteCdbSessionDialog(Kit *kit)
auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setKit(kit); runControl->setKit(kit);
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setStartMode(AttachToRemoteServer); rp.setStartMode(AttachToRemoteServer);
rp.setCloseMode(KillAtClose); rp.setCloseMode(KillAtClose);
rp.setRemoteChannel(dlg.connection()); rp.setRemoteChannel(dlg.connection());
auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
runControl->start(); runControl->start();
} }

View File

@@ -1413,8 +1413,7 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setKit(kit); runControl->setKit(kit);
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setInferiorExecutable(executable); rp.setInferiorExecutable(executable);
if (!sysRoot.isEmpty()) if (!sysRoot.isEmpty())
rp.setSysRoot(FilePath::fromUserInput(sysRoot)); rp.setSysRoot(FilePath::fromUserInput(sysRoot));
@@ -1442,6 +1441,9 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
} }
rp.setUseTerminal(useTerminal); rp.setUseTerminal(useTerminal);
auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
m_scheduledStarts.append(runControl); m_scheduledStarts.append(runControl);
return true; return true;
} }
@@ -1460,8 +1462,7 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->setKit(findUniversalCdbKit()); runControl->setKit(findUniversalCdbKit());
runControl->setAttachPid(ProcessHandle(pid)); runControl->setAttachPid(ProcessHandle(pid));
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setStartMode(AttachToCrashedProcess); rp.setStartMode(AttachToCrashedProcess);
rp.setCrashParameter(it->section(':', 0, 0)); rp.setCrashParameter(it->section(':', 0, 0));
rp.setDisplayName(Tr::tr("Crashed process %1").arg(pid)); rp.setDisplayName(Tr::tr("Crashed process %1").arg(pid));
@@ -1471,6 +1472,10 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
"does not match the pattern <handle>:<pid>.").arg(*it, option); "does not match the pattern <handle>:<pid>.").arg(*it, option);
return false; return false;
} }
auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
m_scheduledStarts.append(runControl); m_scheduledStarts.append(runControl);
return true; return true;
} }
@@ -1637,13 +1642,15 @@ void DebuggerPluginPrivate::attachToLastCore()
runControl->setKit(KitManager::defaultKit()); runControl->setKit(KitManager::defaultKit());
runControl->setDisplayName(Tr::tr("Last Core file \"%1\"").arg(lastCore.coreFile.toUserOutput())); runControl->setDisplayName(Tr::tr("Last Core file \"%1\"").arg(lastCore.coreFile.toUserOutput()));
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setInferiorExecutable(lastCore.binary); rp.setInferiorExecutable(lastCore.binary);
rp.setCoreFilePath(lastCore.coreFile); rp.setCoreFilePath(lastCore.coreFile);
rp.setStartMode(AttachToCore); rp.setStartMode(AttachToCore);
rp.setCloseMode(DetachAtClose); rp.setCloseMode(DetachAtClose);
auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
runControl->start(); runControl->start();
} }
@@ -1686,9 +1693,7 @@ void DebuggerPluginPrivate::attachToRunningApplication()
runControl->setDisplayName(Tr::tr("Process %1").arg(processInfo.processId)); runControl->setDisplayName(Tr::tr("Process %1").arg(processInfo.processId));
runControl->requestDebugChannel(); runControl->requestDebugChannel();
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
debugger->setId("AttachToRunningProcess");
rp.setServerAttachPid(ProcessHandle(processInfo.processId)); rp.setServerAttachPid(ProcessHandle(processInfo.processId));
rp.setServerUseMulti(false); rp.setServerUseMulti(false);
rp.setServerEssential(false); rp.setServerEssential(false);
@@ -1697,6 +1702,9 @@ void DebuggerPluginPrivate::attachToRunningApplication()
rp.setUseContinueInsteadOfRun(true); rp.setUseContinueInsteadOfRun(true);
rp.setContinueAfterAttach(false); rp.setContinueAfterAttach(false);
auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
runControl->start(); runControl->start();
} }
} }
@@ -1759,15 +1767,16 @@ RunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit,
runControl->setDisplayName(Tr::tr("Process %1").arg(processInfo.processId)); runControl->setDisplayName(Tr::tr("Process %1").arg(processInfo.processId));
runControl->setAttachPid(ProcessHandle(processInfo.processId)); runControl->setAttachPid(ProcessHandle(processInfo.processId));
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setInferiorExecutable(device->filePath(processInfo.executable)); rp.setInferiorExecutable(device->filePath(processInfo.executable));
rp.setStartMode(AttachToLocalProcess); rp.setStartMode(AttachToLocalProcess);
rp.setCloseMode(DetachAtClose); rp.setCloseMode(DetachAtClose);
rp.setContinueAfterAttach(contAfterAttach); rp.setContinueAfterAttach(contAfterAttach);
runControl->start(); auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
runControl->start();
return runControl; return runControl;
} }
@@ -2319,12 +2328,14 @@ void DebuggerPlugin::attachExternalApplication(RunControl *rc)
runControl->setDisplayName(Tr::tr("Process %1").arg(pid.pid())); runControl->setDisplayName(Tr::tr("Process %1").arg(pid.pid()));
runControl->setAttachPid(pid); runControl->setAttachPid(pid);
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setInferiorExecutable(rc->targetFilePath()); rp.setInferiorExecutable(rc->targetFilePath());
rp.setStartMode(AttachToLocalProcess); rp.setStartMode(AttachToLocalProcess);
rp.setCloseMode(DetachAtClose); rp.setCloseMode(DetachAtClose);
auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
runControl->start(); runControl->start();
} }

View File

@@ -688,13 +688,14 @@ void EnginesDriver::start()
rc->copyDataFromRunControl(m_runControl); rc->copyDataFromRunControl(m_runControl);
rc->resetDataForAttachToCore(); rc->resetDataForAttachToCore();
auto name = QString(Tr::tr("%1 - Snapshot %2").arg(m_runControl->displayName()).arg(++m_snapshotCounter)); auto name = QString(Tr::tr("%1 - Snapshot %2").arg(m_runControl->displayName()).arg(++m_snapshotCounter));
auto debugger = new DebuggerRunTool(rc); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(rc);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setStartMode(AttachToCore); rp.setStartMode(AttachToCore);
rp.setCloseMode(DetachAtClose); rp.setCloseMode(DetachAtClose);
rp.setDisplayName(name); rp.setDisplayName(name);
rp.setCoreFilePath(FilePath::fromString(coreFile)); rp.setCoreFilePath(FilePath::fromString(coreFile));
rp.setSnapshot(true); rp.setSnapshot(true);
auto debugger = createDebuggerWorker(rc, rp);
Q_UNUSED(debugger)
rc->start(); rc->start();
}); });
} }
@@ -835,6 +836,13 @@ Group debuggerRecipe(RunControl *runControl, const DebuggerRunParameters &initia
}; };
} }
RunWorker *createDebuggerWorker(RunControl *runControl, const DebuggerRunParameters &initialParameters,
const std::function<void(DebuggerRunParameters &)> &parametersModifier)
{
return new RecipeRunner(runControl,
debuggerRecipe(runControl, initialParameters, parametersModifier));
}
void DebuggerRunTool::stop() void DebuggerRunTool::stop()
{ {
if (!d->m_taskTreeRunner.isRunning()) if (!d->m_taskTreeRunner.isRunning())
@@ -875,7 +883,9 @@ class DebuggerRunWorkerFactory final : public ProjectExplorer::RunWorkerFactory
public: public:
DebuggerRunWorkerFactory() DebuggerRunWorkerFactory()
{ {
setProduct<DebuggerRunTool>(); setProducer([](RunControl *runControl) {
return createDebuggerWorker(runControl, DebuggerRunParameters::fromRunControl(runControl));
});
setId(Constants::DEBUGGER_RUN_FACTORY); setId(Constants::DEBUGGER_RUN_FACTORY);
addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE); addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE);

View File

@@ -19,6 +19,11 @@ DEBUGGER_EXPORT Tasking::Group debuggerRecipe(
const DebuggerRunParameters &initialParameters, const DebuggerRunParameters &initialParameters,
const std::function<void(DebuggerRunParameters &)> &parametersModifier = {}); const std::function<void(DebuggerRunParameters &)> &parametersModifier = {});
DEBUGGER_EXPORT ProjectExplorer::RunWorker *createDebuggerWorker(
ProjectExplorer::RunControl *runControl,
const DebuggerRunParameters &initialParameters,
const std::function<void(DebuggerRunParameters &)> &parametersModifier = {});
class DEBUGGER_EXPORT DebuggerRunTool final : public ProjectExplorer::RunWorker class DEBUGGER_EXPORT DebuggerRunTool final : public ProjectExplorer::RunWorker
{ {
Q_OBJECT Q_OBJECT

View File

@@ -106,13 +106,13 @@ void DebuggerUnitTests::testStateMachine()
auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->copyDataFromRunConfiguration(rc); runControl->copyDataFromRunConfiguration(rc);
auto debugger = new DebuggerRunTool(runControl);
DebuggerRunParameters &rp = debugger->runParameters(); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
rp.setInferior(rc->runnable()); rp.setInferior(rc->runnable());
rp.setTestCase(TestNoBoundsOfCurrentFunction); rp.setTestCase(TestNoBoundsOfCurrentFunction);
connect(debugger, &DebuggerRunTool::stopped, auto debugger = createDebuggerWorker(runControl, rp);
connect(debugger, &RunWorker::stopped,
&QTestEventLoop::instance(), &QTestEventLoop::exitLoop); &QTestEventLoop::instance(), &QTestEventLoop::exitLoop);
runControl->start(); runControl->start();
@@ -120,7 +120,6 @@ void DebuggerUnitTests::testStateMachine()
QTestEventLoop::instance().enterLoop(5); QTestEventLoop::instance().enterLoop(5);
} }
enum FakeEnum { FakeDebuggerCommonSettingsId }; enum FakeEnum { FakeDebuggerCommonSettingsId };
void DebuggerUnitTests::testBenchmark() void DebuggerUnitTests::testBenchmark()

View File

@@ -349,8 +349,7 @@ void runAttachToCoreDialog()
runControl->setKit(dlg.kit()); runControl->setKit(dlg.kit());
runControl->setDisplayName(Tr::tr("Core file \"%1\"").arg(dlg.coreFile().toUserOutput())); runControl->setDisplayName(Tr::tr("Core file \"%1\"").arg(dlg.coreFile().toUserOutput()));
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setInferiorExecutable(dlg.symbolFileCopy()); rp.setInferiorExecutable(dlg.symbolFileCopy());
rp.setCoreFilePath(dlg.coreFileCopy()); rp.setCoreFilePath(dlg.coreFileCopy());
rp.setStartMode(AttachToCore); rp.setStartMode(AttachToCore);
@@ -360,6 +359,9 @@ void runAttachToCoreDialog()
if (!sysRoot.isEmpty()) if (!sysRoot.isEmpty())
rp.setSysRoot(sysRoot); rp.setSysRoot(sysRoot);
auto debugger = createDebuggerWorker(runControl, rp);
Q_UNUSED(debugger)
runControl->start(); runControl->start();
} }

View File

@@ -811,14 +811,8 @@ IosRunWorkerFactory::IosRunWorkerFactory()
addSupportedRunConfig(Constants::IOS_RUNCONFIG_ID); addSupportedRunConfig(Constants::IOS_RUNCONFIG_ID);
} }
static void startDebugger(RunControl *runControl, DebuggerRunTool *debugger, IosRunner *iosRunner) static void parametersModifier(RunControl *runControl, DebuggerRunParameters &rp, IosRunner *iosRunner)
{ {
if (!iosRunner->isAppRunning()) {
debugger->reportFailure(Tr::tr("Application not running."));
return;
}
DebuggerRunParameters &rp = debugger->runParameters();
const bool cppDebug = rp.isCppDebugging(); const bool cppDebug = rp.isCppDebugging();
const bool qmlDebug = rp.isQmlDebugging(); const bool qmlDebug = rp.isQmlDebugging();
if (cppDebug) { if (cppDebug) {
@@ -857,16 +851,13 @@ static void startDebugger(RunControl *runControl, DebuggerRunTool *debugger, Ios
static RunWorker *createWorker(RunControl *runControl) static RunWorker *createWorker(RunControl *runControl)
{ {
DebuggerRunTool *debugger = new DebuggerRunTool(runControl);
debugger->setId("IosDebugSupport");
IosDevice::ConstPtr dev = std::dynamic_pointer_cast<const IosDevice>(runControl->device()); IosDevice::ConstPtr dev = std::dynamic_pointer_cast<const IosDevice>(runControl->device());
const bool isIosDeviceType = runControl->device()->type() == Ios::Constants::IOS_DEVICE_TYPE; const bool isIosDeviceType = runControl->device()->type() == Ios::Constants::IOS_DEVICE_TYPE;
const bool isIosDeviceInstance = bool(dev); const bool isIosDeviceInstance = bool(dev);
// type info and device class must match // type info and device class must match
QTC_ASSERT(isIosDeviceInstance == isIosDeviceType, QTC_ASSERT(isIosDeviceInstance == isIosDeviceType,
runControl->postMessage(Tr::tr("Internal error."), ErrorMessageFormat); return nullptr); runControl->postMessage(Tr::tr("Internal error."), ErrorMessageFormat); return nullptr);
DebuggerRunParameters &rp = debugger->runParameters(); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
// TODO cannot use setupPortsGatherer() from DebuggerRunTool, because that also requests // TODO cannot use setupPortsGatherer() from DebuggerRunTool, because that also requests
// the "debugChannel", which then results in runControl trying to retrieve ports&URL for that // the "debugChannel", which then results in runControl trying to retrieve ports&URL for that
// via IDevice, which doesn't really work with the iOS setup, and also completely changes // via IDevice, which doesn't really work with the iOS setup, and also completely changes
@@ -886,7 +877,6 @@ static RunWorker *createWorker(RunControl *runControl)
runner = deviceCtlRunner = new DeviceCtlRunner(runControl); runner = deviceCtlRunner = new DeviceCtlRunner(runControl);
deviceCtlRunner->setStartStopped(true); deviceCtlRunner->setStartStopped(true);
} }
debugger->addStartDependency(runner);
if (isIosDeviceInstance) { if (isIosDeviceInstance) {
if (dev->handler() == IosDevice::Handler::DeviceCtl) { if (dev->handler() == IosDevice::Handler::DeviceCtl) {
@@ -914,7 +904,8 @@ static RunWorker *createWorker(RunControl *runControl)
rp.setDisplayName(data->applicationName); rp.setDisplayName(data->applicationName);
rp.setContinueAfterAttach(true); rp.setContinueAfterAttach(true);
if (isIosDeviceInstance && dev->handler() == IosDevice::Handler::DeviceCtl) { const bool isDeviceCtl = isIosDeviceInstance && dev->handler() == IosDevice::Handler::DeviceCtl;
if (isDeviceCtl) {
const auto msgOnlyCppDebuggingSupported = [] { const auto msgOnlyCppDebuggingSupported = [] {
return Tr::tr("Only C++ debugging is supported for devices with iOS 17 and later."); return Tr::tr("Only C++ debugging is supported for devices with iOS 17 and later.");
}; };
@@ -929,11 +920,15 @@ static RunWorker *createWorker(RunControl *runControl)
runControl->postMessage(msgOnlyCppDebuggingSupported(), LogMessageFormat); runControl->postMessage(msgOnlyCppDebuggingSupported(), LogMessageFormat);
} }
rp.setInferiorExecutable(data->localExecutable); rp.setInferiorExecutable(data->localExecutable);
} else {
QObject::connect(runner, &RunWorker::started, debugger, [runControl, debugger, iosRunner] {
startDebugger(runControl, debugger, iosRunner);
});
} }
auto debugger = createDebuggerWorker(runControl, rp,
[runControl, iosRunner, isDeviceCtl](DebuggerRunParameters &rp) {
if (isDeviceCtl)
return;
parametersModifier(runControl, rp, iosRunner);
});
debugger->addStartDependency(runner);
return debugger; return debugger;
} }

View File

@@ -133,19 +133,9 @@ void showAttachToProcessDialog()
auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
runControl->copyDataFromRunConfiguration(runConfig); runControl->copyDataFromRunConfiguration(runConfig);
runControl->setAttachPid(ProcessHandle(pid)); runControl->setAttachPid(ProcessHandle(pid));
auto debugger = new DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
debugger->setId("QnxAttachDebugSupport");
rp.setupPortsGatherer(runControl); rp.setupPortsGatherer(runControl);
rp.setUseCtrlCStub(true); rp.setUseCtrlCStub(true);
if (rp.isCppDebugging()) {
const auto modifier = [runControl](Process &process) {
const int pdebugPort = runControl->debugChannel().port();
process.setCommand({QNX_DEBUG_EXECUTABLE, {QString::number(pdebugPort)}});
};
auto worker = createProcessWorker(runControl, modifier);
debugger->addStartDependency(worker);
}
rp.setStartMode(AttachToRemoteServer); rp.setStartMode(AttachToRemoteServer);
rp.setCloseMode(DetachAtClose); rp.setCloseMode(DetachAtClose);
@@ -157,6 +147,17 @@ void showAttachToProcessDialog()
rp.setSysRoot(qtVersion->qnxTarget()); rp.setSysRoot(qtVersion->qnxTarget());
rp.setUseContinueInsteadOfRun(true); rp.setUseContinueInsteadOfRun(true);
auto debugger = createDebuggerWorker(runControl, rp);
if (rp.isCppDebugging()) {
const auto modifier = [runControl](Process &process) {
const int pdebugPort = runControl->debugChannel().port();
process.setCommand({QNX_DEBUG_EXECUTABLE, {QString::number(pdebugPort)}});
};
auto worker = createProcessWorker(runControl, modifier);
debugger->addStartDependency(worker);
}
runControl->start(); runControl->start();
} }
@@ -168,9 +169,6 @@ public:
QnxDebugWorkerFactory() QnxDebugWorkerFactory()
{ {
setProducer([](RunControl *runControl) { setProducer([](RunControl *runControl) {
auto debugger = new DebuggerRunTool(runControl);
debugger->setId("QnxDebugSupport");
runControl->postMessage(Tr::tr("Preparing remote side..."), LogMessageFormat); runControl->postMessage(Tr::tr("Preparing remote side..."), LogMessageFormat);
const auto modifier = [runControl](Process &process) { const auto modifier = [runControl](Process &process) {
@@ -192,11 +190,8 @@ public:
auto slog2InfoRunner = new RecipeRunner(runControl, slog2InfoRecipe(runControl)); auto slog2InfoRunner = new RecipeRunner(runControl, slog2InfoRecipe(runControl));
worker->addStartDependency(slog2InfoRunner); worker->addStartDependency(slog2InfoRunner);
debugger->addStartDependency(worker);
Kit *k = runControl->kit(); Kit *k = runControl->kit();
DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setupPortsGatherer(runControl); rp.setupPortsGatherer(runControl);
rp.setStartMode(AttachToRemoteServer); rp.setStartMode(AttachToRemoteServer);
rp.setCloseMode(KillAtClose); rp.setCloseMode(KillAtClose);
@@ -208,6 +203,8 @@ public:
rp.modifyDebuggerEnvironment(qtVersion->environment()); rp.modifyDebuggerEnvironment(qtVersion->environment());
} }
auto debugger = createDebuggerWorker(runControl, rp);
debugger->addStartDependency(worker);
return debugger; return debugger;
}); });
addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE); addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE);

View File

@@ -152,22 +152,15 @@ class AppManagerDebugWorkerFactory final : public RunWorkerFactory
public: public:
AppManagerDebugWorkerFactory() AppManagerDebugWorkerFactory()
{ {
setProducer([](RunControl *runControl) { setProducer([](RunControl *runControl) -> RunWorker * {
DebuggerRunTool *debugger = new DebuggerRunTool(runControl);
debugger->setId("ApplicationManagerPlugin.Debug.Support");
auto debuggee = createInferiorRunner(runControl, QmlDebuggerServices);
debugger->addStartDependency(debuggee);
debugger->addStopDependency(debuggee);
debuggee->addStopDependency(debugger);
BuildConfiguration *bc = runControl->buildConfiguration(); BuildConfiguration *bc = runControl->buildConfiguration();
const Internal::TargetInformation targetInformation(bc); const Internal::TargetInformation targetInformation(bc);
if (!targetInformation.isValid()) { if (!targetInformation.isValid()) {
// TODO: reportFailure won't work from RunWorker's c'tor. // TODO: reportFailure won't work from RunWorker's c'tor.
debugger->reportFailure(Tr::tr("Cannot debug: Invalid target information.")); runControl->postMessage(Tr::tr("Cannot debug: Invalid target information."),
return debugger; ErrorMessageFormat);
return nullptr;
} }
FilePath symbolFile; FilePath symbolFile;
@@ -184,16 +177,20 @@ public:
}).targetFilePath; }).targetFilePath;
} else { } else {
// TODO: reportFailure won't work from RunWorker's c'tor. // TODO: reportFailure won't work from RunWorker's c'tor.
debugger->reportFailure(Tr::tr("Cannot debug: Only QML and native applications are supported.")); runControl->postMessage(Tr::tr("Cannot debug: Only QML and native applications are supported."),
return debugger; ErrorMessageFormat);
return nullptr;
} }
if (symbolFile.isEmpty()) { if (symbolFile.isEmpty()) {
// TODO: reportFailure won't work from RunWorker's c'tor. // TODO: reportFailure won't work from RunWorker's c'tor.
debugger->reportFailure(Tr::tr("Cannot debug: Local executable is not set.")); runControl->postMessage(Tr::tr("Cannot debug: Local executable is not set."),
return debugger; ErrorMessageFormat);
return nullptr;
} }
Debugger::DebuggerRunParameters &rp = debugger->runParameters(); auto debuggee = createInferiorRunner(runControl, QmlDebuggerServices);
DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
rp.setupPortsGatherer(runControl); rp.setupPortsGatherer(runControl);
rp.setStartMode(Debugger::AttachToRemoteServer); rp.setStartMode(Debugger::AttachToRemoteServer);
rp.setCloseMode(Debugger::KillAndExitMonitorAtClose); rp.setCloseMode(Debugger::KillAndExitMonitorAtClose);
@@ -217,6 +214,11 @@ public:
rp.setSysRoot(sysroot); rp.setSysRoot(sysroot);
} }
auto debugger = createDebuggerWorker(runControl, rp);
debugger->addStartDependency(debuggee);
debugger->addStopDependency(debuggee);
debuggee->addStopDependency(debugger);
return debugger; return debugger;
}); });
addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE); addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE);

View File

@@ -46,13 +46,11 @@ class RemoteLinuxDebugWorkerFactory final : public ProjectExplorer::RunWorkerFac
public: public:
RemoteLinuxDebugWorkerFactory() RemoteLinuxDebugWorkerFactory()
{ {
setProducer([](RunControl *rc) { setProducer([](RunControl *runControl) {
rc->requestDebugChannel(); runControl->requestDebugChannel();
auto debugger = new DebuggerRunTool(rc); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters(); rp.setupPortsGatherer(runControl);
debugger->setId("RemoteLinuxDebugWorker");
rp.setupPortsGatherer(rc);
rp.setUseTerminal(false); rp.setUseTerminal(false);
rp.setAddQmlServerInferiorCmdArgIfNeeded(true); rp.setAddQmlServerInferiorCmdArgIfNeeded(true);
@@ -60,11 +58,11 @@ public:
rp.setCloseMode(KillAndExitMonitorAtClose); rp.setCloseMode(KillAndExitMonitorAtClose);
rp.setUseExtendedRemote(true); rp.setUseExtendedRemote(true);
if (rc->device()->osType() == Utils::OsTypeMac) if (runControl->device()->osType() == Utils::OsTypeMac)
rp.setLldbPlatform("remote-macosx"); rp.setLldbPlatform("remote-macosx");
else else
rp.setLldbPlatform("remote-linux"); rp.setLldbPlatform("remote-linux");
return debugger; return createDebuggerWorker(runControl, rp);
}); });
addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE); addSupportedRunMode(ProjectExplorer::Constants::DEBUG_RUN_MODE);
addSupportedDeviceType(Constants::GenericLinuxOsType); addSupportedDeviceType(Constants::GenericLinuxOsType);

View File

@@ -1044,16 +1044,15 @@ static ExecutableItem debuggerRecipe(const Storage<ProcessHandle> pidStorage, Ru
return Sync([runControl, pidStorage] { return Sync([runControl, pidStorage] {
// TODO: Make a part of this recipe // TODO: Make a part of this recipe
auto debugger = new Debugger::DebuggerRunTool(runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(runControl);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setStartMode(Debugger::AttachToRemoteServer); rp.setStartMode(Debugger::AttachToRemoteServer);
rp.setDisplayName(QString("VGdb %1").arg(pidStorage->pid())); rp.setDisplayName(QString("VGdb %1").arg(pidStorage->pid()));
rp.setRemoteChannelPipe(QString("vgdb --pid=%1").arg(pidStorage->pid())); rp.setRemoteChannelPipe(QString("vgdb --pid=%1").arg(pidStorage->pid()));
rp.setUseContinueInsteadOfRun(true); rp.setUseContinueInsteadOfRun(true);
rp.addExpectedSignal("SIGTRAP"); rp.addExpectedSignal("SIGTRAP");
auto debugger = createDebuggerWorker(runControl, rp);
QObject::connect(runControl, &RunControl::stopped, debugger, &RunControl::deleteLater); QObject::connect(runControl, &RunControl::stopped, debugger, &RunControl::deleteLater);
debugger->initiateStart(); debugger->initiateStart();
}); });
} }
@@ -1575,8 +1574,7 @@ void HeobData::processFinished()
if (m_data[0] >= HEOB_PID_ATTACH) { if (m_data[0] >= HEOB_PID_ATTACH) {
m_runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE); m_runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE);
m_runControl->setKit(m_kit); m_runControl->setKit(m_kit);
auto debugger = new DebuggerRunTool(m_runControl); DebuggerRunParameters rp = DebuggerRunParameters::fromRunControl(m_runControl);
DebuggerRunParameters &rp = debugger->runParameters();
rp.setAttachPid(ProcessHandle(m_data[1])); rp.setAttachPid(ProcessHandle(m_data[1]));
rp.setDisplayName(Tr::tr("Process %1").arg(m_data[1])); rp.setDisplayName(Tr::tr("Process %1").arg(m_data[1]));
rp.setStartMode(AttachToLocalProcess); rp.setStartMode(AttachToLocalProcess);
@@ -1586,6 +1584,8 @@ void HeobData::processFinished()
connect(m_runControl, &RunControl::started, this, &HeobData::debugStarted); connect(m_runControl, &RunControl::started, this, &HeobData::debugStarted);
connect(m_runControl, &RunControl::stopped, this, &HeobData::debugStopped); connect(m_runControl, &RunControl::stopped, this, &HeobData::debugStopped);
auto debugger = createDebuggerWorker(m_runControl, rp);
Q_UNUSED(debugger)
m_runControl->start(); m_runControl->start();
return; return;
} }