Valgrind: Use FilePath for some suppression files

Change-Id: I48490a77d569d752ada1883554cf307148f2c0cb
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-09-30 17:12:10 +02:00
parent 2bb6bb633f
commit 8d68e05d05
6 changed files with 48 additions and 48 deletions

View File

@@ -46,6 +46,7 @@
#include <QAction>
using namespace Utils;
using namespace Valgrind::XmlProtocol;
namespace Valgrind {
@@ -56,10 +57,10 @@ MemcheckErrorView::MemcheckErrorView(QWidget *parent)
{
m_suppressAction = new QAction(this);
m_suppressAction->setText(tr("Suppress Error"));
const QIcon icon = Utils::Icon({
{":/utils/images/eye_open.png", Utils::Theme::TextColorNormal},
{":/valgrind/images/suppressoverlay.png", Utils::Theme::IconsErrorColor}},
Utils::Icon::Tint | Utils::Icon::PunchEdges).icon();
const QIcon icon = Icon({
{":/utils/images/eye_open.png", Theme::TextColorNormal},
{":/valgrind/images/suppressoverlay.png", Theme::IconsErrorColor}},
Icon::Tint | Icon::PunchEdges).icon();
m_suppressAction->setIcon(icon);
m_suppressAction->setShortcuts({QKeySequence::Delete, QKeySequence::Backspace});
m_suppressAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
@@ -69,12 +70,12 @@ MemcheckErrorView::MemcheckErrorView(QWidget *parent)
MemcheckErrorView::~MemcheckErrorView() = default;
void MemcheckErrorView::setDefaultSuppressionFile(const QString &suppFile)
void MemcheckErrorView::setDefaultSuppressionFile(const FilePath &suppFile)
{
m_defaultSuppFile = suppFile;
}
QString MemcheckErrorView::defaultSuppressionFile() const
FilePath MemcheckErrorView::defaultSuppressionFile() const
{
return m_defaultSuppFile;
}

View File

@@ -28,6 +28,8 @@
#include <debugger/analyzer/detailederrorview.h>
#include <utils/filepath.h>
#include <QListView>
namespace Valgrind {
@@ -43,8 +45,8 @@ public:
MemcheckErrorView(QWidget *parent = nullptr);
~MemcheckErrorView() override;
void setDefaultSuppressionFile(const QString &suppFile);
QString defaultSuppressionFile() const;
void setDefaultSuppressionFile(const Utils::FilePath &suppFile);
Utils::FilePath defaultSuppressionFile() const;
ValgrindBaseSettings *settings() const { return m_settings; }
void settingsChanged(ValgrindBaseSettings *settings);
@@ -53,7 +55,7 @@ private:
QList<QAction *> customActions() const override;
QAction *m_suppressAction;
QString m_defaultSuppFile;
Utils::FilePath m_defaultSuppFile;
ValgrindBaseSettings *m_settings = nullptr;
};

View File

@@ -128,7 +128,7 @@ public:
void start() override;
void stop() override;
const QStringList suppressionFiles() const;
const Utils::FilePaths suppressionFiles() const;
signals:
void internalParserError(const QString &errorString);
@@ -212,8 +212,8 @@ QStringList MemcheckToolRunner::toolArguments() const
}
arguments << "--leak-check=" + leakCheckValue;
for (const QString &file : m_settings.suppressions.value())
arguments << QString("--suppressions=%1").arg(file);
for (const FilePath &file : m_settings.suppressions.value())
arguments << QString("--suppressions=%1").arg(file.path());
arguments << QString("--num-callers=%1").arg(m_settings.numCallers.value());
@@ -225,7 +225,7 @@ QStringList MemcheckToolRunner::toolArguments() const
return arguments;
}
const QStringList MemcheckToolRunner::suppressionFiles() const
const FilePaths MemcheckToolRunner::suppressionFiles() const
{
return m_settings.suppressions.value();
}
@@ -991,15 +991,15 @@ void MemcheckToolPrivate::setupRunner(MemcheckToolRunner *runTool)
clearErrorView();
m_loadExternalLogFile->setDisabled(true);
QString dir = runControl->project()->projectDirectory().toString() + '/';
const FilePath dir = runControl->project()->projectDirectory();
const QString name = runTool->executable().fileName();
m_errorView->setDefaultSuppressionFile(dir + name + ".supp");
m_errorView->setDefaultSuppressionFile(dir.pathAppended(name + ".supp"));
const QStringList suppressionFiles = runTool->suppressionFiles();
for (const QString &file : suppressionFiles) {
QAction *action = m_filterMenu->addAction(FilePath::fromString(file).fileName());
action->setToolTip(file);
const FilePaths suppressionFiles = runTool->suppressionFiles();
for (const FilePath &file : suppressionFiles) {
QAction *action = m_filterMenu->addAction(file.fileName());
action->setToolTip(file.toUserOutput());
connect(action, &QAction::triggered, this, [file] {
EditorManager::openEditorAt(file, 0);
});

View File

@@ -51,6 +51,7 @@
#include <QPlainTextEdit>
#include <QPushButton>
using namespace Utils;
using namespace Valgrind::XmlProtocol;
namespace Valgrind {
@@ -63,7 +64,7 @@ static QString suppressionText(const Error &error)
// workaround: https://bugs.kde.org/show_bug.cgi?id=255822
if (sup.frames().size() >= 24)
sup.setFrames(sup.frames().mid(0, 23));
QTC_ASSERT(sup.frames().size() < 24, /**/);
QTC_CHECK(sup.frames().size() < 24);
// 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.:
@@ -117,7 +118,7 @@ SuppressionDialog::SuppressionDialog(MemcheckErrorView *view, const QList<Error>
m_settings(view->settings()),
m_cleanupIfCanceled(false),
m_errors(errors),
m_fileChooser(new Utils::PathChooser(this)),
m_fileChooser(new PathChooser(this)),
m_suppressionEdit(new QPlainTextEdit(this))
{
setWindowTitle(tr("Save Suppression"));
@@ -140,27 +141,23 @@ SuppressionDialog::SuppressionDialog(MemcheckErrorView *view, const QList<Error>
formLayout->addRow(m_suppressionEdit);
formLayout->addRow(m_buttonBox);
QFile defaultSuppFile(view->defaultSuppressionFile());
if (!defaultSuppFile.exists()) {
if (defaultSuppFile.open(QIODevice::WriteOnly)) {
defaultSuppFile.close();
const FilePath defaultSuppFile = view->defaultSuppressionFile();
if (!defaultSuppFile.exists() && defaultSuppFile.ensureExistingFile())
m_cleanupIfCanceled = true;
}
}
m_fileChooser->setExpectedKind(Utils::PathChooser::File);
m_fileChooser->setExpectedKind(PathChooser::File);
m_fileChooser->setHistoryCompleter("Valgrind.Suppression.History");
m_fileChooser->setPath(defaultSuppFile.fileName());
m_fileChooser->setPromptDialogFilter("*.supp");
m_fileChooser->setPromptDialogTitle(tr("Select Suppression File"));
QString suppressions;
foreach (const Error &error, m_errors)
for (const Error &error : qAsConst(m_errors))
suppressions += suppressionText(error);
m_suppressionEdit->setPlainText(suppressions);
connect(m_fileChooser, &Utils::PathChooser::validChanged,
connect(m_fileChooser, &PathChooser::validChanged,
this, &SuppressionDialog::validate);
connect(m_suppressionEdit->document(), &QTextDocument::contentsChanged,
this, &SuppressionDialog::validate);
@@ -178,7 +175,7 @@ void SuppressionDialog::maybeShow(MemcheckErrorView *view)
indices.append(view->selectionModel()->currentIndex());
QList<XmlProtocol::Error> errors;
foreach (const QModelIndex &index, indices) {
for (const QModelIndex &index : qAsConst(indices)) {
Error error = view->model()->data(index, ErrorListModel::ErrorRole).value<Error>();
if (!error.suppression().isNull())
errors.append(error);
@@ -193,11 +190,11 @@ void SuppressionDialog::maybeShow(MemcheckErrorView *view)
void SuppressionDialog::accept()
{
const Utils::FilePath path = m_fileChooser->filePath();
const FilePath path = m_fileChooser->filePath();
QTC_ASSERT(!path.isEmpty(), return);
QTC_ASSERT(!m_suppressionEdit->toPlainText().trimmed().isEmpty(), return);
Utils::FileSaver saver(path, QIODevice::Append);
FileSaver saver(path, QIODevice::Append);
if (!saver.hasError()) {
QTextStream stream(saver.file());
stream << m_suppressionEdit->toPlainText();
@@ -216,14 +213,14 @@ void SuppressionDialog::accept()
}
}
m_settings->suppressions.addSuppressionFile(path.toString());
m_settings->suppressions.addSuppressionFile(path);
QModelIndexList indices = m_view->selectionModel()->selectedRows();
Utils::sort(indices, [](const QModelIndex &l, const QModelIndex &r) {
return l.row() > r.row();
});
QAbstractItemModel *model = m_view->model();
foreach (const QModelIndex &index, indices) {
for (const QModelIndex &index : qAsConst(indices)) {
bool removed = model->removeRow(index.row());
QTC_ASSERT(removed, qt_noop());
Q_UNUSED(removed)
@@ -234,7 +231,7 @@ void SuppressionDialog::accept()
const Error rowError = model->data(
model->index(row, 0), ErrorListModel::ErrorRole).value<Error>();
foreach (const Error &error, m_errors) {
for (const Error &error : qAsConst(m_errors)) {
if (equalSuppression(rowError, error)) {
bool removed = model->removeRow(row);
QTC_CHECK(removed);
@@ -254,7 +251,7 @@ void SuppressionDialog::accept()
void SuppressionDialog::reject()
{
if (m_cleanupIfCanceled)
QFile::remove(m_view->defaultSuppressionFile());
m_view->defaultSuppressionFile().removeFile();
QDialog::reject();
}

View File

@@ -73,9 +73,9 @@ public:
QStandardItemModel m_model; // The volatile value of this aspect.
};
void SuppressionAspect::addSuppressionFile(const QString &suppression)
void SuppressionAspect::addSuppressionFile(const FilePath &suppression)
{
QStringList val = value();
FilePaths val = value();
val.append(suppression);
setValue(val);
}
@@ -141,14 +141,14 @@ SuppressionAspect::~SuppressionAspect()
delete d;
}
QStringList SuppressionAspect::value() const
FilePaths SuppressionAspect::value() const
{
return BaseAspect::value().toStringList();
return Utils::transform(BaseAspect::value().toStringList(), &FilePath::fromString);
}
void SuppressionAspect::setValue(const QStringList &val)
void SuppressionAspect::setValue(const FilePaths &val)
{
BaseAspect::setValue(val);
BaseAspect::setValue(Utils::transform<QStringList>(val, &FilePath::toString));
}
void SuppressionAspect::addToLayout(LayoutBuilder &builder)
@@ -180,7 +180,7 @@ void SuppressionAspect::addToLayout(LayoutBuilder &builder)
};
builder.addItem(Span { 2, group });
setVolatileValue(value());
setVolatileValue(BaseAspect::value());
}
void SuppressionAspect::fromMap(const QVariantMap &map)

View File

@@ -46,8 +46,8 @@ public:
explicit SuppressionAspect(bool global);
~SuppressionAspect() final;
QStringList value() const;
void setValue(const QStringList &val);
Utils::FilePaths value() const;
void setValue(const Utils::FilePaths &val);
void addToLayout(Utils::LayoutBuilder &builder) final;
@@ -57,7 +57,7 @@ public:
QVariant volatileValue() const final;
void setVolatileValue(const QVariant &val) final;
void addSuppressionFile(const QString &suppressionFile);
void addSuppressionFile(const Utils::FilePath &suppressionFile);
private:
friend class ValgrindBaseSettings;