2011-03-04 12:15:19 +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:19 +01:00
|
|
|
**
|
|
|
|
** Author: Nicolas Arnaud-Cormos, KDAB (nicolas.arnaud-cormos@kdab.com)
|
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-03-04 12:15:19 +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:19 +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:19 +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:19 +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:19 +01:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include "memcheckengine.h"
|
|
|
|
|
2011-07-12 16:47:32 +02:00
|
|
|
#include "valgrindsettings.h"
|
2011-03-04 12:15:19 +01:00
|
|
|
|
|
|
|
#include <analyzerbase/analyzersettings.h>
|
|
|
|
|
|
|
|
#include <valgrind/xmlprotocol/error.h>
|
|
|
|
#include <valgrind/xmlprotocol/status.h>
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
2011-04-04 14:39:29 +02:00
|
|
|
using namespace Analyzer;
|
2011-03-04 12:15:19 +01:00
|
|
|
using namespace Valgrind::XmlProtocol;
|
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
namespace Valgrind {
|
2011-05-18 17:05:49 +02:00
|
|
|
namespace Internal {
|
2011-04-04 14:39:29 +02:00
|
|
|
|
2011-06-30 13:44:22 +02:00
|
|
|
MemcheckEngine::MemcheckEngine(IAnalyzerTool *tool, const AnalyzerStartParameters &sp,
|
|
|
|
ProjectExplorer::RunConfiguration *runConfiguration)
|
|
|
|
: ValgrindEngine(tool, sp, runConfiguration)
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
2011-05-18 17:05:49 +02:00
|
|
|
connect(&m_parser, SIGNAL(error(Valgrind::XmlProtocol::Error)),
|
|
|
|
SIGNAL(parserError(Valgrind::XmlProtocol::Error)));
|
2011-03-04 12:15:19 +01:00
|
|
|
connect(&m_parser, SIGNAL(suppressionCount(QString,qint64)),
|
|
|
|
SIGNAL(suppressionCount(QString,qint64)));
|
|
|
|
connect(&m_parser, SIGNAL(internalError(QString)),
|
|
|
|
SIGNAL(internalParserError(QString)));
|
|
|
|
connect(&m_parser, SIGNAL(status(Valgrind::XmlProtocol::Status)),
|
|
|
|
SLOT(status(Valgrind::XmlProtocol::Status)));
|
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
m_progress->setProgressRange(0, XmlProtocol::Status::Finished + 1);
|
2011-03-04 12:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MemcheckEngine::progressTitle() const
|
|
|
|
{
|
|
|
|
return tr("Analyzing Memory");
|
|
|
|
}
|
|
|
|
|
|
|
|
Valgrind::ValgrindRunner *MemcheckEngine::runner()
|
|
|
|
{
|
|
|
|
return &m_runner;
|
|
|
|
}
|
|
|
|
|
2011-07-25 14:49:07 +02:00
|
|
|
bool MemcheckEngine::start()
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
|
|
|
m_runner.setParser(&m_parser);
|
|
|
|
|
2011-06-10 16:34:06 +02:00
|
|
|
emit outputReceived(tr("Analyzing memory of %1\n").arg(executable()),
|
|
|
|
Utils::NormalMessageFormat);
|
2011-07-25 14:49:07 +02:00
|
|
|
return ValgrindEngine::start();
|
2011-03-04 12:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemcheckEngine::stop()
|
|
|
|
{
|
|
|
|
disconnect(&m_parser, SIGNAL(internalError(QString)),
|
|
|
|
this, SIGNAL(internalParserError(QString)));
|
|
|
|
ValgrindEngine::stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList MemcheckEngine::toolArguments() const
|
|
|
|
{
|
|
|
|
QStringList arguments;
|
|
|
|
arguments << QLatin1String("--gen-suppressions=all");
|
|
|
|
|
2011-07-12 16:47:32 +02:00
|
|
|
ValgrindBaseSettings *memcheckSettings = m_settings->subConfig<ValgrindBaseSettings>();
|
2011-03-04 12:15:19 +01:00
|
|
|
QTC_ASSERT(memcheckSettings, return arguments);
|
|
|
|
|
|
|
|
if (memcheckSettings->trackOrigins())
|
|
|
|
arguments << QLatin1String("--track-origins=yes");
|
|
|
|
|
2011-05-11 16:26:34 +02:00
|
|
|
foreach (const QString &file, memcheckSettings->suppressionFiles())
|
2011-03-04 12:15:19 +01:00
|
|
|
arguments << QString("--suppressions=%1").arg(file);
|
|
|
|
|
|
|
|
arguments << QString("--num-callers=%1").arg(memcheckSettings->numCallers());
|
|
|
|
return arguments;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList MemcheckEngine::suppressionFiles() const
|
|
|
|
{
|
2011-07-12 16:47:32 +02:00
|
|
|
return m_settings->subConfig<ValgrindBaseSettings>()->suppressionFiles();
|
2011-03-04 12:15:19 +01:00
|
|
|
}
|
|
|
|
|
2011-03-04 16:00:01 +01:00
|
|
|
void MemcheckEngine::status(const Status &status)
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
|
|
|
m_progress->setProgressValue(status.state() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemcheckEngine::receiveLogMessage(const QByteArray &b)
|
|
|
|
{
|
|
|
|
QString error = QString::fromLocal8Bit(b);
|
|
|
|
// workaround https://bugs.kde.org/show_bug.cgi?id=255888
|
|
|
|
error.remove(QRegExp("==*== </valgrindoutput>", Qt::CaseSensitive, QRegExp::Wildcard));
|
|
|
|
|
|
|
|
error = error.trimmed();
|
|
|
|
|
|
|
|
if (error.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
stop();
|
|
|
|
|
|
|
|
QString file;
|
|
|
|
int line = -1;
|
|
|
|
|
|
|
|
const QRegExp suppressionError(QLatin1String("in suppressions file \"([^\"]+)\" near line (\\d+)"),
|
|
|
|
Qt::CaseSensitive, QRegExp::RegExp2);
|
|
|
|
if (suppressionError.indexIn(error) != -1) {
|
|
|
|
file = suppressionError.cap(1);
|
|
|
|
line = suppressionError.cap(2).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit taskToBeAdded(ProjectExplorer::Task::Error, error, file, line);
|
|
|
|
}
|
2011-05-18 17:05:49 +02:00
|
|
|
|
|
|
|
} // namespace Internal
|
2011-05-23 13:50:28 +02:00
|
|
|
} // namespace Valgrind
|