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:
@@ -131,8 +131,6 @@ void CallgrindController::run(Option option)
|
||||
const int pid = Utils::HostOsInfo::isWindowsHost() ? 0 : m_valgrindProc->pid();
|
||||
m_process->setValgrindExecutable(CALLGRIND_CONTROL_BINARY);
|
||||
m_process->setValgrindArguments(QStringList() << optionString << QString::number(pid));
|
||||
m_process->setDebuggeeExecutable(QString());
|
||||
m_process->setDebugeeArguments(QString());
|
||||
m_process->run();
|
||||
}
|
||||
|
||||
|
@@ -83,16 +83,19 @@ bool ValgrindRunControl::startEngine()
|
||||
emit outputReceived(tr("Command line arguments: %1").arg(runnable().debuggeeArgs), DebugFormat);
|
||||
#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();
|
||||
run->setWorkingDirectory(workingDirectory());
|
||||
run->setValgrindExecutable(m_settings->valgrindExecutable());
|
||||
run->setValgrindArguments(genericToolArguments() + toolArguments());
|
||||
run->setDebuggeeExecutable(runnable().debuggee);
|
||||
run->setDebuggeeArguments(runnable().debuggeeArgs);
|
||||
run->setEnvironment(m_environment);
|
||||
run->setConnectionParameters(connection().connParams);
|
||||
run->setUseStartupProject(!m_isCustomStart);
|
||||
run->setLocalRunMode(m_localRunMode);
|
||||
run->setDebuggee(debuggee);
|
||||
|
||||
connect(run, &ValgrindRunner::processOutputReceived,
|
||||
this, &ValgrindRunControl::receiveProcessOutput);
|
||||
|
@@ -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);
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#define VALGRINDPROCESS_H
|
||||
|
||||
#include <projectexplorer/applicationlauncher.h>
|
||||
#include <projectexplorer/runnables.h>
|
||||
|
||||
#include <ssh/sshremoteprocess.h>
|
||||
#include <ssh/sshconnection.h>
|
||||
@@ -36,18 +37,6 @@
|
||||
|
||||
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
|
||||
*/
|
||||
@@ -63,8 +52,7 @@ public:
|
||||
|
||||
void setValgrindExecutable(const QString &valgrindExecutable);
|
||||
void setValgrindArguments(const QStringList &valgrindArguments);
|
||||
void setDebuggeeExecutable(const QString &debuggeeExecutable);
|
||||
void setDebugeeArguments(const QString &debuggeeArguments);
|
||||
void setDebuggee(const ProjectExplorer::StandardRunnable &debuggee);
|
||||
|
||||
void run();
|
||||
void close();
|
||||
@@ -73,10 +61,7 @@ public:
|
||||
QProcess::ProcessError processError() const;
|
||||
|
||||
void setProcessChannelMode(QProcess::ProcessChannelMode mode);
|
||||
void setWorkingDirectory(const QString &path);
|
||||
QString workingDirectory() const;
|
||||
void setEnvironment(const Utils::Environment &environment);
|
||||
void setLocalRunMode(ProjectExplorer::ApplicationLauncher::Mode localRunMode);
|
||||
|
||||
qint64 pid() const;
|
||||
QSsh::SshConnection *connection() const;
|
||||
@@ -89,7 +74,7 @@ signals:
|
||||
void processOutput(const QString &, Utils::OutputFormat format);
|
||||
void localHostAddressRetrieved(const QHostAddress &localHostAddress);
|
||||
|
||||
private slots:
|
||||
private:
|
||||
void handleRemoteStderr();
|
||||
void handleRemoteStdout();
|
||||
void handleError(QSsh::SshError);
|
||||
@@ -100,24 +85,26 @@ private slots:
|
||||
void remoteProcessStarted();
|
||||
void findPIDOutputReceived();
|
||||
|
||||
private:
|
||||
QString argumentString(Utils::OsType osType) const;
|
||||
|
||||
ProjectExplorer::StandardRunnable m_debuggee;
|
||||
ProjectExplorer::ApplicationLauncher m_localProcess;
|
||||
|
||||
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;
|
||||
QStringList m_valgrindArguments;
|
||||
QString m_debuggeeExecutable;
|
||||
QString m_debuggeeArguments;
|
||||
bool m_isLocal;
|
||||
ProjectExplorer::ApplicationLauncher::Mode m_localRunMode;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Valgrind
|
||||
|
||||
#endif // VALGRINDPROCESS_H
|
||||
|
@@ -27,6 +27,8 @@
|
||||
#include "valgrindrunner.h"
|
||||
#include "valgrindprocess.h"
|
||||
|
||||
#include <projectexplorer/runnables.h>
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -36,35 +38,26 @@
|
||||
|
||||
#include <QEventLoop>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace Valgrind {
|
||||
|
||||
class ValgrindRunner::Private
|
||||
{
|
||||
public:
|
||||
explicit Private(ValgrindRunner *qq)
|
||||
: q(qq),
|
||||
process(0),
|
||||
channelMode(QProcess::SeparateChannels),
|
||||
finished(false),
|
||||
useStartupProject(true),
|
||||
localRunMode(ProjectExplorer::ApplicationLauncher::Gui)
|
||||
{
|
||||
}
|
||||
Private(ValgrindRunner *runner) : q(runner) {}
|
||||
|
||||
void run(ValgrindProcess *process);
|
||||
|
||||
ValgrindRunner *q;
|
||||
ValgrindProcess *process;
|
||||
Utils::Environment environment;
|
||||
QProcess::ProcessChannelMode channelMode;
|
||||
bool finished;
|
||||
ValgrindProcess *process = 0;
|
||||
QProcess::ProcessChannelMode channelMode = QProcess::SeparateChannels;
|
||||
bool finished = false;
|
||||
QString valgrindExecutable;
|
||||
QStringList valgrindArguments;
|
||||
QString debuggeeExecutable;
|
||||
QString debuggeeArguments;
|
||||
StandardRunnable debuggee;
|
||||
QString workingdir;
|
||||
bool useStartupProject;
|
||||
ProjectExplorer::ApplicationLauncher::Mode localRunMode;
|
||||
bool useStartupProject = true;
|
||||
QSsh::SshConnectionParameters connParams;
|
||||
};
|
||||
|
||||
@@ -80,14 +73,12 @@ void ValgrindRunner::Private::run(ValgrindProcess *_process)
|
||||
|
||||
process = _process;
|
||||
|
||||
if (environment.size() > 0)
|
||||
process->setEnvironment(environment);
|
||||
|
||||
process->setWorkingDirectory(workingdir);
|
||||
process->setProcessChannelMode(channelMode);
|
||||
process->setLocalRunMode(localRunMode);
|
||||
// consider appending our options last so they override any interfering user-supplied options
|
||||
// -q as suggested by valgrind manual
|
||||
process->setValgrindExecutable(valgrindExecutable);
|
||||
process->setValgrindArguments(q->fullValgrindArguments());
|
||||
process->setDebuggee(debuggee);
|
||||
|
||||
QObject::connect(process, &ValgrindProcess::processOutput,
|
||||
q, &ValgrindRunner::processOutputReceived);
|
||||
@@ -100,10 +91,6 @@ void ValgrindRunner::Private::run(ValgrindProcess *_process)
|
||||
QObject::connect(process, &ValgrindProcess::localHostAddressRetrieved, q,
|
||||
&ValgrindRunner::localHostAddressRetrieved);
|
||||
|
||||
process->setValgrindExecutable(valgrindExecutable);
|
||||
process->setValgrindArguments(q->fullValgrindArguments());
|
||||
process->setDebuggeeExecutable(debuggeeExecutable);
|
||||
process->setDebugeeArguments(debuggeeArguments);
|
||||
process->run();
|
||||
}
|
||||
|
||||
@@ -153,29 +140,9 @@ QStringList ValgrindRunner::fullValgrindArguments() const
|
||||
return fullArgs;
|
||||
}
|
||||
|
||||
QString ValgrindRunner::debuggeeExecutable() const
|
||||
void ValgrindRunner::setDebuggee(const StandardRunnable &debuggee)
|
||||
{
|
||||
return d->debuggeeExecutable;
|
||||
}
|
||||
|
||||
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;
|
||||
d->debuggee = debuggee;
|
||||
}
|
||||
|
||||
const QSsh::SshConnectionParameters &ValgrindRunner::connectionParameters() const
|
||||
@@ -188,21 +155,6 @@ void ValgrindRunner::setConnectionParameters(const QSsh::SshConnectionParameters
|
||||
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)
|
||||
{
|
||||
d->channelMode = mode;
|
||||
|
@@ -28,17 +28,15 @@
|
||||
#define VALGRIND_RUNNER_H
|
||||
|
||||
#include <analyzerbase/analyzerconstants.h>
|
||||
#include <projectexplorer/applicationlauncher.h>
|
||||
|
||||
#include <projectexplorer/runnables.h>
|
||||
|
||||
#include <utils/outputformat.h>
|
||||
#include <ssh/sshconnection.h>
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
namespace Utils {
|
||||
class Environment;
|
||||
class SshConnectionParameters;
|
||||
}
|
||||
namespace Utils { class SshConnectionParameters; }
|
||||
|
||||
namespace Valgrind {
|
||||
|
||||
@@ -57,21 +55,12 @@ public:
|
||||
QStringList valgrindArguments() const;
|
||||
QStringList fullValgrindArguments() const;
|
||||
void setValgrindArguments(const QStringList &toolArguments);
|
||||
QString debuggeeExecutable() const;
|
||||
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 setDebuggee(const ProjectExplorer::StandardRunnable &debuggee) ;
|
||||
void setProcessChannelMode(QProcess::ProcessChannelMode mode);
|
||||
|
||||
void setUseStartupProject(bool useStartupProject);
|
||||
bool useStartupProject() const;
|
||||
|
||||
void setLocalRunMode(ProjectExplorer::ApplicationLauncher::Mode localRunMode);
|
||||
|
||||
void setConnectionParameters(const QSsh::SshConnectionParameters &connParams);
|
||||
const QSsh::SshConnectionParameters &connectionParameters() const;
|
||||
|
||||
|
Reference in New Issue
Block a user