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

View File

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

View File

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

View File

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

View File

@@ -73,9 +73,9 @@ public:
QStandardItemModel m_model; // The volatile value of this aspect. 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); val.append(suppression);
setValue(val); setValue(val);
} }
@@ -141,14 +141,14 @@ SuppressionAspect::~SuppressionAspect()
delete d; 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) void SuppressionAspect::addToLayout(LayoutBuilder &builder)
@@ -180,7 +180,7 @@ void SuppressionAspect::addToLayout(LayoutBuilder &builder)
}; };
builder.addItem(Span { 2, group }); builder.addItem(Span { 2, group });
setVolatileValue(value()); setVolatileValue(BaseAspect::value());
} }
void SuppressionAspect::fromMap(const QVariantMap &map) void SuppressionAspect::fromMap(const QVariantMap &map)

View File

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