Valgrind: Use StandardRunnable in ValgrindRunner and ValgrindProcess

Change-Id: I17def50bbf6887b63d676fdb245064f1df2003de
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
hjk
2016-01-25 17:15:54 +01:00
parent 96a9f1011f
commit 9a3b340c00
6 changed files with 61 additions and 162 deletions

View File

@@ -131,8 +131,6 @@ void CallgrindController::run(Option option)
const int pid = Utils::HostOsInfo::isWindowsHost() ? 0 : m_valgrindProc->pid(); const int pid = Utils::HostOsInfo::isWindowsHost() ? 0 : m_valgrindProc->pid();
m_process->setValgrindExecutable(CALLGRIND_CONTROL_BINARY); m_process->setValgrindExecutable(CALLGRIND_CONTROL_BINARY);
m_process->setValgrindArguments(QStringList() << optionString << QString::number(pid)); m_process->setValgrindArguments(QStringList() << optionString << QString::number(pid));
m_process->setDebuggeeExecutable(QString());
m_process->setDebugeeArguments(QString());
m_process->run(); m_process->run();
} }

View File

@@ -83,16 +83,19 @@ bool ValgrindRunControl::startEngine()
emit outputReceived(tr("Command line arguments: %1").arg(runnable().debuggeeArgs), DebugFormat); emit outputReceived(tr("Command line arguments: %1").arg(runnable().debuggeeArgs), DebugFormat);
#endif #endif
StandardRunnable debuggee;
debuggee.workingDirectory = workingDirectory();
debuggee.executable = runnable().debuggee;
debuggee.commandLineArguments = runnable().debuggeeArgs;
debuggee.environment = m_environment;
debuggee.runMode = m_localRunMode;
ValgrindRunner *run = runner(); ValgrindRunner *run = runner();
run->setWorkingDirectory(workingDirectory());
run->setValgrindExecutable(m_settings->valgrindExecutable()); run->setValgrindExecutable(m_settings->valgrindExecutable());
run->setValgrindArguments(genericToolArguments() + toolArguments()); run->setValgrindArguments(genericToolArguments() + toolArguments());
run->setDebuggeeExecutable(runnable().debuggee);
run->setDebuggeeArguments(runnable().debuggeeArgs);
run->setEnvironment(m_environment);
run->setConnectionParameters(connection().connParams); run->setConnectionParameters(connection().connParams);
run->setUseStartupProject(!m_isCustomStart); run->setUseStartupProject(!m_isCustomStart);
run->setLocalRunMode(m_localRunMode); run->setDebuggee(debuggee);
connect(run, &ValgrindRunner::processOutputReceived, connect(run, &ValgrindRunner::processOutputReceived,
this, &ValgrindRunControl::receiveProcessOutput); this, &ValgrindRunControl::receiveProcessOutput);

View File

@@ -40,8 +40,7 @@ namespace Valgrind {
ValgrindProcess::ValgrindProcess(bool isLocal, const QSsh::SshConnectionParameters &sshParams, ValgrindProcess::ValgrindProcess(bool isLocal, const QSsh::SshConnectionParameters &sshParams,
QSsh::SshConnection *connection, QObject *parent) QSsh::SshConnection *connection, QObject *parent)
: QObject(parent), : QObject(parent),
m_isLocal(isLocal), m_isLocal(isLocal)
m_localRunMode(ApplicationLauncher::Gui)
{ {
m_remote.m_params = sshParams; m_remote.m_params = sshParams;
m_remote.m_connection = connection; m_remote.m_connection = connection;
@@ -56,20 +55,9 @@ void ValgrindProcess::setProcessChannelMode(QProcess::ProcessChannelMode mode)
///TODO: remote support this by handling the mode internally ///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 QString ValgrindProcess::workingDirectory() const
{ {
if (isLocal()) return m_debuggee.workingDirectory;
return m_localProcess.workingDirectory();
else
return m_remote.m_workingDir;
} }
bool ValgrindProcess::isRunning() const bool ValgrindProcess::isRunning() const
@@ -85,33 +73,21 @@ void ValgrindProcess::setValgrindExecutable(const QString &valgrindExecutable)
m_valgrindExecutable = 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) void ValgrindProcess::setValgrindArguments(const QStringList &valgrindArguments)
{ {
m_valgrindArguments = 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() void ValgrindProcess::close()
{ {
if (isLocal()) { if (isLocal()) {
@@ -146,13 +122,10 @@ void ValgrindProcess::run()
connect(&m_localProcess, &ApplicationLauncher::appendMessage, connect(&m_localProcess, &ApplicationLauncher::appendMessage,
this, &ValgrindProcess::processOutput); this, &ValgrindProcess::processOutput);
m_localProcess.start(m_localRunMode, m_valgrindExecutable, m_localProcess.start(m_debuggee.runMode, m_valgrindExecutable,
argumentString(Utils::HostOsInfo::hostOs())); argumentString(Utils::HostOsInfo::hostOs()));
} else { } else {
m_remote.m_valgrindExe = m_valgrindExecutable;
m_remote.m_debuggee = m_debuggeeExecutable;
// connect to host and wait for connection // connect to host and wait for connection
if (!m_remote.m_connection) if (!m_remote.m_connection)
m_remote.m_connection = new QSsh::SshConnection(m_remote.m_params, this); m_remote.m_connection = new QSsh::SshConnection(m_remote.m_params, this);
@@ -231,10 +204,10 @@ void ValgrindProcess::connected()
// connected, run command // connected, run command
QString cmd; QString cmd;
if (!m_remote.m_workingDir.isEmpty()) if (!m_debuggee.workingDirectory.isEmpty())
cmd += QString::fromLatin1("cd '%1' && ").arg(m_remote.m_workingDir); 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()); m_remote.m_process = m_remote.m_connection->createRemoteProcess(cmd.toUtf8());
connect(m_remote.m_process.data(), &QSsh::SshRemoteProcess::readyReadStandardError, connect(m_remote.m_process.data(), &QSsh::SshRemoteProcess::readyReadStandardError,
@@ -272,7 +245,7 @@ void ValgrindProcess::remoteProcessStarted()
// hence we need to do something more complex... // hence we need to do something more complex...
// plain path to exe, m_valgrindExe contains e.g. env vars etc. pp. // 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..." // sleep required since otherwise we might only match "bash -c..."
// and not the actual valgrind run // and not the actual valgrind run
const QString cmd = QString::fromLatin1("sleep 1; ps ax" // list all processes with aliased name 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 " | tail -n 1" // limit to single process
// we pick the last one, first would be "bash -c ..." // we pick the last one, first would be "bash -c ..."
" | awk '{print $1;}'" // get pid " | 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()); m_remote.m_findPID = m_remote.m_connection->createRemoteProcess(cmd.toUtf8());
connect(m_remote.m_findPID.data(), &QSsh::SshRemoteProcess::readyReadStandardError, connect(m_remote.m_findPID.data(), &QSsh::SshRemoteProcess::readyReadStandardError,
@@ -308,15 +281,12 @@ void ValgrindProcess::findPIDOutputReceived()
QString ValgrindProcess::argumentString(Utils::OsType osType) const QString ValgrindProcess::argumentString(Utils::OsType osType) const
{ {
QString arguments = Utils::QtcProcess::joinArgs(m_valgrindArguments, osType); QString arguments = Utils::QtcProcess::joinArgs(m_valgrindArguments, osType);
if (!m_debuggeeExecutable.isEmpty()) if (!m_debuggee.executable.isEmpty())
Utils::QtcProcess::addArg(&arguments, m_debuggeeExecutable, osType); Utils::QtcProcess::addArg(&arguments, m_debuggee.executable, osType);
Utils::QtcProcess::addArgs(&arguments, m_debuggeeArguments); Utils::QtcProcess::addArgs(&arguments, m_debuggee.commandLineArguments);
return arguments; return arguments;
} }
///////////
void ValgrindProcess::closed(int status) void ValgrindProcess::closed(int status)
{ {
QTC_ASSERT(m_remote.m_process, return); QTC_ASSERT(m_remote.m_process, return);

View File

@@ -28,6 +28,7 @@
#define VALGRINDPROCESS_H #define VALGRINDPROCESS_H
#include <projectexplorer/applicationlauncher.h> #include <projectexplorer/applicationlauncher.h>
#include <projectexplorer/runnables.h>
#include <ssh/sshremoteprocess.h> #include <ssh/sshremoteprocess.h>
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
@@ -36,18 +37,6 @@
namespace Valgrind { namespace Valgrind {
struct Remote {
QSsh::SshConnectionParameters m_params;
QSsh::SshConnection *m_connection;
QSsh::SshRemoteProcess::Ptr m_process;
QString m_workingDir;
QString m_valgrindExe;
QString m_debuggee;
QString m_errorString;
QProcess::ProcessError m_error;
QSsh::SshRemoteProcess::Ptr m_findPID;
};
/** /**
* Process for supplying local and remote valgrind runs * Process for supplying local and remote valgrind runs
*/ */
@@ -63,8 +52,7 @@ public:
void setValgrindExecutable(const QString &valgrindExecutable); void setValgrindExecutable(const QString &valgrindExecutable);
void setValgrindArguments(const QStringList &valgrindArguments); void setValgrindArguments(const QStringList &valgrindArguments);
void setDebuggeeExecutable(const QString &debuggeeExecutable); void setDebuggee(const ProjectExplorer::StandardRunnable &debuggee);
void setDebugeeArguments(const QString &debuggeeArguments);
void run(); void run();
void close(); void close();
@@ -73,10 +61,7 @@ public:
QProcess::ProcessError processError() const; QProcess::ProcessError processError() const;
void setProcessChannelMode(QProcess::ProcessChannelMode mode); void setProcessChannelMode(QProcess::ProcessChannelMode mode);
void setWorkingDirectory(const QString &path);
QString workingDirectory() const; QString workingDirectory() const;
void setEnvironment(const Utils::Environment &environment);
void setLocalRunMode(ProjectExplorer::ApplicationLauncher::Mode localRunMode);
qint64 pid() const; qint64 pid() const;
QSsh::SshConnection *connection() const; QSsh::SshConnection *connection() const;
@@ -89,7 +74,7 @@ signals:
void processOutput(const QString &, Utils::OutputFormat format); void processOutput(const QString &, Utils::OutputFormat format);
void localHostAddressRetrieved(const QHostAddress &localHostAddress); void localHostAddressRetrieved(const QHostAddress &localHostAddress);
private slots: private:
void handleRemoteStderr(); void handleRemoteStderr();
void handleRemoteStdout(); void handleRemoteStdout();
void handleError(QSsh::SshError); void handleError(QSsh::SshError);
@@ -100,24 +85,26 @@ private slots:
void remoteProcessStarted(); void remoteProcessStarted();
void findPIDOutputReceived(); void findPIDOutputReceived();
private:
QString argumentString(Utils::OsType osType) const; QString argumentString(Utils::OsType osType) const;
ProjectExplorer::StandardRunnable m_debuggee;
ProjectExplorer::ApplicationLauncher m_localProcess; ProjectExplorer::ApplicationLauncher m_localProcess;
qint64 m_pid; qint64 m_pid;
Remote m_remote; struct Remote {
QSsh::SshConnectionParameters m_params;
QSsh::SshConnection *m_connection;
QSsh::SshRemoteProcess::Ptr m_process;
QString m_errorString;
QProcess::ProcessError m_error;
QSsh::SshRemoteProcess::Ptr m_findPID;
} m_remote;
QString m_valgrindExecutable; QString m_valgrindExecutable;
QStringList m_valgrindArguments; QStringList m_valgrindArguments;
QString m_debuggeeExecutable;
QString m_debuggeeArguments;
bool m_isLocal; bool m_isLocal;
ProjectExplorer::ApplicationLauncher::Mode m_localRunMode;
}; };
} // namespace Valgrind } // namespace Valgrind
#endif // VALGRINDPROCESS_H #endif // VALGRINDPROCESS_H

View File

@@ -27,6 +27,8 @@
#include "valgrindrunner.h" #include "valgrindrunner.h"
#include "valgrindprocess.h" #include "valgrindprocess.h"
#include <projectexplorer/runnables.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -36,35 +38,26 @@
#include <QEventLoop> #include <QEventLoop>
using namespace ProjectExplorer;
namespace Valgrind { namespace Valgrind {
class ValgrindRunner::Private class ValgrindRunner::Private
{ {
public: public:
explicit Private(ValgrindRunner *qq) Private(ValgrindRunner *runner) : q(runner) {}
: q(qq),
process(0),
channelMode(QProcess::SeparateChannels),
finished(false),
useStartupProject(true),
localRunMode(ProjectExplorer::ApplicationLauncher::Gui)
{
}
void run(ValgrindProcess *process); void run(ValgrindProcess *process);
ValgrindRunner *q; ValgrindRunner *q;
ValgrindProcess *process; ValgrindProcess *process = 0;
Utils::Environment environment; QProcess::ProcessChannelMode channelMode = QProcess::SeparateChannels;
QProcess::ProcessChannelMode channelMode; bool finished = false;
bool finished;
QString valgrindExecutable; QString valgrindExecutable;
QStringList valgrindArguments; QStringList valgrindArguments;
QString debuggeeExecutable; StandardRunnable debuggee;
QString debuggeeArguments;
QString workingdir; QString workingdir;
bool useStartupProject; bool useStartupProject = true;
ProjectExplorer::ApplicationLauncher::Mode localRunMode;
QSsh::SshConnectionParameters connParams; QSsh::SshConnectionParameters connParams;
}; };
@@ -80,14 +73,12 @@ void ValgrindRunner::Private::run(ValgrindProcess *_process)
process = _process; process = _process;
if (environment.size() > 0)
process->setEnvironment(environment);
process->setWorkingDirectory(workingdir);
process->setProcessChannelMode(channelMode); process->setProcessChannelMode(channelMode);
process->setLocalRunMode(localRunMode);
// consider appending our options last so they override any interfering user-supplied options // consider appending our options last so they override any interfering user-supplied options
// -q as suggested by valgrind manual // -q as suggested by valgrind manual
process->setValgrindExecutable(valgrindExecutable);
process->setValgrindArguments(q->fullValgrindArguments());
process->setDebuggee(debuggee);
QObject::connect(process, &ValgrindProcess::processOutput, QObject::connect(process, &ValgrindProcess::processOutput,
q, &ValgrindRunner::processOutputReceived); q, &ValgrindRunner::processOutputReceived);
@@ -100,10 +91,6 @@ void ValgrindRunner::Private::run(ValgrindProcess *_process)
QObject::connect(process, &ValgrindProcess::localHostAddressRetrieved, q, QObject::connect(process, &ValgrindProcess::localHostAddressRetrieved, q,
&ValgrindRunner::localHostAddressRetrieved); &ValgrindRunner::localHostAddressRetrieved);
process->setValgrindExecutable(valgrindExecutable);
process->setValgrindArguments(q->fullValgrindArguments());
process->setDebuggeeExecutable(debuggeeExecutable);
process->setDebugeeArguments(debuggeeArguments);
process->run(); process->run();
} }
@@ -153,29 +140,9 @@ QStringList ValgrindRunner::fullValgrindArguments() const
return fullArgs; return fullArgs;
} }
QString ValgrindRunner::debuggeeExecutable() const void ValgrindRunner::setDebuggee(const StandardRunnable &debuggee)
{ {
return d->debuggeeExecutable; d->debuggee = debuggee;
}
void ValgrindRunner::setDebuggeeExecutable(const QString &executable)
{
d->debuggeeExecutable = executable;
}
QString ValgrindRunner::debuggeeArguments() const
{
return d->debuggeeArguments;
}
void ValgrindRunner::setDebuggeeArguments(const QString &arguments)
{
d->debuggeeArguments = arguments;
}
void ValgrindRunner::setLocalRunMode(ProjectExplorer::ApplicationLauncher::Mode localRunMode)
{
d->localRunMode = localRunMode;
} }
const QSsh::SshConnectionParameters &ValgrindRunner::connectionParameters() const const QSsh::SshConnectionParameters &ValgrindRunner::connectionParameters() const
@@ -188,21 +155,6 @@ void ValgrindRunner::setConnectionParameters(const QSsh::SshConnectionParameters
d->connParams = connParams; d->connParams = connParams;
} }
void ValgrindRunner::setWorkingDirectory(const QString &path)
{
d->workingdir = path;
}
QString ValgrindRunner::workingDirectory() const
{
return d->workingdir;
}
void ValgrindRunner::setEnvironment(const Utils::Environment &environment)
{
d->environment = environment;
}
void ValgrindRunner::setProcessChannelMode(QProcess::ProcessChannelMode mode) void ValgrindRunner::setProcessChannelMode(QProcess::ProcessChannelMode mode)
{ {
d->channelMode = mode; d->channelMode = mode;

View File

@@ -28,17 +28,15 @@
#define VALGRIND_RUNNER_H #define VALGRIND_RUNNER_H
#include <analyzerbase/analyzerconstants.h> #include <analyzerbase/analyzerconstants.h>
#include <projectexplorer/applicationlauncher.h>
#include <projectexplorer/runnables.h>
#include <utils/outputformat.h> #include <utils/outputformat.h>
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
#include <QProcess> #include <QProcess>
namespace Utils { namespace Utils { class SshConnectionParameters; }
class Environment;
class SshConnectionParameters;
}
namespace Valgrind { namespace Valgrind {
@@ -57,21 +55,12 @@ public:
QStringList valgrindArguments() const; QStringList valgrindArguments() const;
QStringList fullValgrindArguments() const; QStringList fullValgrindArguments() const;
void setValgrindArguments(const QStringList &toolArguments); void setValgrindArguments(const QStringList &toolArguments);
QString debuggeeExecutable() const; void setDebuggee(const ProjectExplorer::StandardRunnable &debuggee) ;
void setDebuggeeExecutable(const QString &executable);
QString debuggeeArguments() const;
void setDebuggeeArguments(const QString &arguments);
void setWorkingDirectory(const QString &path);
QString workingDirectory() const;
void setEnvironment(const Utils::Environment &environment);
void setProcessChannelMode(QProcess::ProcessChannelMode mode); void setProcessChannelMode(QProcess::ProcessChannelMode mode);
void setUseStartupProject(bool useStartupProject); void setUseStartupProject(bool useStartupProject);
bool useStartupProject() const; bool useStartupProject() const;
void setLocalRunMode(ProjectExplorer::ApplicationLauncher::Mode localRunMode);
void setConnectionParameters(const QSsh::SshConnectionParameters &connParams); void setConnectionParameters(const QSsh::SshConnectionParameters &connParams);
const QSsh::SshConnectionParameters &connectionParameters() const; const QSsh::SshConnectionParameters &connectionParameters() const;