2011-03-04 12:15:19 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator Instrumentation Tools
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Author: Milian Wolff, KDAB (milian.wolff@kdab.com)
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.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-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2011-03-04 12:15:19 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "suppressiondialog.h"
|
|
|
|
|
#include "ui_suppressiondialog.h"
|
2011-04-04 14:39:29 +02:00
|
|
|
|
2011-03-04 12:15:19 +01:00
|
|
|
#include "memcheckerrorview.h"
|
2011-07-12 16:47:32 +02:00
|
|
|
#include "valgrindsettings.h"
|
2011-03-04 12:15:19 +01:00
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
#include "xmlprotocol/suppression.h"
|
|
|
|
|
#include "xmlprotocol/errorlistmodel.h"
|
|
|
|
|
#include "xmlprotocol/stack.h"
|
|
|
|
|
#include "xmlprotocol/frame.h"
|
|
|
|
|
|
2011-03-04 12:15:19 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/projectnodes.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/pathchooser.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2011-03-04 12:15:19 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2011-03-08 13:56:52 +01:00
|
|
|
#include <QtCore/QFile>
|
|
|
|
|
#include <QtGui/QPushButton>
|
2011-03-04 12:15:19 +01:00
|
|
|
|
|
|
|
|
using namespace Analyzer;
|
|
|
|
|
using namespace Valgrind::XmlProtocol;
|
|
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
namespace Valgrind {
|
|
|
|
|
namespace Internal {
|
2011-05-18 17:05:49 +02:00
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
static QString suppressionText(const Error &error)
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
|
|
|
|
Suppression sup(error.suppression());
|
|
|
|
|
|
|
|
|
|
// workaround: https://bugs.kde.org/show_bug.cgi?id=255822
|
2011-07-13 14:58:54 +02:00
|
|
|
if (sup.frames().size() >= 24)
|
2011-03-04 12:15:19 +01:00
|
|
|
sup.setFrames(sup.frames().mid(0, 23));
|
2011-07-13 14:58:54 +02:00
|
|
|
QTC_ASSERT(sup.frames().size() < 24, /**/)
|
2011-03-04 12:15:19 +01:00
|
|
|
|
|
|
|
|
// try to set some useful name automatically, instead of "insert_name_here"
|
|
|
|
|
// we take the last stack frame and append the suppression kind, e.g.:
|
|
|
|
|
// QDebug::operator<<(bool) [Memcheck:Cond]
|
|
|
|
|
if (!error.stacks().isEmpty() && !error.stacks().first().frames().isEmpty()) {
|
|
|
|
|
const Frame &frame = error.stacks().first().frames().first();
|
|
|
|
|
|
|
|
|
|
QString newName;
|
|
|
|
|
if (!frame.functionName().isEmpty())
|
|
|
|
|
newName = frame.functionName();
|
|
|
|
|
else if (!frame.object().isEmpty())
|
|
|
|
|
newName = frame.object();
|
|
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
if (!newName.isEmpty())
|
2011-03-04 12:15:19 +01:00
|
|
|
sup.setName(newName + '[' + sup.kind() + ']');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sup.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// @p error input error, which might get hidden when it has the same stack
|
|
|
|
|
/// @p suppressed the error that got suppressed already
|
2011-05-18 17:05:49 +02:00
|
|
|
static bool equalSuppression(const Error &error, const Error &suppressed)
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
|
|
|
|
if (error.kind() != suppressed.kind() || error.suppression().isNull())
|
|
|
|
|
return false;
|
|
|
|
|
|
2011-05-18 17:05:49 +02:00
|
|
|
const SuppressionFrames errorFrames = error.suppression().frames();
|
|
|
|
|
const SuppressionFrames suppressedFrames = suppressed.suppression().frames();
|
2011-03-04 12:15:19 +01:00
|
|
|
|
|
|
|
|
// limit to 23 frames, see: https://bugs.kde.org/show_bug.cgi?id=255822
|
|
|
|
|
if (qMin(23, suppressedFrames.size()) > errorFrames.size())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int frames = 23;
|
|
|
|
|
if (errorFrames.size() < frames)
|
|
|
|
|
frames = errorFrames.size();
|
|
|
|
|
|
|
|
|
|
if (suppressedFrames.size() < frames)
|
|
|
|
|
frames = suppressedFrames.size();
|
|
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
for (int i = 0; i < frames; ++i)
|
2011-03-04 12:15:19 +01:00
|
|
|
if (errorFrames.at(i) != suppressedFrames.at(i))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool sortIndizesReverse(const QModelIndex &l, const QModelIndex &r)
|
|
|
|
|
{
|
|
|
|
|
return l.row() > r.row();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
SuppressionDialog::SuppressionDialog(MemcheckErrorView *view)
|
|
|
|
|
: QDialog(),
|
2011-05-18 17:05:49 +02:00
|
|
|
m_view(view),
|
|
|
|
|
m_ui(new Ui::SuppressionDialog),
|
|
|
|
|
m_settings(view->settings()),
|
|
|
|
|
m_cleanupIfCanceled(false)
|
2011-03-04 12:15:19 +01:00
|
|
|
{
|
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
// NOTE: pathchooser requires existing files.
|
2011-03-04 12:15:19 +01:00
|
|
|
QFile defaultSuppFile(view->defaultSuppressionFile());
|
|
|
|
|
if (!defaultSuppFile.exists()) {
|
|
|
|
|
if (defaultSuppFile.open(QIODevice::WriteOnly)) {
|
|
|
|
|
defaultSuppFile.close();
|
|
|
|
|
m_cleanupIfCanceled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
// NOTE: First set kind, then set path. Otherwise the file will be seen as "invalid".
|
2011-03-04 12:15:19 +01:00
|
|
|
m_ui->fileChooser->setExpectedKind(Utils::PathChooser::File);
|
|
|
|
|
m_ui->fileChooser->setPath(defaultSuppFile.fileName());
|
|
|
|
|
m_ui->fileChooser->setPromptDialogFilter(QLatin1String("*.supp"));
|
|
|
|
|
m_ui->fileChooser->setPromptDialogTitle(tr("Select Suppression File"));
|
|
|
|
|
connect(m_ui->fileChooser, SIGNAL(validChanged()),
|
|
|
|
|
SLOT(validate()));
|
|
|
|
|
connect(m_ui->suppressionEdit->document(), SIGNAL(contentsChanged()),
|
|
|
|
|
SLOT(validate()));
|
|
|
|
|
|
|
|
|
|
QString suppressions;
|
2011-07-13 14:58:54 +02:00
|
|
|
QModelIndexList indices = m_view->selectionModel()->selectedRows();
|
|
|
|
|
if (indices.isEmpty() && m_view->selectionModel()->currentIndex().isValid()) {
|
2011-03-04 16:00:04 +01:00
|
|
|
// can happen when using arrow keys to navigate and shortcut to trigger suppression
|
2011-07-13 14:58:54 +02:00
|
|
|
indices.append(m_view->selectionModel()->currentIndex());
|
2011-03-04 16:00:04 +01:00
|
|
|
}
|
2011-07-13 14:58:54 +02:00
|
|
|
foreach (const QModelIndex &index, indices) {
|
2011-03-04 12:15:19 +01:00
|
|
|
Error error = m_view->model()->data(index, ErrorListModel::ErrorRole).value<Error>();
|
|
|
|
|
if (!error.suppression().isNull())
|
2011-07-13 14:58:54 +02:00
|
|
|
m_errors.append(error);
|
2011-03-04 12:15:19 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-11 16:26:34 +02:00
|
|
|
foreach (const Error &error, m_errors)
|
2011-03-04 12:15:19 +01:00
|
|
|
suppressions += suppressionText(error);
|
|
|
|
|
|
|
|
|
|
m_ui->suppressionEdit->setPlainText(suppressions);
|
|
|
|
|
|
|
|
|
|
setWindowTitle(tr("Save Suppression"));
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-28 13:22:45 +02:00
|
|
|
SuppressionDialog::~SuppressionDialog()
|
|
|
|
|
{
|
|
|
|
|
delete m_ui;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-04 16:00:04 +01:00
|
|
|
bool SuppressionDialog::shouldShow() const
|
|
|
|
|
{
|
|
|
|
|
return !m_errors.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-04 12:15:19 +01:00
|
|
|
void SuppressionDialog::accept()
|
|
|
|
|
{
|
|
|
|
|
const QString path = m_ui->fileChooser->path();
|
|
|
|
|
QTC_ASSERT(!path.isEmpty(), return);
|
|
|
|
|
QTC_ASSERT(!m_ui->suppressionEdit->toPlainText().trimmed().isEmpty(), return);
|
|
|
|
|
|
2011-03-30 15:15:15 +02:00
|
|
|
Utils::FileSaver saver(path, QIODevice::Append);
|
|
|
|
|
QTextStream stream(saver.file());
|
2011-03-04 12:15:19 +01:00
|
|
|
stream << m_ui->suppressionEdit->toPlainText();
|
2011-03-30 15:15:15 +02:00
|
|
|
saver.setResult(&stream);
|
|
|
|
|
if (!saver.finalize(this))
|
|
|
|
|
return;
|
2011-03-04 12:15:19 +01:00
|
|
|
|
|
|
|
|
// add file to project (if there is a project that contains this file on the file system)
|
|
|
|
|
ProjectExplorer::SessionManager *session = ProjectExplorer::ProjectExplorerPlugin::instance()->session();
|
|
|
|
|
if (!session->projectForFile(path)) {
|
2011-05-11 16:26:34 +02:00
|
|
|
foreach (ProjectExplorer::Project *p, session->projects()) {
|
2011-03-04 12:15:19 +01:00
|
|
|
if (path.startsWith(p->projectDirectory())) {
|
|
|
|
|
p->rootProjectNode()->addFiles(ProjectExplorer::UnknownFileType, QStringList() << path);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-12 16:47:32 +02:00
|
|
|
m_settings->subConfig<ValgrindBaseSettings>()->addSuppressionFiles(QStringList(path));
|
2011-03-04 12:15:19 +01:00
|
|
|
|
2011-07-13 14:58:54 +02:00
|
|
|
QModelIndexList indices = m_view->selectionModel()->selectedRows();
|
|
|
|
|
qSort(indices.begin(), indices.end(), sortIndizesReverse);
|
|
|
|
|
foreach (const QModelIndex &index, indices) {
|
2011-03-04 12:15:19 +01:00
|
|
|
bool removed = m_view->model()->removeRow(index.row());
|
|
|
|
|
QTC_ASSERT(removed, qt_noop());
|
|
|
|
|
Q_UNUSED(removed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// one suppression might hide multiple rows, care for that
|
|
|
|
|
for (int row = 0; row < m_view->model()->rowCount(); ++row ) {
|
|
|
|
|
const Error rowError = m_view->model()->data(
|
|
|
|
|
m_view->model()->index(row, 0), ErrorListModel::ErrorRole).value<Error>();
|
|
|
|
|
|
2011-05-11 16:26:34 +02:00
|
|
|
foreach (const Error &error, m_errors) {
|
2011-03-04 12:15:19 +01:00
|
|
|
if (equalSuppression(rowError, error)) {
|
|
|
|
|
bool removed = m_view->model()->removeRow(row);
|
|
|
|
|
QTC_ASSERT(removed, qt_noop());
|
|
|
|
|
Q_UNUSED(removed);
|
|
|
|
|
// gets increased in the for loop again
|
|
|
|
|
--row;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// select a new item
|
2011-07-13 14:58:54 +02:00
|
|
|
m_view->setCurrentIndex(indices.first());
|
2011-03-04 12:15:19 +01:00
|
|
|
|
|
|
|
|
QDialog::accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SuppressionDialog::reject()
|
|
|
|
|
{
|
2011-05-18 17:05:49 +02:00
|
|
|
if (m_cleanupIfCanceled)
|
2011-03-04 12:15:19 +01:00
|
|
|
QFile::remove(m_view->defaultSuppressionFile());
|
|
|
|
|
|
|
|
|
|
QDialog::reject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SuppressionDialog::validate()
|
|
|
|
|
{
|
2011-05-18 17:05:49 +02:00
|
|
|
bool valid = m_ui->fileChooser->isValid()
|
|
|
|
|
&& !m_ui->suppressionEdit->toPlainText().trimmed().isEmpty();
|
2011-03-04 12:15:19 +01:00
|
|
|
|
|
|
|
|
m_ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(valid);
|
|
|
|
|
}
|
2011-05-18 17:05:49 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
2011-05-23 13:50:28 +02:00
|
|
|
} // namespace Valgrind
|