2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
2011-03-04 12:15:18 +01:00
|
|
|
** Author: Milian Wolff, KDAB (milian.wolff@kdab.com)
|
2016-01-15 14:57:40 +01:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-03-04 12:15:18 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
#include "valgrindrunner.h"
|
|
|
|
|
#include "valgrindprocess.h"
|
|
|
|
|
|
2016-01-25 17:15:54 +01:00
|
|
|
#include <projectexplorer/runnables.h>
|
|
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/environment.h>
|
|
|
|
|
#include <utils/hostosinfo.h>
|
2011-03-04 12:15:18 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-05-18 10:49:35 +02:00
|
|
|
#include <ssh/sshconnection.h>
|
|
|
|
|
#include <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
|
|
|
|
2016-01-25 17:15:54 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2011-05-18 17:05:49 +02:00
|
|
|
namespace Valgrind {
|
2011-03-04 12:15:18 +01:00
|
|
|
|
|
|
|
|
class ValgrindRunner::Private
|
|
|
|
|
{
|
|
|
|
|
public:
|
2016-01-25 17:15:54 +01:00
|
|
|
ValgrindProcess *process = 0;
|
|
|
|
|
QProcess::ProcessChannelMode channelMode = QProcess::SeparateChannels;
|
|
|
|
|
bool finished = false;
|
2011-03-04 12:15:18 +01:00
|
|
|
QString valgrindExecutable;
|
|
|
|
|
QStringList valgrindArguments;
|
2016-01-25 17:15:54 +01:00
|
|
|
StandardRunnable debuggee;
|
2016-01-30 01:38:58 +01:00
|
|
|
IDevice::ConstPtr device;
|
2011-03-04 12:15:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ValgrindRunner::ValgrindRunner(QObject *parent)
|
2016-02-02 16:09:40 +01:00
|
|
|
: QObject(parent), d(new Private)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 12:19:48 +02:00
|
|
|
QStringList ValgrindRunner::fullValgrindArguments() const
|
|
|
|
|
{
|
|
|
|
|
QStringList fullArgs = valgrindArguments();
|
|
|
|
|
fullArgs << QString::fromLatin1("--tool=%1").arg(tool());
|
|
|
|
|
if (Utils::HostOsInfo::isMacHost())
|
|
|
|
|
// May be slower to start but without it we get no filenames for symbols.
|
|
|
|
|
fullArgs << QLatin1String("--dsymutil=yes");
|
|
|
|
|
return fullArgs;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 17:15:54 +01:00
|
|
|
void ValgrindRunner::setDebuggee(const StandardRunnable &debuggee)
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2016-01-25 17:15:54 +01:00
|
|
|
d->debuggee = debuggee;
|
2014-05-06 00:08:12 +03:00
|
|
|
}
|
|
|
|
|
|
2011-03-04 12:15:18 +01:00
|
|
|
void ValgrindRunner::setProcessChannelMode(QProcess::ProcessChannelMode mode)
|
|
|
|
|
{
|
|
|
|
|
d->channelMode = mode;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-30 01:38:58 +01:00
|
|
|
void ValgrindRunner::setDevice(const IDevice::ConstPtr &device)
|
2015-06-16 11:48:45 +02:00
|
|
|
{
|
2016-01-30 01:38:58 +01:00
|
|
|
d->device = device;
|
2015-06-16 11:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-30 01:38:58 +01:00
|
|
|
IDevice::ConstPtr ValgrindRunner::device() const
|
2015-06-16 11:48:45 +02:00
|
|
|
{
|
2016-01-30 01:38:58 +01:00
|
|
|
return d->device;
|
2015-06-16 11:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-04 12:15:18 +01:00
|
|
|
void ValgrindRunner::waitForFinished() const
|
|
|
|
|
{
|
|
|
|
|
if (d->finished || !d->process)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QEventLoop loop;
|
2015-02-06 12:39:07 +02:00
|
|
|
connect(this, &ValgrindRunner::finished, &loop, &QEventLoop::quit);
|
2011-03-04 12:15:18 +01:00
|
|
|
loop.exec();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-20 14:19:44 +01:00
|
|
|
bool ValgrindRunner::start()
|
2011-03-04 12:15:18 +01:00
|
|
|
{
|
2016-02-02 16:09:40 +01:00
|
|
|
d->process = new ValgrindProcess(d->device, this);
|
|
|
|
|
d->process->setProcessChannelMode(d->channelMode);
|
|
|
|
|
// consider appending our options last so they override any interfering user-supplied options
|
|
|
|
|
// -q as suggested by valgrind manual
|
|
|
|
|
d->process->setValgrindExecutable(d->valgrindExecutable);
|
|
|
|
|
d->process->setValgrindArguments(fullValgrindArguments());
|
|
|
|
|
d->process->setDebuggee(d->debuggee);
|
|
|
|
|
|
|
|
|
|
QObject::connect(d->process, &ValgrindProcess::processOutput,
|
|
|
|
|
this, &ValgrindRunner::processOutputReceived);
|
|
|
|
|
QObject::connect(d->process, &ValgrindProcess::started,
|
|
|
|
|
this, &ValgrindRunner::started);
|
|
|
|
|
QObject::connect(d->process, &ValgrindProcess::finished,
|
|
|
|
|
this, &ValgrindRunner::processFinished);
|
|
|
|
|
QObject::connect(d->process, &ValgrindProcess::error,
|
|
|
|
|
this, &ValgrindRunner::processError);
|
|
|
|
|
|
|
|
|
|
d->process->run();
|
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)
|
2015-02-06 11:41:57 +02:00
|
|
|
emit processErrorReceived(errorString(), d->process->processError());
|
2011-03-04 12:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|