Debugger: Use Utils::ProcessHandle for DebuggerEngine::m_inferiorPid

That's the intended "typesafe" use.

Change-Id: Ib288fe87a47bd9484bda83e05406f0d22989b3c2
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2017-02-27 13:30:08 +01:00
parent 96f615b477
commit 32ae4d3e09
10 changed files with 44 additions and 45 deletions

View File

@@ -428,10 +428,10 @@ void CdbEngine::consoleStubProcessStarted()
DebuggerRunParameters attachParameters = runParameters(); DebuggerRunParameters attachParameters = runParameters();
attachParameters.inferior.executable.clear(); attachParameters.inferior.executable.clear();
attachParameters.inferior.commandLineArguments.clear(); attachParameters.inferior.commandLineArguments.clear();
attachParameters.attachPID = m_consoleStub->applicationPID(); attachParameters.attachPID = ProcessHandle(m_consoleStub->applicationPID());
attachParameters.startMode = AttachExternal; attachParameters.startMode = AttachExternal;
attachParameters.useTerminal = false; attachParameters.useTerminal = false;
showMessage(QString("Attaching to %1...").arg(attachParameters.attachPID), LogMisc); showMessage(QString("Attaching to %1...").arg(attachParameters.attachPID.pid()), LogMisc);
QString errorMessage; QString errorMessage;
if (!launchCDB(attachParameters, &errorMessage)) { if (!launchCDB(attachParameters, &errorMessage)) {
showMessage(errorMessage, LogError); showMessage(errorMessage, LogError);
@@ -570,7 +570,7 @@ bool CdbEngine::launchCDB(const DebuggerRunParameters &sp, QString *errorMessage
break; break;
case AttachExternal: case AttachExternal:
case AttachCrashedExternal: case AttachCrashedExternal:
arguments << "-p" << QString::number(sp.attachPID); arguments << "-p" << QString::number(sp.attachPID.pid());
if (sp.startMode == AttachCrashedExternal) { if (sp.startMode == AttachCrashedExternal) {
arguments << "-e" << sp.crashParameter << "-g"; arguments << "-e" << sp.crashParameter << "-g";
} else { } else {

View File

@@ -108,7 +108,7 @@ QDebug operator<<(QDebug str, const DebuggerRunParameters &sp)
<< " inferior environment=<" << sp.inferior.environment.size() << " variables>" << " inferior environment=<" << sp.inferior.environment.size() << " variables>"
<< " debugger environment=<" << sp.debugger.environment.size() << " variables>" << " debugger environment=<" << sp.debugger.environment.size() << " variables>"
<< " workingDir=" << sp.inferior.workingDirectory << " workingDir=" << sp.inferior.workingDirectory
<< " attachPID=" << sp.attachPID << " attachPID=" << sp.attachPID.pid()
<< " useTerminal=" << sp.useTerminal << " useTerminal=" << sp.useTerminal
<< " remoteChannel=" << sp.remoteChannel << " remoteChannel=" << sp.remoteChannel
<< " serverStartScript=" << sp.serverStartScript << " serverStartScript=" << sp.serverStartScript
@@ -311,7 +311,7 @@ public:
void raiseApplication() void raiseApplication()
{ {
QTC_ASSERT(runControl(), return); QTC_ASSERT(runControl(), return);
runControl()->bringApplicationToForeground(m_inferiorPid); runControl()->bringApplicationToForeground(m_inferiorPid.pid());
} }
void scheduleResetLocation() void scheduleResetLocation()
@@ -363,7 +363,7 @@ public:
RemoteSetupState m_remoteSetupState = RemoteSetupNone; RemoteSetupState m_remoteSetupState = RemoteSetupNone;
Terminal m_terminal; Terminal m_terminal;
qint64 m_inferiorPid = 0; ProcessHandle m_inferiorPid;
ModulesHandler m_modulesHandler; ModulesHandler m_modulesHandler;
RegisterHandler m_registerHandler; RegisterHandler m_registerHandler;
@@ -593,10 +593,10 @@ void DebuggerEngine::startDebugger(DebuggerRunControl *runControl)
d->m_runControl = runControl; d->m_runControl = runControl;
d->m_inferiorPid = d->m_runParameters.attachPID > 0 d->m_inferiorPid = d->m_runParameters.attachPID.isValid()
? d->m_runParameters.attachPID : 0; ? d->m_runParameters.attachPID : ProcessHandle();
if (d->m_inferiorPid) if (d->m_inferiorPid.isValid())
d->m_runControl->setApplicationProcessHandle(ProcessHandle(d->m_inferiorPid)); d->m_runControl->setApplicationProcessHandle(d->m_inferiorPid);
if (isNativeMixedActive()) if (isNativeMixedActive())
d->m_runParameters.inferior.environment.set("QV4_FORCE_INTERPRETER", "1"); 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) { } else if (result.inferiorPid != InvalidPid && runParameters().startMode == AttachExternal) {
// e.g. iOS Simulator // e.g. iOS Simulator
runParameters().attachPID = result.inferiorPid; runParameters().attachPID = ProcessHandle(result.inferiorPid);
} }
if (result.qmlServerPort.isValid()) { if (result.qmlServerPort.isValid()) {
@@ -1430,11 +1430,11 @@ bool DebuggerEngine::debuggerActionsEnabled(DebuggerState state)
void DebuggerEngine::notifyInferiorPid(qint64 pid) void DebuggerEngine::notifyInferiorPid(qint64 pid)
{ {
if (d->m_inferiorPid == pid) if (d->m_inferiorPid.pid() == pid)
return; return;
d->m_inferiorPid = pid; d->m_inferiorPid = ProcessHandle(pid);
if (pid) { if (d->m_inferiorPid.isValid()) {
runControl()->setApplicationProcessHandle(ProcessHandle(pid)); runControl()->setApplicationProcessHandle(d->m_inferiorPid);
showMessage(tr("Taking notice of pid %1").arg(pid)); showMessage(tr("Taking notice of pid %1").arg(pid));
if (d->m_runParameters.startMode == StartInternal if (d->m_runParameters.startMode == StartInternal
|| d->m_runParameters.startMode == StartExternal || d->m_runParameters.startMode == StartExternal
@@ -1445,7 +1445,7 @@ void DebuggerEngine::notifyInferiorPid(qint64 pid)
qint64 DebuggerEngine::inferiorPid() const qint64 DebuggerEngine::inferiorPid() const
{ {
return d->m_inferiorPid; return d->m_inferiorPid.pid();
} }
bool DebuggerEngine::isReverseDebugging() const bool DebuggerEngine::isReverseDebugging() const

View File

@@ -1166,9 +1166,9 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
if (pid) { if (pid) {
rp.startMode = AttachExternal; rp.startMode = AttachExternal;
rp.closeMode = DetachAtClose; rp.closeMode = DetachAtClose;
rp.attachPID = pid; rp.attachPID = ProcessHandle(pid);
rp.displayName = tr("Process %1").arg(rp.attachPID); rp.displayName = tr("Process %1").arg(rp.attachPID.pid());
rp.startMessage = tr("Attaching to local process %1.").arg(rp.attachPID); rp.startMessage = tr("Attaching to local process %1.").arg(rp.attachPID.pid());
} else { } else {
rp.startMode = StartExternal; rp.startMode = StartExternal;
QStringList args = it->split(QLatin1Char(',')); QStringList args = it->split(QLatin1Char(','));
@@ -1230,10 +1230,10 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
DebuggerRunParameters rp; DebuggerRunParameters rp;
rp.startMode = AttachCrashedExternal; rp.startMode = AttachCrashedExternal;
rp.crashParameter = it->section(QLatin1Char(':'), 0, 0); rp.crashParameter = it->section(QLatin1Char(':'), 0, 0);
rp.attachPID = it->section(QLatin1Char(':'), 1, 1).toULongLong(); rp.attachPID = ProcessHandle(it->section(QLatin1Char(':'), 1, 1).toULongLong());
rp.displayName = tr("Crashed process %1").arg(rp.attachPID); rp.displayName = tr("Crashed process %1").arg(rp.attachPID.pid());
rp.startMessage = tr("Attaching to crashed process %1").arg(rp.attachPID); rp.startMessage = tr("Attaching to crashed process %1").arg(rp.attachPID.pid());
if (!rp.attachPID) { if (!rp.attachPID.isValid()) {
*errorMessage = DebuggerPlugin::tr("The parameter \"%1\" of option \"%2\" " *errorMessage = DebuggerPlugin::tr("The parameter \"%1\" of option \"%2\" "
"does not match the pattern <handle>:<pid>.").arg(*it, option); "does not match the pattern <handle>:<pid>.").arg(*it, option);
return false; return false;
@@ -2108,7 +2108,7 @@ DebuggerRunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit,
} }
DebuggerRunParameters rp; DebuggerRunParameters rp;
rp.attachPID = process.pid; rp.attachPID = ProcessHandle(process.pid);
rp.displayName = tr("Process %1").arg(process.pid); rp.displayName = tr("Process %1").arg(process.pid);
rp.inferior.executable = process.exe; rp.inferior.executable = process.exe;
rp.startMode = AttachExternal; rp.startMode = AttachExternal;
@@ -2120,8 +2120,8 @@ DebuggerRunControl *DebuggerPluginPrivate::attachToRunningProcess(Kit *kit,
void DebuggerPlugin::attachExternalApplication(RunControl *rc) void DebuggerPlugin::attachExternalApplication(RunControl *rc)
{ {
DebuggerRunParameters rp; DebuggerRunParameters rp;
rp.attachPID = rc->applicationProcessHandle().pid(); rp.attachPID = rc->applicationProcessHandle();
rp.displayName = tr("Process %1").arg(rp.attachPID); rp.displayName = tr("Process %1").arg(rp.attachPID.pid());
rp.startMode = AttachExternal; rp.startMode = AttachExternal;
rp.closeMode = DetachAtClose; rp.closeMode = DetachAtClose;
rp.toolChainAbi = rc->abi(); rp.toolChainAbi = rc->abi();
@@ -2924,8 +2924,8 @@ static QString formatStartParameters(DebuggerRunParameters &sp)
str << "Debugger: " << QDir::toNativeSeparators(cmd) << '\n'; str << "Debugger: " << QDir::toNativeSeparators(cmd) << '\n';
if (!sp.coreFile.isEmpty()) if (!sp.coreFile.isEmpty())
str << "Core: " << QDir::toNativeSeparators(sp.coreFile) << '\n'; str << "Core: " << QDir::toNativeSeparators(sp.coreFile) << '\n';
if (sp.attachPID > 0) if (sp.attachPID.isValid())
str << "PID: " << sp.attachPID << ' ' << sp.crashParameter << '\n'; str << "PID: " << sp.attachPID.pid() << ' ' << sp.crashParameter << '\n';
if (!sp.projectSourceDirectory.isEmpty()) { if (!sp.projectSourceDirectory.isEmpty()) {
str << "Project: " << QDir::toNativeSeparators(sp.projectSourceDirectory); str << "Project: " << QDir::toNativeSeparators(sp.projectSourceDirectory);
str << "Addtional Search Directories:" str << "Addtional Search Directories:"

View File

@@ -380,9 +380,9 @@ static DebuggerRunControl *doCreate(DebuggerRunParameters rp, RunConfiguration *
} }
// We might get an executable from a local PID. // 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()) foreach (const DeviceProcessItem &p, DeviceProcessList::localProcesses())
if (p.pid == rp.attachPID) if (p.pid == rp.attachPID.pid())
rp.inferior.executable = p.exe; rp.inferior.executable = p.exe;
} }

View File

@@ -31,6 +31,7 @@
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/port.h> #include <utils/port.h>
#include <utils/processhandle.h>
#include <projectexplorer/abi.h> #include <projectexplorer/abi.h>
#include <projectexplorer/runconfiguration.h> #include <projectexplorer/runconfiguration.h>
#include <projectexplorer/runnables.h> #include <projectexplorer/runnables.h>
@@ -73,7 +74,7 @@ public:
ProjectExplorer::StandardRunnable inferior; ProjectExplorer::StandardRunnable inferior;
QString displayName; // Used in the Snapshots view. QString displayName; // Used in the Snapshots view.
Utils::Environment stubEnvironment; Utils::Environment stubEnvironment;
qint64 attachPID = InvalidPid; Utils::ProcessHandle attachPID;
QStringList solibSearchPath; QStringList solibSearchPath;
bool useTerminal = false; bool useTerminal = false;

View File

@@ -59,7 +59,7 @@ void GdbAttachEngine::setupInferior()
void GdbAttachEngine::runEngine() void GdbAttachEngine::runEngine()
{ {
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state()); 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)); showStatusMessage(tr("Attaching to process %1.").arg(pid));
runCommand({"attach " + QString::number(pid), runCommand({"attach " + QString::number(pid),
[this](const DebuggerResponse &r) { handleAttach(r); }}); [this](const DebuggerResponse &r) { handleAttach(r); }});
@@ -110,10 +110,9 @@ void GdbAttachEngine::handleAttach(const DebuggerResponse &response)
} }
} }
void GdbAttachEngine::interruptInferior2() void GdbAttachEngine::interruptInferior2()
{ {
interruptLocalInferior(runParameters().attachPID); interruptLocalInferior(runParameters().attachPID.pid());
} }
void GdbAttachEngine::shutdownEngine() void GdbAttachEngine::shutdownEngine()

View File

@@ -294,9 +294,9 @@ void GdbRemoteServerEngine::handleTargetExtendedRemote(const DebuggerResponse &r
QString commands = expand(stringSetting(GdbPostAttachCommands)); QString commands = expand(stringSetting(GdbPostAttachCommands));
if (!commands.isEmpty()) if (!commands.isEmpty())
runCommand({commands, NativeCommand}); 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. // gdb server will stop the remote application itself.
runCommand({"attach " + QString::number(runParameters().attachPID), runCommand({"attach " + QString::number(runParameters().attachPID.pid()),
CB(handleTargetExtendedAttach)}); CB(handleTargetExtendedAttach)});
} else if (!runParameters().inferior.executable.isEmpty()) { } else if (!runParameters().inferior.executable.isEmpty()) {
runCommand({"-gdb-set remote exec-file " + runParameters().inferior.executable, runCommand({"-gdb-set remote exec-file " + runParameters().inferior.executable,
@@ -347,10 +347,9 @@ void GdbRemoteServerEngine::handleTargetQnx(const DebuggerResponse &response)
showMessage(msgAttachedToStoppedInferior(), StatusBar); showMessage(msgAttachedToStoppedInferior(), StatusBar);
const DebuggerRunParameters &rp = isMasterEngine() ? runParameters() : masterEngine()->runParameters(); const DebuggerRunParameters &rp = isMasterEngine() ? runParameters() : masterEngine()->runParameters();
const qint64 pid = rp.attachPID;
const QString remoteExecutable = rp.inferior.executable; const QString remoteExecutable = rp.inferior.executable;
if (pid > -1) if (rp.attachPID.isValid())
runCommand({"attach " + QString::number(pid), CB(handleAttach)}); runCommand({"attach " + QString::number(rp.attachPID.pid()), CB(handleAttach)});
else if (!remoteExecutable.isEmpty()) else if (!remoteExecutable.isEmpty())
runCommand({"set nto-executable " + remoteExecutable, CB(handleSetNtoExecutable)}); runCommand({"set nto-executable " + remoteExecutable, CB(handleSetNtoExecutable)});
else else
@@ -465,7 +464,7 @@ void GdbRemoteServerEngine::notifyEngineRemoteServerRunning
(const QString &serverChannel, int inferiorPid) (const QString &serverChannel, int inferiorPid)
{ {
// Currently only used by Android support. // Currently only used by Android support.
runParameters().attachPID = inferiorPid; runParameters().attachPID = Utils::ProcessHandle(inferiorPid);
runParameters().remoteChannel = serverChannel; runParameters().remoteChannel = serverChannel;
runParameters().useExtendedRemote = true; runParameters().useExtendedRemote = true;
showMessage("NOTE: REMOTE SERVER RUNNING IN MULTIMODE"); showMessage("NOTE: REMOTE SERVER RUNNING IN MULTIMODE");

View File

@@ -366,9 +366,9 @@ void LldbEngine::setupInferior()
cmd2.arg("startmode", rp.startMode); 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 // 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 // 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 QTC_CHECK(!rp.attachPID.isValid() || (rp.startMode == AttachCrashedExternal
|| rp.startMode == AttachExternal)); || rp.startMode == AttachExternal));
cmd2.arg("attachpid", rp.attachPID); cmd2.arg("attachpid", rp.attachPID.pid());
cmd2.arg("sysroot", rp.deviceSymbolsRoot.isEmpty() ? rp.sysRoot : rp.deviceSymbolsRoot); cmd2.arg("sysroot", rp.deviceSymbolsRoot.isEmpty() ? rp.sysRoot : rp.deviceSymbolsRoot);
cmd2.arg("remotechannel", ((rp.startMode == AttachToRemoteProcess cmd2.arg("remotechannel", ((rp.startMode == AttachToRemoteProcess
|| rp.startMode == AttachToRemoteServer) || rp.startMode == AttachToRemoteServer)

View File

@@ -119,7 +119,7 @@ void QnxAttachDebugSupport::launchPDebug()
void QnxAttachDebugSupport::attachToProcess() void QnxAttachDebugSupport::attachToProcess()
{ {
Debugger::DebuggerStartParameters sp; Debugger::DebuggerStartParameters sp;
sp.attachPID = m_process.pid; sp.attachPID = Utils::ProcessHandle(m_process.pid);
sp.startMode = Debugger::AttachToRemoteServer; sp.startMode = Debugger::AttachToRemoteServer;
sp.closeMode = Debugger::DetachAtClose; sp.closeMode = Debugger::DetachAtClose;
sp.connParams.port = m_pdebugPort.number(); sp.connParams.port = m_pdebugPort.number();

View File

@@ -138,7 +138,7 @@ RunControl *WinRtDebugSupport::createDebugRunControl(WinRtRunConfiguration *runC
QList<QByteArray> arg = output.split(':'); QList<QByteArray> arg = output.split(':');
if (arg.first() == "PID") { if (arg.first() == "PID") {
bool ok =false; bool ok =false;
params.attachPID = arg.last().toInt(&ok); params.attachPID = Utils::ProcessHandle(arg.last().toInt(&ok));
if (!ok) { if (!ok) {
*errorMessage = tr("Cannot extract the PID from the WinRT debugging helper. " *errorMessage = tr("Cannot extract the PID from the WinRT debugging helper. "
"(output: %1)").arg(QString::fromLocal8Bit(output)); "(output: %1)").arg(QString::fromLocal8Bit(output));