forked from qt-creator/qt-creator
Debugger: Dissolve DebuggerServerRunner
Replace it with a plain (optional) Process in the main debugger startup sequence. Change-Id: I9b67bc99625aba68a923a362fc5bf9be828a8fb1 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -1712,12 +1712,7 @@ public:
|
|||||||
{
|
{
|
||||||
setId("AttachToRunningProcess");
|
setId("AttachToRunningProcess");
|
||||||
setUsePortsGatherer(true, false);
|
setUsePortsGatherer(true, false);
|
||||||
|
setUseDebugServer(pid, false, false);
|
||||||
auto gdbServer = new DebugServerRunner(runControl, portsGatherer());
|
|
||||||
gdbServer->setUseMulti(false);
|
|
||||||
gdbServer->setAttachPid(pid);
|
|
||||||
|
|
||||||
addStartDependency(gdbServer);
|
|
||||||
|
|
||||||
setStartMode(AttachToRemoteProcess);
|
setStartMode(AttachToRemoteProcess);
|
||||||
setCloseMode(DetachAtClose);
|
setCloseMode(DetachAtClose);
|
||||||
|
@@ -162,8 +162,17 @@ public:
|
|||||||
int engineStartsNeeded = 0;
|
int engineStartsNeeded = 0;
|
||||||
int engineStopsNeeded = 0;
|
int engineStopsNeeded = 0;
|
||||||
QString runId;
|
QString runId;
|
||||||
|
|
||||||
|
// Terminal
|
||||||
Process terminalProc;
|
Process terminalProc;
|
||||||
DebuggerRunTool::AllowTerminal allowTerminal = DebuggerRunTool::DoAllowTerminal;
|
DebuggerRunTool::AllowTerminal allowTerminal = DebuggerRunTool::DoAllowTerminal;
|
||||||
|
|
||||||
|
// DebugServer
|
||||||
|
Process debuggerServerProc;
|
||||||
|
bool useDebugServer = false;
|
||||||
|
Utils::ProcessHandle serverAttachPid;
|
||||||
|
bool serverUseMulti = true;
|
||||||
|
bool serverEssential = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
@@ -509,6 +518,11 @@ void DebuggerRunTool::continueAfterTerminalStart()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startDebugServerIfNeededAndContinueStartup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebuggerRunTool::continueAfterDebugServerStart()
|
||||||
|
{
|
||||||
Utils::globalMacroExpander()->registerFileVariables(
|
Utils::globalMacroExpander()->registerFileVariables(
|
||||||
"DebuggedExecutable", Tr::tr("Debugged executable"),
|
"DebuggedExecutable", Tr::tr("Debugged executable"),
|
||||||
[this] { return m_runParameters.inferior.command.executable(); }
|
[this] { return m_runParameters.inferior.command.executable(); }
|
||||||
@@ -1033,36 +1047,35 @@ QUrl DebugServerPortsGatherer::qmlServer() const
|
|||||||
return channel(1);
|
return channel(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DebugServerRunner
|
void DebuggerRunTool::startDebugServerIfNeededAndContinueStartup()
|
||||||
|
|
||||||
DebugServerRunner::DebugServerRunner(RunControl *runControl, DebugServerPortsGatherer *portsGatherer)
|
|
||||||
: SimpleTargetRunner(runControl)
|
|
||||||
{
|
{
|
||||||
setId("DebugServerRunner");
|
if (!d->useDebugServer) {
|
||||||
addStartDependency(portsGatherer);
|
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 isQmlDebugging = portsGatherer()->useQmlServer();
|
||||||
const bool isCppDebugging = portsGatherer->useGdbServer();
|
const bool isCppDebugging = portsGatherer()->useGdbServer();
|
||||||
|
|
||||||
|
CommandLine commandLine = m_runParameters.inferior.command;
|
||||||
CommandLine cmd;
|
CommandLine cmd;
|
||||||
|
|
||||||
if (isQmlDebugging && !isCppDebugging) {
|
if (isQmlDebugging && !isCppDebugging) {
|
||||||
// FIXME: Case should not happen?
|
// FIXME: Case should not happen?
|
||||||
cmd.setExecutable(commandLine().executable());
|
cmd.setExecutable(commandLine.executable());
|
||||||
cmd.addArg(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices,
|
cmd.addArg(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlDebuggerServices,
|
||||||
portsGatherer->qmlServer()));
|
portsGatherer()->qmlServer()));
|
||||||
cmd.addArgs(commandLine().arguments(), CommandLine::Raw);
|
cmd.addArgs(commandLine.arguments(), CommandLine::Raw);
|
||||||
} else {
|
} else {
|
||||||
cmd.setExecutable(runControl->device()->debugServerPath());
|
cmd.setExecutable(device()->debugServerPath());
|
||||||
|
|
||||||
if (cmd.isEmpty()) {
|
if (cmd.isEmpty()) {
|
||||||
if (runControl->device()->osType() == Utils::OsTypeMac) {
|
if (device()->osType() == Utils::OsTypeMac) {
|
||||||
const FilePath debugServerLocation = runControl->device()->filePath(
|
const FilePath debugServerLocation = device()->filePath(
|
||||||
"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/"
|
"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/"
|
||||||
"Resources/debugserver");
|
"Resources/debugserver");
|
||||||
|
|
||||||
@@ -1072,15 +1085,15 @@ DebugServerRunner::DebugServerRunner(RunControl *runControl, DebugServerPortsGat
|
|||||||
// TODO: In the future it is expected that the debugserver will be
|
// 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.
|
// replaced by lldb-server. Remove the check for debug server at that point.
|
||||||
const FilePath lldbserver
|
const FilePath lldbserver
|
||||||
= runControl->device()->filePath("lldb-server").searchInPath();
|
= device()->filePath("lldb-server").searchInPath();
|
||||||
if (lldbserver.isExecutableFile())
|
if (lldbserver.isExecutableFile())
|
||||||
cmd.setExecutable(lldbserver);
|
cmd.setExecutable(lldbserver);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const FilePath gdbServerPath
|
const FilePath gdbServerPath
|
||||||
= runControl->device()->filePath("gdbserver").searchInPath();
|
= device()->filePath("gdbserver").searchInPath();
|
||||||
FilePath lldbServerPath
|
FilePath lldbServerPath
|
||||||
= runControl->device()->filePath("lldb-server").searchInPath();
|
= device()->filePath("lldb-server").searchInPath();
|
||||||
|
|
||||||
// TODO: Which one should we prefer?
|
// TODO: Which one should we prefer?
|
||||||
if (gdbServerPath.isExecutableFile())
|
if (gdbServerPath.isExecutableFile())
|
||||||
@@ -1102,50 +1115,60 @@ DebugServerRunner::DebugServerRunner(RunControl *runControl, DebugServerPortsGat
|
|||||||
if (cmd.executable().baseName().contains("lldb-server")) {
|
if (cmd.executable().baseName().contains("lldb-server")) {
|
||||||
cmd.addArg("platform");
|
cmd.addArg("platform");
|
||||||
cmd.addArg("--listen");
|
cmd.addArg("--listen");
|
||||||
cmd.addArg(QString("*:%1").arg(portsGatherer->gdbServer().port()));
|
cmd.addArg(QString("*:%1").arg(portsGatherer()->gdbServer().port()));
|
||||||
cmd.addArg("--server");
|
cmd.addArg("--server");
|
||||||
} else if (cmd.executable().baseName() == "debugserver") {
|
} else if (cmd.executable().baseName() == "debugserver") {
|
||||||
const QString ipAndPort("`echo $SSH_CLIENT | cut -d ' ' -f 1`:%1");
|
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())
|
if (d->serverAttachPid.isValid())
|
||||||
cmd.addArgs({"--attach", QString::number(m_pid.pid())});
|
cmd.addArgs({"--attach", QString::number(d->serverAttachPid.pid())});
|
||||||
else
|
else
|
||||||
cmd.addCommandLineAsArgs(runControl->runnable().command);
|
cmd.addCommandLineAsArgs(runControl()->runnable().command);
|
||||||
} else {
|
} else {
|
||||||
// Something resembling gdbserver
|
// Something resembling gdbserver
|
||||||
if (m_useMulti)
|
if (d->serverUseMulti)
|
||||||
cmd.addArg("--multi");
|
cmd.addArg("--multi");
|
||||||
if (m_pid.isValid())
|
if (d->serverAttachPid.isValid())
|
||||||
cmd.addArg("--attach");
|
cmd.addArg("--attach");
|
||||||
|
|
||||||
const auto port = portsGatherer->gdbServer().port();
|
const auto port = portsGatherer()->gdbServer().port();
|
||||||
cmd.addArg(QString(":%1").arg(port));
|
cmd.addArg(QString(":%1").arg(port));
|
||||||
|
|
||||||
if (runControl->device()->extraData(RemoteLinux::Constants::SshForwardDebugServerPort).toBool()) {
|
if (device()->extraData(RemoteLinux::Constants::SshForwardDebugServerPort).toBool()) {
|
||||||
addExtraData(RemoteLinux::Constants::SshForwardPort, port);
|
QVariantHash extraData;
|
||||||
addExtraData(RemoteLinux::Constants::DisableSharing, true);
|
extraData[RemoteLinux::Constants::SshForwardPort] = port;
|
||||||
|
extraData[RemoteLinux::Constants::DisableSharing] = true;
|
||||||
|
d->debuggerServerProc.setExtraData(extraData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_pid.isValid())
|
if (d->serverAttachPid.isValid())
|
||||||
cmd.addArg(QString::number(m_pid.pid()));
|
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 DebuggerRunTool::setUseDebugServer(ProcessHandle attachPid, bool essential, bool useMulti)
|
||||||
|
|
||||||
void DebugServerRunner::setUseMulti(bool on)
|
|
||||||
{
|
{
|
||||||
m_useMulti = on;
|
d->useDebugServer = true;
|
||||||
}
|
d->serverAttachPid = attachPid;
|
||||||
|
d->serverEssential = essential;
|
||||||
void DebugServerRunner::setAttachPid(ProcessHandle pid)
|
d->serverUseMulti = useMulti;
|
||||||
{
|
|
||||||
m_pid = pid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DebuggerRunWorkerFactory
|
// DebuggerRunWorkerFactory
|
||||||
|
@@ -62,6 +62,7 @@ public:
|
|||||||
void setContinueAfterAttach(bool on);
|
void setContinueAfterAttach(bool on);
|
||||||
void setBreakOnMain(bool on);
|
void setBreakOnMain(bool on);
|
||||||
void setUseTerminal(bool on);
|
void setUseTerminal(bool on);
|
||||||
|
void setUseDebugServer(Utils::ProcessHandle attachPid, bool essential, bool useMulti);
|
||||||
|
|
||||||
void setCommandsAfterConnect(const QString &commands);
|
void setCommandsAfterConnect(const QString &commands);
|
||||||
void setCommandsForReset(const QString &commands);
|
void setCommandsForReset(const QString &commands);
|
||||||
@@ -115,6 +116,9 @@ private:
|
|||||||
void startTerminalIfNeededAndContinueStartup();
|
void startTerminalIfNeededAndContinueStartup();
|
||||||
void continueAfterTerminalStart();
|
void continueAfterTerminalStart();
|
||||||
|
|
||||||
|
void startDebugServerIfNeededAndContinueStartup();
|
||||||
|
void continueAfterDebugServerStart();
|
||||||
|
|
||||||
Internal::DebuggerRunToolPrivate *d;
|
Internal::DebuggerRunToolPrivate *d;
|
||||||
QList<QPointer<Internal::DebuggerEngine>> m_engines;
|
QList<QPointer<Internal::DebuggerEngine>> m_engines;
|
||||||
Internal::DebuggerRunParameters m_runParameters;
|
Internal::DebuggerRunParameters m_runParameters;
|
||||||
@@ -139,22 +143,6 @@ private:
|
|||||||
bool m_useQmlServer = false;
|
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
|
class DebuggerRunWorkerFactory final : public ProjectExplorer::RunWorkerFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -29,11 +29,7 @@ public:
|
|||||||
|
|
||||||
setUsePortsGatherer(isCppDebugging(), isQmlDebugging());
|
setUsePortsGatherer(isCppDebugging(), isQmlDebugging());
|
||||||
addQmlServerInferiorCommandLineArgumentIfNeeded();
|
addQmlServerInferiorCommandLineArgumentIfNeeded();
|
||||||
|
setUseDebugServer({}, true, true);
|
||||||
auto debugServer = new DebugServerRunner(runControl, portsGatherer());
|
|
||||||
debugServer->setEssential(true);
|
|
||||||
|
|
||||||
addStartDependency(debugServer);
|
|
||||||
|
|
||||||
setStartMode(AttachToRemoteServer);
|
setStartMode(AttachToRemoteServer);
|
||||||
setCloseMode(KillAndExitMonitorAtClose);
|
setCloseMode(KillAndExitMonitorAtClose);
|
||||||
|
Reference in New Issue
Block a user