From 265491e408c514d25554c533c304da0e58310234 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 25 Sep 2024 16:16:36 +0200 Subject: [PATCH] Debugger: Dissolve DebuggerServerRunner Replace it with a plain (optional) Process in the main debugger startup sequence. Change-Id: I9b67bc99625aba68a923a362fc5bf9be828a8fb1 Reviewed-by: Christian Stenger --- src/plugins/debugger/debuggerplugin.cpp | 7 +- src/plugins/debugger/debuggerruncontrol.cpp | 109 +++++++++++------- src/plugins/debugger/debuggerruncontrol.h | 20 +--- .../remotelinux/remotelinuxdebugsupport.cpp | 6 +- 4 files changed, 72 insertions(+), 70 deletions(-) diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index d7ad2501612..92b308fe597 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1712,12 +1712,7 @@ public: { setId("AttachToRunningProcess"); setUsePortsGatherer(true, false); - - auto gdbServer = new DebugServerRunner(runControl, portsGatherer()); - gdbServer->setUseMulti(false); - gdbServer->setAttachPid(pid); - - addStartDependency(gdbServer); + setUseDebugServer(pid, false, false); setStartMode(AttachToRemoteProcess); setCloseMode(DetachAtClose); diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index 154e30e4fc4..f92088001c2 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -162,8 +162,17 @@ public: int engineStartsNeeded = 0; int engineStopsNeeded = 0; QString runId; + + // Terminal Process terminalProc; DebuggerRunTool::AllowTerminal allowTerminal = DebuggerRunTool::DoAllowTerminal; + + // DebugServer + Process debuggerServerProc; + bool useDebugServer = false; + Utils::ProcessHandle serverAttachPid; + bool serverUseMulti = true; + bool serverEssential = true; }; } // namespace Internal @@ -509,6 +518,11 @@ void DebuggerRunTool::continueAfterTerminalStart() return; } + startDebugServerIfNeededAndContinueStartup(); +} + +void DebuggerRunTool::continueAfterDebugServerStart() +{ Utils::globalMacroExpander()->registerFileVariables( "DebuggedExecutable", Tr::tr("Debugged executable"), [this] { return m_runParameters.inferior.command.executable(); } @@ -1033,36 +1047,35 @@ QUrl DebugServerPortsGatherer::qmlServer() const return channel(1); } -// DebugServerRunner - -DebugServerRunner::DebugServerRunner(RunControl *runControl, DebugServerPortsGatherer *portsGatherer) - : SimpleTargetRunner(runControl) +void DebuggerRunTool::startDebugServerIfNeededAndContinueStartup() { - setId("DebugServerRunner"); - addStartDependency(portsGatherer); + if (!d->useDebugServer) { + continueAfterDebugServerStart(); + return; + } - QTC_ASSERT(portsGatherer, reportFailure(); return); + // FIXME: Indentation intentionally wrong to keep diff in gerrit small. Will fix later. - setStartModifier([this, runControl, portsGatherer] { - QTC_ASSERT(portsGatherer, reportFailure(); return); + QTC_ASSERT(portsGatherer(), reportFailure(); return); - const bool isQmlDebugging = portsGatherer->useQmlServer(); - const bool isCppDebugging = portsGatherer->useGdbServer(); + const bool isQmlDebugging = portsGatherer()->useQmlServer(); + const bool isCppDebugging = portsGatherer()->useGdbServer(); + CommandLine commandLine = m_runParameters.inferior.command; CommandLine cmd; if (isQmlDebugging && !isCppDebugging) { // FIXME: Case should not happen? - cmd.setExecutable(commandLine().executable()); + cmd.setExecutable(commandLine.executable()); cmd.addArg(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices, - portsGatherer->qmlServer())); - cmd.addArgs(commandLine().arguments(), CommandLine::Raw); + portsGatherer()->qmlServer())); + cmd.addArgs(commandLine.arguments(), CommandLine::Raw); } else { - cmd.setExecutable(runControl->device()->debugServerPath()); + cmd.setExecutable(device()->debugServerPath()); if (cmd.isEmpty()) { - if (runControl->device()->osType() == Utils::OsTypeMac) { - const FilePath debugServerLocation = runControl->device()->filePath( + if (device()->osType() == Utils::OsTypeMac) { + const FilePath debugServerLocation = device()->filePath( "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/" "Resources/debugserver"); @@ -1072,15 +1085,15 @@ DebugServerRunner::DebugServerRunner(RunControl *runControl, DebugServerPortsGat // TODO: In the future it is expected that the debugserver will be // replaced by lldb-server. Remove the check for debug server at that point. const FilePath lldbserver - = runControl->device()->filePath("lldb-server").searchInPath(); + = device()->filePath("lldb-server").searchInPath(); if (lldbserver.isExecutableFile()) cmd.setExecutable(lldbserver); } } else { const FilePath gdbServerPath - = runControl->device()->filePath("gdbserver").searchInPath(); + = device()->filePath("gdbserver").searchInPath(); FilePath lldbServerPath - = runControl->device()->filePath("lldb-server").searchInPath(); + = device()->filePath("lldb-server").searchInPath(); // TODO: Which one should we prefer? if (gdbServerPath.isExecutableFile()) @@ -1102,50 +1115,60 @@ DebugServerRunner::DebugServerRunner(RunControl *runControl, DebugServerPortsGat if (cmd.executable().baseName().contains("lldb-server")) { cmd.addArg("platform"); cmd.addArg("--listen"); - cmd.addArg(QString("*:%1").arg(portsGatherer->gdbServer().port())); + cmd.addArg(QString("*:%1").arg(portsGatherer()->gdbServer().port())); cmd.addArg("--server"); } else if (cmd.executable().baseName() == "debugserver") { const QString ipAndPort("`echo $SSH_CLIENT | cut -d ' ' -f 1`:%1"); - cmd.addArgs(ipAndPort.arg(portsGatherer->gdbServer().port()), CommandLine::Raw); + cmd.addArgs(ipAndPort.arg(portsGatherer()->gdbServer().port()), CommandLine::Raw); - if (m_pid.isValid()) - cmd.addArgs({"--attach", QString::number(m_pid.pid())}); + if (d->serverAttachPid.isValid()) + cmd.addArgs({"--attach", QString::number(d->serverAttachPid.pid())}); else - cmd.addCommandLineAsArgs(runControl->runnable().command); + cmd.addCommandLineAsArgs(runControl()->runnable().command); } else { // Something resembling gdbserver - if (m_useMulti) + if (d->serverUseMulti) cmd.addArg("--multi"); - if (m_pid.isValid()) + if (d->serverAttachPid.isValid()) cmd.addArg("--attach"); - const auto port = portsGatherer->gdbServer().port(); + const auto port = portsGatherer()->gdbServer().port(); cmd.addArg(QString(":%1").arg(port)); - if (runControl->device()->extraData(RemoteLinux::Constants::SshForwardDebugServerPort).toBool()) { - addExtraData(RemoteLinux::Constants::SshForwardPort, port); - addExtraData(RemoteLinux::Constants::DisableSharing, true); + if (device()->extraData(RemoteLinux::Constants::SshForwardDebugServerPort).toBool()) { + QVariantHash extraData; + extraData[RemoteLinux::Constants::SshForwardPort] = port; + extraData[RemoteLinux::Constants::DisableSharing] = true; + d->debuggerServerProc.setExtraData(extraData); } - if (m_pid.isValid()) - cmd.addArg(QString::number(m_pid.pid())); + if (d->serverAttachPid.isValid()) + cmd.addArg(QString::number(d->serverAttachPid.pid())); } } - setCommandLine(cmd); + d->debuggerServerProc.setCommand(cmd); + + connect(&d->debuggerServerProc, &Process::started, this, [this] { + continueAfterDebugServerStart(); }); + + connect(&d->debuggerServerProc, &Process::done, this, [this] { + if (d->terminalProc.error() != QProcess::UnknownError) + reportFailure(d->terminalProc.errorString()); + if (d->terminalProc.error() != QProcess::FailedToStart && d->serverEssential) + reportDone(); + }); + + d->debuggerServerProc.start(); } -DebugServerRunner::~DebugServerRunner() = default; - -void DebugServerRunner::setUseMulti(bool on) +void DebuggerRunTool::setUseDebugServer(ProcessHandle attachPid, bool essential, bool useMulti) { - m_useMulti = on; -} - -void DebugServerRunner::setAttachPid(ProcessHandle pid) -{ - m_pid = pid; + d->useDebugServer = true; + d->serverAttachPid = attachPid; + d->serverEssential = essential; + d->serverUseMulti = useMulti; } // DebuggerRunWorkerFactory diff --git a/src/plugins/debugger/debuggerruncontrol.h b/src/plugins/debugger/debuggerruncontrol.h index beadec4b102..dcd2a8e6875 100644 --- a/src/plugins/debugger/debuggerruncontrol.h +++ b/src/plugins/debugger/debuggerruncontrol.h @@ -62,6 +62,7 @@ public: void setContinueAfterAttach(bool on); void setBreakOnMain(bool on); void setUseTerminal(bool on); + void setUseDebugServer(Utils::ProcessHandle attachPid, bool essential, bool useMulti); void setCommandsAfterConnect(const QString &commands); void setCommandsForReset(const QString &commands); @@ -115,6 +116,9 @@ private: void startTerminalIfNeededAndContinueStartup(); void continueAfterTerminalStart(); + void startDebugServerIfNeededAndContinueStartup(); + void continueAfterDebugServerStart(); + Internal::DebuggerRunToolPrivate *d; QList> m_engines; Internal::DebuggerRunParameters m_runParameters; @@ -139,22 +143,6 @@ private: bool m_useQmlServer = false; }; -class DEBUGGER_EXPORT DebugServerRunner : public ProjectExplorer::SimpleTargetRunner -{ -public: - explicit DebugServerRunner(ProjectExplorer::RunControl *runControl, - DebugServerPortsGatherer *portsGatherer); - - ~DebugServerRunner() override; - - void setUseMulti(bool on); - void setAttachPid(Utils::ProcessHandle pid); - -private: - Utils::ProcessHandle m_pid; - bool m_useMulti = true; -}; - class DebuggerRunWorkerFactory final : public ProjectExplorer::RunWorkerFactory { public: diff --git a/src/plugins/remotelinux/remotelinuxdebugsupport.cpp b/src/plugins/remotelinux/remotelinuxdebugsupport.cpp index 7a9b19145e8..ed55eb532ea 100644 --- a/src/plugins/remotelinux/remotelinuxdebugsupport.cpp +++ b/src/plugins/remotelinux/remotelinuxdebugsupport.cpp @@ -29,11 +29,7 @@ public: setUsePortsGatherer(isCppDebugging(), isQmlDebugging()); addQmlServerInferiorCommandLineArgumentIfNeeded(); - - auto debugServer = new DebugServerRunner(runControl, portsGatherer()); - debugServer->setEssential(true); - - addStartDependency(debugServer); + setUseDebugServer({}, true, true); setStartMode(AttachToRemoteServer); setCloseMode(KillAndExitMonitorAtClose);