2011-03-04 12:15:18 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
|
|
|
|
** Author: Milian Wolff, KDAB (milian.wolff@kdab.com)
|
|
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-03-04 12:15:18 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2011-03-04 12:15:18 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "valgrindrunner.h"
|
|
|
|
|
#include "valgrindprocess.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/environment.h>
|
2011-04-04 14:39:27 +02:00
|
|
|
#include <utils/ssh/sshconnection.h>
|
|
|
|
|
#include <utils/ssh/sshremoteprocess.h>
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QEventLoop>
|
2011-03-04 12:15:18 +01:00
|
|
|
|
2011-05-18 17:05:49 +02:00
|
|
|
namespace Valgrind {
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
class ValgrindRunner::Private
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit Private(ValgrindRunner *qq)
|
|
|
|
|
: q(qq),
|
|
|
|
|
process(0),
|
|
|
|
|
channelMode(QProcess::SeparateChannels),
|
2011-10-20 16:07:50 +02:00
|
|
|
finished(false),
|
2012-03-05 12:37:32 +01:00
|
|
|
startMode(Analyzer::StartLocal)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-04 14:39:27 +02:00
|
|
|
void run(ValgrindProcess *process);
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
ValgrindRunner *q;
|
2011-04-04 14:39:27 +02:00
|
|
|
ValgrindProcess *process;
|
2011-03-04 12:15:18 +01:00
|
|
|
Utils::Environment environment;
|
|
|
|
|
QProcess::ProcessChannelMode channelMode;
|
|
|
|
|
bool finished;
|
|
|
|
|
QString valgrindExecutable;
|
|
|
|
|
QStringList valgrindArguments;
|
|
|
|
|
QString debuggeeExecutable;
|
|
|
|
|
QString debuggeeArguments;
|
|
|
|
|
QString workingdir;
|
2011-10-20 16:07:50 +02:00
|
|
|
Analyzer::StartMode startMode;
|
|
|
|
|
Utils::SshConnectionParameters connParams;
|
2011-03-04 12:15:18 +01:00
|
|
|
};
|
|
|
|
|
|
2011-04-04 14:39:27 +02:00
|
|
|
void ValgrindRunner::Private::run(ValgrindProcess *_process)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
if (process && process->isRunning()) {
|
|
|
|
|
process->close();
|
|
|
|
|
process->disconnect(q);
|
|
|
|
|
process->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(_process, return);
|
|
|
|
|
|
|
|
|
|
process = _process;
|
|
|
|
|
|
|
|
|
|
if (environment.size() > 0)
|
|
|
|
|
process->setEnvironment(environment);
|
|
|
|
|
|
|
|
|
|
process->setWorkingDirectory(workingdir);
|
|
|
|
|
process->setProcessChannelMode(channelMode);
|
|
|
|
|
// consider appending our options last so they override any interfering user-supplied options
|
|
|
|
|
// -q as suggested by valgrind manual
|
|
|
|
|
QStringList valgrindArgs = valgrindArguments;
|
|
|
|
|
valgrindArgs << QString("--tool=%1").arg(q->tool());
|
|
|
|
|
|
2011-04-04 14:39:27 +02:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
// May be slower to start but without it we get no filenames for symbols.
|
|
|
|
|
valgrindArgs << QLatin1String("--dsymutil=yes");
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-06-10 16:34:06 +02:00
|
|
|
QObject::connect(process, SIGNAL(processOutput(QByteArray,Utils::OutputFormat)),
|
|
|
|
|
q, SIGNAL(processOutputReceived(QByteArray,Utils::OutputFormat)));
|
2011-03-04 12:15:18 +01:00
|
|
|
QObject::connect(process, SIGNAL(started()),
|
|
|
|
|
q, SLOT(processStarted()));
|
2012-03-05 22:30:59 +01:00
|
|
|
QObject::connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),
|
|
|
|
|
q, SLOT(processFinished(int,QProcess::ExitStatus)));
|
2011-03-04 12:15:18 +01:00
|
|
|
QObject::connect(process, SIGNAL(error(QProcess::ProcessError)),
|
|
|
|
|
q, SLOT(processError(QProcess::ProcessError)));
|
|
|
|
|
|
|
|
|
|
process->run(valgrindExecutable, valgrindArgs, debuggeeExecutable, debuggeeArguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ValgrindRunner::ValgrindRunner(QObject *parent)
|
|
|
|
|
: QObject(parent),
|
|
|
|
|
d(new Private(this))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ValgrindRunner::~ValgrindRunner()
|
|
|
|
|
{
|
|
|
|
|
if (d->process && d->process->isRunning()) {
|
|
|
|
|
// make sure we don't delete the thread while it's still running
|
|
|
|
|
waitForFinished();
|
|
|
|
|
}
|
|
|
|
|
delete d;
|
|
|
|
|
d = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::setValgrindExecutable(const QString &executable)
|
|
|
|
|
{
|
|
|
|
|
d->valgrindExecutable = executable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ValgrindRunner::valgrindExecutable() const
|
|
|
|
|
{
|
|
|
|
|
return d->valgrindExecutable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::setValgrindArguments(const QStringList &toolArguments)
|
|
|
|
|
{
|
|
|
|
|
d->valgrindArguments = toolArguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList ValgrindRunner::valgrindArguments() const
|
|
|
|
|
{
|
|
|
|
|
return d->valgrindArguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ValgrindRunner::debuggeeExecutable() const
|
|
|
|
|
{
|
|
|
|
|
return d->debuggeeExecutable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::setDebuggeeExecutable(const QString &executable)
|
|
|
|
|
{
|
|
|
|
|
d->debuggeeExecutable = executable;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-04 16:00:02 +01:00
|
|
|
QString ValgrindRunner::debuggeeArguments() const
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
return d->debuggeeArguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::setDebuggeeArguments(const QString &arguments)
|
|
|
|
|
{
|
|
|
|
|
d->debuggeeArguments = arguments;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-20 16:07:50 +02:00
|
|
|
Analyzer::StartMode ValgrindRunner::startMode() const
|
|
|
|
|
{
|
|
|
|
|
return d->startMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::setStartMode(Analyzer::StartMode startMode)
|
|
|
|
|
{
|
|
|
|
|
d->startMode = startMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Utils::SshConnectionParameters &ValgrindRunner::connectionParameters() const
|
|
|
|
|
{
|
|
|
|
|
return d->connParams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::setConnectionParameters(const Utils::SshConnectionParameters &connParams)
|
|
|
|
|
{
|
|
|
|
|
d->connParams = connParams;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-04 12:15:18 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::waitForFinished() const
|
|
|
|
|
{
|
|
|
|
|
if (d->finished || !d->process)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QEventLoop loop;
|
|
|
|
|
connect(this, SIGNAL(finished()), &loop, SLOT(quit()));
|
|
|
|
|
loop.exec();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-20 14:19:44 +01:00
|
|
|
bool ValgrindRunner::start()
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2011-10-20 16:07:50 +02:00
|
|
|
if (d->startMode == Analyzer::StartLocal)
|
|
|
|
|
d->run(new LocalValgrindProcess(this));
|
|
|
|
|
else if (d->startMode == Analyzer::StartRemote)
|
|
|
|
|
d->run(new RemoteValgrindProcess(d->connParams, this));
|
2012-01-20 14:19:44 +01:00
|
|
|
return true;
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::processError(QProcess::ProcessError e)
|
|
|
|
|
{
|
|
|
|
|
if (d->finished)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
d->finished = true;
|
|
|
|
|
|
|
|
|
|
// make sure we don't wait for the connection anymore
|
|
|
|
|
emit processErrorReceived(errorString(), e);
|
|
|
|
|
emit finished();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::processFinished(int ret, QProcess::ExitStatus status)
|
|
|
|
|
{
|
|
|
|
|
if (d->finished)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
d->finished = true;
|
|
|
|
|
|
|
|
|
|
// make sure we don't wait for the connection anymore
|
|
|
|
|
emit finished();
|
|
|
|
|
|
|
|
|
|
if (ret != 0 || status == QProcess::CrashExit)
|
|
|
|
|
emit processErrorReceived(errorString(), d->process->error());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::processStarted()
|
|
|
|
|
{
|
|
|
|
|
emit started();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ValgrindRunner::errorString() const
|
|
|
|
|
{
|
|
|
|
|
if (d->process)
|
|
|
|
|
return d->process->errorString();
|
|
|
|
|
else
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValgrindRunner::stop()
|
|
|
|
|
{
|
|
|
|
|
if (d->process)
|
|
|
|
|
d->process->close();
|
2011-03-08 13:56:52 +01:00
|
|
|
}
|
2011-04-04 14:39:27 +02:00
|
|
|
|
|
|
|
|
ValgrindProcess *ValgrindRunner::valgrindProcess() const
|
|
|
|
|
{
|
|
|
|
|
return d->process;
|
|
|
|
|
}
|
2011-05-18 17:05:49 +02:00
|
|
|
|
|
|
|
|
} // namespace Valgrind
|