summaryrefslogtreecommitdiff
path: root/src/plugins/memcheck/memchecksettings.cpp
blob: 9aff4115927459bafc36fe412ec06239f2b2bb4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Author: Milian Wolff, KDAB (milian.wolff@kdab.com)
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/

#include "memchecksettings.h"
#include "memcheckconfigwidget.h"

#include <valgrind/xmlprotocol/error.h>

#include <utils/qtcassert.h>

using namespace Analyzer;
using namespace Memcheck;

using namespace Memcheck::Internal;

static const QLatin1String numCallersC("Analyzer.Valgrind.NumCallers");
static const QLatin1String trackOriginsC("Analyzer.Valgrind.TrackOrigins");
static const QLatin1String suppressionFilesC("Analyzer.Valgrind.SupressionFiles");
static const QLatin1String removedSuppressionFilesC("Analyzer.Valgrind.RemovedSupressionFiles");
static const QLatin1String addedSuppressionFilesC("Analyzer.Valgrind.AddedSupressionFiles");
static const QLatin1String filterExternalIssuesC("Analyzer.Valgrind.FilterExternalIssues");
static const QLatin1String visibleErrorKindsC("Analyzer.Valgrind.VisibleErrorKinds");

static const QLatin1String lastSuppressionDirectoryC("Analyzer.Valgrind.LastSuppressionDirectory");
static const QLatin1String lastSuppressionHistoryC("Analyzer.Valgrind.LastSuppressionHistory");

AbstractMemcheckSettings::AbstractMemcheckSettings(QObject *parent)
: AbstractAnalyzerSubConfig(parent)
{
}

AbstractMemcheckSettings::~AbstractMemcheckSettings()
{

}

QVariantMap AbstractMemcheckSettings::defaults() const
{
    QVariantMap map;
    map.insert(numCallersC, 25);
    map.insert(trackOriginsC, true);
    map.insert(filterExternalIssuesC, true);

    QVariantList defaultErrorKinds;
    for(int i = 0; i < Valgrind::XmlProtocol::MemcheckErrorKindCount; ++i)
        defaultErrorKinds << i;
    map.insert(visibleErrorKindsC, defaultErrorKinds);

    return map;
}

bool AbstractMemcheckSettings::fromMap(const QVariantMap &map)
{
    setIfPresent(map, numCallersC, &m_numCallers);
    setIfPresent(map, trackOriginsC, &m_trackOrigins);
    setIfPresent(map, filterExternalIssuesC, &m_filterExternalIssues);

    // if we get more of these try a template specialization of setIfPresent for lists...
    if (map.contains(visibleErrorKindsC)) {
        m_visibleErrorKinds.clear();
        foreach(const QVariant &val, map.value(visibleErrorKindsC).toList())
            m_visibleErrorKinds << val.toInt();
    }

    return true;
}

QVariantMap AbstractMemcheckSettings::toMap() const
{
    QVariantMap map;
    map.insert(numCallersC, m_numCallers);
    map.insert(trackOriginsC, m_trackOrigins);
    map.insert(filterExternalIssuesC, m_filterExternalIssues);

    QVariantList errorKinds;
    foreach (int i, m_visibleErrorKinds)
        errorKinds << i;
    map.insert(visibleErrorKindsC, errorKinds);

    return map;
}

void AbstractMemcheckSettings::setNumCallers(int numCallers)
{
    if (m_numCallers != numCallers) {
        m_numCallers = numCallers;
        emit numCallersChanged(numCallers);
    }
}

void AbstractMemcheckSettings::setTrackOrigins(bool trackOrigins)
{
    if (m_trackOrigins != trackOrigins) {
        m_trackOrigins = trackOrigins;
        emit trackOriginsChanged(trackOrigins);
    }
}

void AbstractMemcheckSettings::setFilterExternalIssues(bool filterExternalIssues)
{
    if (m_filterExternalIssues != filterExternalIssues) {
        m_filterExternalIssues = filterExternalIssues;
        emit filterExternalIssuesChanged(filterExternalIssues);
    }
}

void AbstractMemcheckSettings::setVisibleErrorKinds(const QList<int> &visibleErrorKinds)
{
    if (m_visibleErrorKinds != visibleErrorKinds) {
        m_visibleErrorKinds = visibleErrorKinds;
        emit visibleErrorKindsChanged(visibleErrorKinds);
    }
}

QString AbstractMemcheckSettings::id() const
{
    return "Analyzer.Valgrind.Settings.Memcheck";
}

QString AbstractMemcheckSettings::displayName() const
{
    return tr("Memory Analysis");
}

QWidget *AbstractMemcheckSettings::createConfigWidget(QWidget *parent)
{
    return new MemcheckConfigWidget(this, parent);
}

MemcheckGlobalSettings::MemcheckGlobalSettings(QObject *parent)
: AbstractMemcheckSettings(parent)
{
}

MemcheckGlobalSettings::~MemcheckGlobalSettings()
{
}

QStringList MemcheckGlobalSettings::suppressionFiles() const
{
    return m_suppressionFiles;
}

void MemcheckGlobalSettings::addSuppressionFiles(const QStringList &suppressions)
{
    foreach (const QString &s, suppressions)
        if (!m_suppressionFiles.contains(s))
            m_suppressionFiles.append(s);
}

void MemcheckGlobalSettings::removeSuppressionFiles(const QStringList &suppressions)
{
    foreach (const QString &s, suppressions)
        m_suppressionFiles.removeAll(s);
}

QString MemcheckGlobalSettings::lastSuppressionDialogDirectory() const
{
    return m_lastSuppressionDirectory;
}

void MemcheckGlobalSettings::setLastSuppressionDialogDirectory(const QString &directory)
{
    m_lastSuppressionDirectory = directory;
}

QStringList MemcheckGlobalSettings::lastSuppressionDialogHistory() const
{
    return m_lastSuppressionHistory;
}

void MemcheckGlobalSettings::setLastSuppressionDialogHistory(const QStringList &history)
{
    m_lastSuppressionHistory = history;
}

QVariantMap MemcheckGlobalSettings::defaults() const
{
    QVariantMap ret = AbstractMemcheckSettings::defaults();
    ret.insert(suppressionFilesC, QStringList());
    ret.insert(lastSuppressionDirectoryC, QString());
    ret.insert(lastSuppressionHistoryC, QStringList());
    return ret;
}

bool MemcheckGlobalSettings::fromMap(const QVariantMap &map)
{
    AbstractMemcheckSettings::fromMap(map);
    m_suppressionFiles = map.value(suppressionFilesC).toStringList();
    m_lastSuppressionDirectory = map.value(lastSuppressionDirectoryC).toString();
    m_lastSuppressionHistory = map.value(lastSuppressionHistoryC).toStringList();
    return true;
}

QVariantMap MemcheckGlobalSettings::toMap() const
{
    QVariantMap map = AbstractMemcheckSettings::toMap();
    map.insert(suppressionFilesC, m_suppressionFiles);
    map.insert(lastSuppressionDirectoryC, m_lastSuppressionDirectory);
    map.insert(lastSuppressionHistoryC, m_lastSuppressionHistory);
    return map;
}

MemcheckGlobalSettings *globalMemcheckSettings()
{
    MemcheckGlobalSettings *ret = AnalyzerGlobalSettings::instance()->subConfig<MemcheckGlobalSettings>();
    QTC_ASSERT(ret, return 0);
    return ret;
}

MemcheckProjectSettings::MemcheckProjectSettings(QObject *parent)
: AbstractMemcheckSettings(parent)
{
}

MemcheckProjectSettings::~MemcheckProjectSettings()
{
}

QVariantMap MemcheckProjectSettings::defaults() const
{
    QVariantMap ret = AbstractMemcheckSettings::defaults();
    ret.insert(addedSuppressionFilesC, QStringList());
    ret.insert(removedSuppressionFilesC, QStringList());
    return ret;
}

bool MemcheckProjectSettings::fromMap(const QVariantMap &map)
{
    AbstractMemcheckSettings::fromMap(map);
    setIfPresent(map, addedSuppressionFilesC, &m_addedSuppressionFiles);
    setIfPresent(map, removedSuppressionFilesC, &m_disabledGlobalSuppressionFiles);
    return true;
}

QVariantMap MemcheckProjectSettings::toMap() const
{
    QVariantMap map = AbstractMemcheckSettings::toMap();
    map.insert(addedSuppressionFilesC, m_addedSuppressionFiles);
    map.insert(removedSuppressionFilesC, m_disabledGlobalSuppressionFiles);
    return map;
}

void MemcheckProjectSettings::addSuppressionFiles(const QStringList &suppressions)
{
    QStringList globalSuppressions = globalMemcheckSettings()->suppressionFiles();
    foreach (const QString &s, suppressions) {
        if (m_addedSuppressionFiles.contains(s))
            continue;
        m_disabledGlobalSuppressionFiles.removeAll(s);
        if (!globalSuppressions.contains(s))
            m_addedSuppressionFiles.append(s);
    }
}

void MemcheckProjectSettings::removeSuppressionFiles(const QStringList &suppressions)
{
    QStringList globalSuppressions = globalMemcheckSettings()->suppressionFiles();
    foreach (const QString &s, suppressions) {
        m_addedSuppressionFiles.removeAll(s);
        if (globalSuppressions.contains(s))
            m_disabledGlobalSuppressionFiles.append(s);
    }
}

QStringList MemcheckProjectSettings::suppressionFiles() const
{
    QStringList ret = globalMemcheckSettings()->suppressionFiles();
    foreach (const QString &s, m_disabledGlobalSuppressionFiles)
        ret.removeAll(s);
    ret.append(m_addedSuppressionFiles);
    return ret;
}