forked from qt-creator/qt-creator
Valgrind: Use StandardRunnable in ValgrindRunner and ValgrindProcess
Change-Id: I17def50bbf6887b63d676fdb245064f1df2003de Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -40,8 +40,7 @@ namespace Valgrind {
|
||||
ValgrindProcess::ValgrindProcess(bool isLocal, const QSsh::SshConnectionParameters &sshParams,
|
||||
QSsh::SshConnection *connection, QObject *parent)
|
||||
: QObject(parent),
|
||||
m_isLocal(isLocal),
|
||||
m_localRunMode(ApplicationLauncher::Gui)
|
||||
m_isLocal(isLocal)
|
||||
{
|
||||
m_remote.m_params = sshParams;
|
||||
m_remote.m_connection = connection;
|
||||
@@ -56,20 +55,9 @@ void ValgrindProcess::setProcessChannelMode(QProcess::ProcessChannelMode mode)
|
||||
///TODO: remote support this by handling the mode internally
|
||||
}
|
||||
|
||||
void ValgrindProcess::setWorkingDirectory(const QString &path)
|
||||
{
|
||||
if (isLocal())
|
||||
m_localProcess.setWorkingDirectory(path);
|
||||
else
|
||||
m_remote.m_workingDir = path;
|
||||
}
|
||||
|
||||
QString ValgrindProcess::workingDirectory() const
|
||||
{
|
||||
if (isLocal())
|
||||
return m_localProcess.workingDirectory();
|
||||
else
|
||||
return m_remote.m_workingDir;
|
||||
return m_debuggee.workingDirectory;
|
||||
}
|
||||
|
||||
bool ValgrindProcess::isRunning() const
|
||||
@@ -85,33 +73,21 @@ void ValgrindProcess::setValgrindExecutable(const QString &valgrindExecutable)
|
||||
m_valgrindExecutable = valgrindExecutable;
|
||||
}
|
||||
|
||||
void ValgrindProcess::setDebuggee(const StandardRunnable &debuggee)
|
||||
{
|
||||
m_debuggee = debuggee;
|
||||
if (isLocal()) {
|
||||
m_localProcess.setWorkingDirectory(m_debuggee.workingDirectory);
|
||||
m_localProcess.setEnvironment(m_debuggee.environment);
|
||||
///TODO: remote anything that should/could be done here?
|
||||
}
|
||||
}
|
||||
|
||||
void ValgrindProcess::setValgrindArguments(const QStringList &valgrindArguments)
|
||||
{
|
||||
m_valgrindArguments = valgrindArguments;
|
||||
}
|
||||
|
||||
void ValgrindProcess::setDebuggeeExecutable(const QString &debuggeeExecutable)
|
||||
{
|
||||
m_debuggeeExecutable = debuggeeExecutable;
|
||||
}
|
||||
|
||||
void ValgrindProcess::setDebugeeArguments(const QString &debuggeeArguments)
|
||||
{
|
||||
m_debuggeeArguments = debuggeeArguments;
|
||||
}
|
||||
|
||||
void ValgrindProcess::setEnvironment(const Utils::Environment &environment)
|
||||
{
|
||||
if (isLocal())
|
||||
m_localProcess.setEnvironment(environment);
|
||||
///TODO: remote anything that should/could be done here?
|
||||
}
|
||||
|
||||
void ValgrindProcess::setLocalRunMode(ApplicationLauncher::Mode localRunMode)
|
||||
{
|
||||
m_localRunMode = localRunMode;
|
||||
}
|
||||
|
||||
void ValgrindProcess::close()
|
||||
{
|
||||
if (isLocal()) {
|
||||
@@ -146,13 +122,10 @@ void ValgrindProcess::run()
|
||||
connect(&m_localProcess, &ApplicationLauncher::appendMessage,
|
||||
this, &ValgrindProcess::processOutput);
|
||||
|
||||
m_localProcess.start(m_localRunMode, m_valgrindExecutable,
|
||||
m_localProcess.start(m_debuggee.runMode, m_valgrindExecutable,
|
||||
argumentString(Utils::HostOsInfo::hostOs()));
|
||||
|
||||
} else {
|
||||
m_remote.m_valgrindExe = m_valgrindExecutable;
|
||||
m_remote.m_debuggee = m_debuggeeExecutable;
|
||||
|
||||
// connect to host and wait for connection
|
||||
if (!m_remote.m_connection)
|
||||
m_remote.m_connection = new QSsh::SshConnection(m_remote.m_params, this);
|
||||
@@ -231,10 +204,10 @@ void ValgrindProcess::connected()
|
||||
// connected, run command
|
||||
QString cmd;
|
||||
|
||||
if (!m_remote.m_workingDir.isEmpty())
|
||||
cmd += QString::fromLatin1("cd '%1' && ").arg(m_remote.m_workingDir);
|
||||
if (!m_debuggee.workingDirectory.isEmpty())
|
||||
cmd += QString::fromLatin1("cd '%1' && ").arg(m_debuggee.workingDirectory);
|
||||
|
||||
cmd += m_remote.m_valgrindExe + QLatin1Char(' ') + argumentString(Utils::OsTypeLinux);
|
||||
cmd += m_valgrindExecutable + QLatin1Char(' ') + argumentString(Utils::OsTypeLinux);
|
||||
|
||||
m_remote.m_process = m_remote.m_connection->createRemoteProcess(cmd.toUtf8());
|
||||
connect(m_remote.m_process.data(), &QSsh::SshRemoteProcess::readyReadStandardError,
|
||||
@@ -272,7 +245,7 @@ void ValgrindProcess::remoteProcessStarted()
|
||||
// hence we need to do something more complex...
|
||||
|
||||
// plain path to exe, m_valgrindExe contains e.g. env vars etc. pp.
|
||||
const QString proc = m_remote.m_valgrindExe.split(QLatin1Char(' ')).last();
|
||||
const QString proc = m_valgrindExecutable.split(QLatin1Char(' ')).last();
|
||||
// sleep required since otherwise we might only match "bash -c..."
|
||||
// and not the actual valgrind run
|
||||
const QString cmd = QString::fromLatin1("sleep 1; ps ax" // list all processes with aliased name
|
||||
@@ -280,7 +253,7 @@ void ValgrindProcess::remoteProcessStarted()
|
||||
" | tail -n 1" // limit to single process
|
||||
// we pick the last one, first would be "bash -c ..."
|
||||
" | awk '{print $1;}'" // get pid
|
||||
).arg(proc, Utils::FileName::fromString(m_remote.m_debuggee).fileName());
|
||||
).arg(proc, Utils::FileName::fromString(m_debuggee.executable).fileName());
|
||||
|
||||
m_remote.m_findPID = m_remote.m_connection->createRemoteProcess(cmd.toUtf8());
|
||||
connect(m_remote.m_findPID.data(), &QSsh::SshRemoteProcess::readyReadStandardError,
|
||||
@@ -308,15 +281,12 @@ void ValgrindProcess::findPIDOutputReceived()
|
||||
QString ValgrindProcess::argumentString(Utils::OsType osType) const
|
||||
{
|
||||
QString arguments = Utils::QtcProcess::joinArgs(m_valgrindArguments, osType);
|
||||
if (!m_debuggeeExecutable.isEmpty())
|
||||
Utils::QtcProcess::addArg(&arguments, m_debuggeeExecutable, osType);
|
||||
Utils::QtcProcess::addArgs(&arguments, m_debuggeeArguments);
|
||||
if (!m_debuggee.executable.isEmpty())
|
||||
Utils::QtcProcess::addArg(&arguments, m_debuggee.executable, osType);
|
||||
Utils::QtcProcess::addArgs(&arguments, m_debuggee.commandLineArguments);
|
||||
return arguments;
|
||||
}
|
||||
|
||||
|
||||
///////////
|
||||
|
||||
void ValgrindProcess::closed(int status)
|
||||
{
|
||||
QTC_ASSERT(m_remote.m_process, return);
|
||||
|
||||
Reference in New Issue
Block a user