From 32ae4d3e09732e29156e22fc9aa0745d17826eaa Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 27 Feb 2017 13:30:08 +0100 Subject: [PATCH] Debugger: Use Utils::ProcessHandle for DebuggerEngine::m_inferiorPid That's the intended "typesafe" use. Change-Id: Ib288fe87a47bd9484bda83e05406f0d22989b3c2 Reviewed-by: David Schulz --- src/plugins/debugger/cdb/cdbengine.cpp | 6 ++--- src/plugins/debugger/debuggerengine.cpp | 26 +++++++++---------- src/plugins/debugger/debuggerplugin.cpp | 24 ++++++++--------- src/plugins/debugger/debuggerruncontrol.cpp | 4 +-- .../debugger/debuggerstartparameters.h | 3 ++- src/plugins/debugger/gdb/attachgdbadapter.cpp | 5 ++-- .../debugger/gdb/remotegdbserveradapter.cpp | 11 ++++---- src/plugins/debugger/lldb/lldbengine.cpp | 6 ++--- src/plugins/qnx/qnxattachdebugsupport.cpp | 2 +- src/plugins/winrt/winrtdebugsupport.cpp | 2 +- 10 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp index db6f103a55d..a40e40feda6 100644 --- a/src/plugins/debugger/cdb/cdbengine.cpp +++ b/src/plugins/debugger/cdb/cdbengine.cpp @@ -428,10 +428,10 @@ void CdbEngine::consoleStubProcessStarted() DebuggerRunParameters attachParameters = runParameters(); attachParameters.inferior.executable.clear(); attachParameters.inferior.commandLineArguments.clear(); - attachParameters.attachPID = m_consoleStub->applicationPID(); + attachParameters.attachPID = ProcessHandle(m_consoleStub->applicationPID()); attachParameters.startMode = AttachExternal; attachParameters.useTerminal = false; - showMessage(QString("Attaching to %1...").arg(attachParameters.attachPID), LogMisc); + showMessage(QString("Attaching to %1...").arg(attachParameters.attachPID.pid()), LogMisc); QString errorMessage; if (!launchCDB(attachParameters, &errorMessage)) { showMessage(errorMessage, LogError); @@ -570,7 +570,7 @@ bool CdbEngine::launchCDB(const DebuggerRunParameters &sp, QString *errorMessage break; case AttachExternal: case AttachCrashedExternal: - arguments << "-p" << QString::number(sp.attachPID); + arguments << "-p" << QString::number(sp.attachPID.pid()); if (sp.startMode == AttachCrashedExternal) { arguments << "-e" << sp.crashParameter << "-g"; } else { diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp index 18d08e36996..5df6b0096ac 100644 --- a/src/plugins/debugger/debuggerengine.cpp +++ b/src/plugins/debugger/debuggerengine.cpp @@ -108,7 +108,7 @@ QDebug operator<<(QDebug str, const DebuggerRunParameters &sp) << " inferior environment=<" << sp.inferior.environment.size() << " variables>" << " debugger environment=<" << sp.debugger.environment.size() << " variables>" << " workingDir=" << sp.inferior.workingDirectory - << " attachPID=" << sp.attachPID + << " attachPID=" << sp.attachPID.pid() << " useTerminal=" << sp.useTerminal << " remoteChannel=" << sp.remoteChannel << " serverStartScript=" << sp.serverStartScript @@ -311,7 +311,7 @@ public: void raiseApplication() { QTC_ASSERT(runControl(), return); - runControl()->bringApplicationToForeground(m_inferiorPid); + runControl()->bringApplicationToForeground(m_inferiorPid.pid()); } void scheduleResetLocation() @@ -363,7 +363,7 @@ public: RemoteSetupState m_remoteSetupState = RemoteSetupNone; Terminal m_terminal; - qint64 m_inferiorPid = 0; + ProcessHandle m_inferiorPid; ModulesHandler m_modulesHandler; RegisterHandler m_registerHandler; @@ -593,10 +593,10 @@ void DebuggerEngine::startDebugger(DebuggerRunControl *runControl) d->m_runControl = runControl; - d->m_inferiorPid = d->m_runParameters.attachPID > 0 - ? d->m_runParameters.attachPID : 0; - if (d->m_inferiorPid) - d->m_runControl->setApplicationProcessHandle(ProcessHandle(d->m_inferiorPid)); + d->m_inferiorPid = d->m_runParameters.attachPID.isValid() + ? d->m_runParameters.attachPID : ProcessHandle(); + if (d->m_inferiorPid.isValid()) + d->m_runControl->setApplicationProcessHandle(d->m_inferiorPid); if (isNativeMixedActive()) d->m_runParameters.inferior.environment.set("QV4_FORCE_INTERPRETER", "1"); @@ -945,7 +945,7 @@ void DebuggerEngine::notifyEngineRemoteSetupFinished(const RemoteSetupResult &re } } else if (result.inferiorPid != InvalidPid && runParameters().startMode == AttachExternal) { // e.g. iOS Simulator - runParameters().attachPID = result.inferiorPid; + runParameters().attachPID = ProcessHandle(result.inferiorPid); } if (result.qmlServerPort.isValid()) { @@ -1430,11 +1430,11 @@ bool DebuggerEngine::debuggerActionsEnabled(DebuggerState state) void DebuggerEngine::notifyInferiorPid(qint64 pid) { - if (d->m_inferiorPid == pid) + if (d->m_inferiorPid.pid() == pid) return; - d->m_inferiorPid = pid; - if (pid) { - runControl()->setApplicationProcessHandle(ProcessHandle(pid)); + d->m_inferiorPid = ProcessHandle(pid); + if (d->m_inferiorPid.isValid()) { + runControl()->setApplicationProcessHandle(d->m_inferiorPid); showMessage(tr("Taking notice of pid %1").arg(pid)); if (d->m_runParameters.startMode == StartInternal || d->m_runParameters.startMode == StartExternal @@ -1445,7 +1445,7 @@ void DebuggerEngine::notifyInferiorPid(qint64 pid) qint64 DebuggerEngine::inferiorPid() const { - return d->m_inferiorPid; + return d->m_inferiorPid.pid(); } bool DebuggerEngine::isReverseDebugging() const diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 509a17cf92d..4223065c145 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1166,9 +1166,9 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it, if (pid) { rp.startMode = AttachExternal; rp.closeMode = DetachAtClose; - rp.attachPID = pid; - rp.displayName = tr("Process %1").arg(rp.attachPID); - rp.startMessage = tr("Attaching to local process %1.").arg(rp.attachPID); + rp.attachPID = ProcessHandle(pid); + rp.displayName = tr("Process %1").arg(rp.attachPID.pid()); + rp.startMessage = tr("Attaching to local process %1.").arg(rp.attachPID.pid()); } else { rp.startMode = StartExternal; QStringList args = it->split(QLatin1Char(',')); @@ -1230,10 +1230,10 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it, DebuggerRunParameters rp; rp.startMode = AttachCrashedExternal; rp.crashParameter = it->section(QLatin1Char(':'), 0, 0); - rp.attachPID = it->section(QLatin1Char(':'), 1, 1).toULongLong(); - rp.displayName = tr("Crashed process %1").arg(rp.attachPID); - rp.startMessage = tr("Attaching to crashed process %1").arg(rp.attachPID); - if (!rp.attachPID) { + rp.attachPID = ProcessHandle(it->section(QLatin1Char(':'), 1, 1).toULongLong()); + rp.displayName = tr("Crashed process %1").arg(rp.attachPID.pid()); + rp.startMessage = tr("Attaching to crashed process %1").arg(rp.attachPID.pid()); + if (!rp.attachPID.isValid()) { *errorMessage = DebuggerPlugin::tr("The parameter \"%1\" of option \"%2\" " "does not match the pattern :.").arg(*it, option); return false; @@ -2108,7 +2108,7 @@ DebuggerRunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit, } DebuggerRunParameters rp; - rp.attachPID = process.pid; + rp.attachPID = ProcessHandle(process.pid); rp.displayName = tr("Process %1").arg(process.pid); rp.inferior.executable = process.exe; rp.startMode = AttachExternal; @@ -2120,8 +2120,8 @@ DebuggerRunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit, void DebuggerPlugin::attachExternalApplication(RunControl *rc) { DebuggerRunParameters rp; - rp.attachPID = rc->applicationProcessHandle().pid(); - rp.displayName = tr("Process %1").arg(rp.attachPID); + rp.attachPID = rc->applicationProcessHandle(); + rp.displayName = tr("Process %1").arg(rp.attachPID.pid()); rp.startMode = AttachExternal; rp.closeMode = DetachAtClose; rp.toolChainAbi = rc->abi(); @@ -2924,8 +2924,8 @@ static QString formatStartParameters(DebuggerRunParameters &sp) str << "Debugger: " << QDir::toNativeSeparators(cmd) << '\n'; if (!sp.coreFile.isEmpty()) str << "Core: " << QDir::toNativeSeparators(sp.coreFile) << '\n'; - if (sp.attachPID > 0) - str << "PID: " << sp.attachPID << ' ' << sp.crashParameter << '\n'; + if (sp.attachPID.isValid()) + str << "PID: " << sp.attachPID.pid() << ' ' << sp.crashParameter << '\n'; if (!sp.projectSourceDirectory.isEmpty()) { str << "Project: " << QDir::toNativeSeparators(sp.projectSourceDirectory); str << "Addtional Search Directories:" diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index c31cbff9943..426b36df042 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -380,9 +380,9 @@ static DebuggerRunControl *doCreate(DebuggerRunParameters rp, RunConfiguration * } // We might get an executable from a local PID. - if (rp.inferior.executable.isEmpty() && rp.attachPID != InvalidPid) { + if (rp.inferior.executable.isEmpty() && rp.attachPID.isValid()) { foreach (const DeviceProcessItem &p, DeviceProcessList::localProcesses()) - if (p.pid == rp.attachPID) + if (p.pid == rp.attachPID.pid()) rp.inferior.executable = p.exe; } diff --git a/src/plugins/debugger/debuggerstartparameters.h b/src/plugins/debugger/debuggerstartparameters.h index 4bf7236609c..8d1627c1eae 100644 --- a/src/plugins/debugger/debuggerstartparameters.h +++ b/src/plugins/debugger/debuggerstartparameters.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -73,7 +74,7 @@ public: ProjectExplorer::StandardRunnable inferior; QString displayName; // Used in the Snapshots view. Utils::Environment stubEnvironment; - qint64 attachPID = InvalidPid; + Utils::ProcessHandle attachPID; QStringList solibSearchPath; bool useTerminal = false; diff --git a/src/plugins/debugger/gdb/attachgdbadapter.cpp b/src/plugins/debugger/gdb/attachgdbadapter.cpp index dc274922531..0f0f0b0374a 100644 --- a/src/plugins/debugger/gdb/attachgdbadapter.cpp +++ b/src/plugins/debugger/gdb/attachgdbadapter.cpp @@ -59,7 +59,7 @@ void GdbAttachEngine::setupInferior() void GdbAttachEngine::runEngine() { QTC_ASSERT(state() == EngineRunRequested, qDebug() << state()); - const qint64 pid = runParameters().attachPID; + const qint64 pid = runParameters().attachPID.pid(); showStatusMessage(tr("Attaching to process %1.").arg(pid)); runCommand({"attach " + QString::number(pid), [this](const DebuggerResponse &r) { handleAttach(r); }}); @@ -110,10 +110,9 @@ void GdbAttachEngine::handleAttach(const DebuggerResponse &response) } } - void GdbAttachEngine::interruptInferior2() { - interruptLocalInferior(runParameters().attachPID); + interruptLocalInferior(runParameters().attachPID.pid()); } void GdbAttachEngine::shutdownEngine() diff --git a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp index 10c7e4c280b..4b18434308c 100644 --- a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp +++ b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp @@ -294,9 +294,9 @@ void GdbRemoteServerEngine::handleTargetExtendedRemote(const DebuggerResponse &r QString commands = expand(stringSetting(GdbPostAttachCommands)); if (!commands.isEmpty()) runCommand({commands, NativeCommand}); - if (runParameters().attachPID > 0) { // attach to pid if valid + if (runParameters().attachPID.isValid()) { // attach to pid if valid // gdb server will stop the remote application itself. - runCommand({"attach " + QString::number(runParameters().attachPID), + runCommand({"attach " + QString::number(runParameters().attachPID.pid()), CB(handleTargetExtendedAttach)}); } else if (!runParameters().inferior.executable.isEmpty()) { runCommand({"-gdb-set remote exec-file " + runParameters().inferior.executable, @@ -347,10 +347,9 @@ void GdbRemoteServerEngine::handleTargetQnx(const DebuggerResponse &response) showMessage(msgAttachedToStoppedInferior(), StatusBar); const DebuggerRunParameters &rp = isMasterEngine() ? runParameters() : masterEngine()->runParameters(); - const qint64 pid = rp.attachPID; const QString remoteExecutable = rp.inferior.executable; - if (pid > -1) - runCommand({"attach " + QString::number(pid), CB(handleAttach)}); + if (rp.attachPID.isValid()) + runCommand({"attach " + QString::number(rp.attachPID.pid()), CB(handleAttach)}); else if (!remoteExecutable.isEmpty()) runCommand({"set nto-executable " + remoteExecutable, CB(handleSetNtoExecutable)}); else @@ -465,7 +464,7 @@ void GdbRemoteServerEngine::notifyEngineRemoteServerRunning (const QString &serverChannel, int inferiorPid) { // Currently only used by Android support. - runParameters().attachPID = inferiorPid; + runParameters().attachPID = Utils::ProcessHandle(inferiorPid); runParameters().remoteChannel = serverChannel; runParameters().useExtendedRemote = true; showMessage("NOTE: REMOTE SERVER RUNNING IN MULTIMODE"); diff --git a/src/plugins/debugger/lldb/lldbengine.cpp b/src/plugins/debugger/lldb/lldbengine.cpp index 047ce0beea8..07695256208 100644 --- a/src/plugins/debugger/lldb/lldbengine.cpp +++ b/src/plugins/debugger/lldb/lldbengine.cpp @@ -366,9 +366,9 @@ void LldbEngine::setupInferior() cmd2.arg("startmode", rp.startMode); // it is better not to check the start mode on the python sid (as we would have to duplicate the // enum values), and thus we assume that if the rp.attachPID is valid we really have to attach - QTC_CHECK(rp.attachPID <= 0 || (rp.startMode == AttachCrashedExternal - || rp.startMode == AttachExternal)); - cmd2.arg("attachpid", rp.attachPID); + QTC_CHECK(!rp.attachPID.isValid() || (rp.startMode == AttachCrashedExternal + || rp.startMode == AttachExternal)); + cmd2.arg("attachpid", rp.attachPID.pid()); cmd2.arg("sysroot", rp.deviceSymbolsRoot.isEmpty() ? rp.sysRoot : rp.deviceSymbolsRoot); cmd2.arg("remotechannel", ((rp.startMode == AttachToRemoteProcess || rp.startMode == AttachToRemoteServer) diff --git a/src/plugins/qnx/qnxattachdebugsupport.cpp b/src/plugins/qnx/qnxattachdebugsupport.cpp index 82f3c0e74b5..3fac0873fb2 100644 --- a/src/plugins/qnx/qnxattachdebugsupport.cpp +++ b/src/plugins/qnx/qnxattachdebugsupport.cpp @@ -119,7 +119,7 @@ void QnxAttachDebugSupport::launchPDebug() void QnxAttachDebugSupport::attachToProcess() { Debugger::DebuggerStartParameters sp; - sp.attachPID = m_process.pid; + sp.attachPID = Utils::ProcessHandle(m_process.pid); sp.startMode = Debugger::AttachToRemoteServer; sp.closeMode = Debugger::DetachAtClose; sp.connParams.port = m_pdebugPort.number(); diff --git a/src/plugins/winrt/winrtdebugsupport.cpp b/src/plugins/winrt/winrtdebugsupport.cpp index 89cca7dd664..92c553796d0 100644 --- a/src/plugins/winrt/winrtdebugsupport.cpp +++ b/src/plugins/winrt/winrtdebugsupport.cpp @@ -138,7 +138,7 @@ RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runC QList arg = output.split(':'); if (arg.first() == "PID") { bool ok =false; - params.attachPID = arg.last().toInt(&ok); + params.attachPID = Utils::ProcessHandle(arg.last().toInt(&ok)); if (!ok) { *errorMessage = tr("Cannot extract the PID from the WinRT debugging helper. " "(output: %1)").arg(QString::fromLocal8Bit(output));