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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
** Author: Milian Wolff, KDAB (milian.wolff@kdab.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "valgrindsettings.h"
#include "valgrindplugin.h"
#include "valgrindconfigwidget.h"
#include <coreplugin/icore.h>
#include <utils/qtcassert.h>
#include <valgrind/xmlprotocol/error.h>
#include <QSettings>
#include <QDebug>
using namespace Analyzer;
const char numCallersC[] = "Analyzer.Valgrind.NumCallers";
const char leakCheckOnFinishC[] = "Analyzer.Valgrind.LeakCheckOnFinish";
const char showReachableC[] = "Analyzer.Valgrind.ShowReachable";
const char trackOriginsC[] = "Analyzer.Valgrind.TrackOrigins";
const char selfModifyingCodeDetectionC[] = "Analyzer.Valgrind.SelfModifyingCodeDetection";
const char suppressionFilesC[] = "Analyzer.Valgrind.SupressionFiles";
const char removedSuppressionFilesC[] = "Analyzer.Valgrind.RemovedSuppressionFiles";
const char addedSuppressionFilesC[] = "Analyzer.Valgrind.AddedSuppressionFiles";
const char filterExternalIssuesC[] = "Analyzer.Valgrind.FilterExternalIssues";
const char visibleErrorKindsC[] = "Analyzer.Valgrind.VisibleErrorKinds";
const char lastSuppressionDirectoryC[] = "Analyzer.Valgrind.LastSuppressionDirectory";
const char lastSuppressionHistoryC[] = "Analyzer.Valgrind.LastSuppressionHistory";
const char callgrindEnableCacheSimC[] = "Analyzer.Valgrind.Callgrind.EnableCacheSim";
const char callgrindEnableBranchSimC[] = "Analyzer.Valgrind.Callgrind.EnableBranchSim";
const char callgrindCollectSystimeC[] = "Analyzer.Valgrind.Callgrind.CollectSystime";
const char callgrindCollectBusEventsC[] = "Analyzer.Valgrind.Callgrind.CollectBusEvents";
const char callgrindEnableEventToolTipsC[] = "Analyzer.Valgrind.Callgrind.EnableEventToolTips";
const char callgrindMinimumCostRatioC[] = "Analyzer.Valgrind.Callgrind.MinimumCostRatio";
const char callgrindVisualisationMinimumCostRatioC[] = "Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio";
const char callgrindCycleDetectionC[] = "Analyzer.Valgrind.Callgrind.CycleDetection";
const char callgrindShortenTemplates[] = "Analyzer.Valgrind.Callgrind.ShortenTemplates";
const char callgrindCostFormatC[] = "Analyzer.Valgrind.Callgrind.CostFormat";
const char valgrindExeC[] = "Analyzer.Valgrind.ValgrindExecutable";
namespace Valgrind {
namespace Internal {
//////////////////////////////////////////////////////////////////
//
// ValgrindBaseSettings
//
//////////////////////////////////////////////////////////////////
/**
* Utility function to set @p val if @p key is present in @p map.
*/
template <typename T> void setIfPresent(const QVariantMap &map, const QString &key, T *val)
{
if (map.contains(key))
*val = map.value(key).template value<T>();
}
void ValgrindBaseSettings::fromMap(const QVariantMap &map)
{
// General
setIfPresent(map, QLatin1String(valgrindExeC), &m_valgrindExecutable);
setIfPresent(map, QLatin1String(selfModifyingCodeDetectionC),
(int*) &m_selfModifyingCodeDetection);
// Memcheck
setIfPresent(map, QLatin1String(numCallersC), &m_numCallers);
setIfPresent(map, QLatin1String(leakCheckOnFinishC), (int*) &m_leakCheckOnFinish);
setIfPresent(map, QLatin1String(showReachableC), &m_showReachable);
setIfPresent(map, QLatin1String(trackOriginsC), &m_trackOrigins);
setIfPresent(map, QLatin1String(filterExternalIssuesC), &m_filterExternalIssues);
if (map.contains(QLatin1String(visibleErrorKindsC))) {
m_visibleErrorKinds.clear();
foreach (const QVariant &val, map.value(QLatin1String(visibleErrorKindsC)).toList())
m_visibleErrorKinds << val.toInt();
}
// Callgrind
setIfPresent(map, QLatin1String(callgrindEnableCacheSimC), &m_enableCacheSim);
setIfPresent(map, QLatin1String(callgrindEnableBranchSimC), &m_enableBranchSim);
setIfPresent(map, QLatin1String(callgrindCollectSystimeC), &m_collectSystime);
setIfPresent(map, QLatin1String(callgrindCollectBusEventsC), &m_collectBusEvents);
setIfPresent(map, QLatin1String(callgrindEnableEventToolTipsC), &m_enableEventToolTips);
setIfPresent(map, QLatin1String(callgrindMinimumCostRatioC), &m_minimumInclusiveCostRatio);
setIfPresent(map, QLatin1String(callgrindVisualisationMinimumCostRatioC),
&m_visualisationMinimumInclusiveCostRatio);
emit changed();
}
void ValgrindBaseSettings::toMap(QVariantMap &map) const
{
// General
map.insert(QLatin1String(valgrindExeC), m_valgrindExecutable);
map.insert(QLatin1String(selfModifyingCodeDetectionC), m_selfModifyingCodeDetection);
// Memcheck
map.insert(QLatin1String(numCallersC), m_numCallers);
map.insert(QLatin1String(leakCheckOnFinishC), m_leakCheckOnFinish);
map.insert(QLatin1String(showReachableC), m_showReachable);
map.insert(QLatin1String(trackOriginsC), m_trackOrigins);
map.insert(QLatin1String(filterExternalIssuesC), m_filterExternalIssues);
QVariantList errorKinds;
foreach (int i, m_visibleErrorKinds)
errorKinds << i;
map.insert(QLatin1String(visibleErrorKindsC), errorKinds);
// Callgrind
map.insert(QLatin1String(callgrindEnableCacheSimC), m_enableCacheSim);
map.insert(QLatin1String(callgrindEnableBranchSimC), m_enableBranchSim);
map.insert(QLatin1String(callgrindCollectSystimeC), m_collectSystime);
map.insert(QLatin1String(callgrindCollectBusEventsC), m_collectBusEvents);
map.insert(QLatin1String(callgrindEnableEventToolTipsC), m_enableEventToolTips);
map.insert(QLatin1String(callgrindMinimumCostRatioC), m_minimumInclusiveCostRatio);
map.insert(QLatin1String(callgrindVisualisationMinimumCostRatioC),
m_visualisationMinimumInclusiveCostRatio);
}
void ValgrindBaseSettings::setValgrindExecutable(const QString &valgrindExecutable)
{
if (m_valgrindExecutable != valgrindExecutable) {
m_valgrindExecutable = valgrindExecutable;
emit valgrindExecutableChanged(valgrindExecutable);
}
}
void ValgrindBaseSettings::setSelfModifyingCodeDetection(int smcDetection)
{
if (m_selfModifyingCodeDetection != smcDetection) {
m_selfModifyingCodeDetection = (SelfModifyingCodeDetection) smcDetection;
emit selfModifyingCodeDetectionChanged(smcDetection);
}
}
QString ValgrindBaseSettings::valgrindExecutable() const
{
return m_valgrindExecutable;
}
ValgrindBaseSettings::SelfModifyingCodeDetection ValgrindBaseSettings::selfModifyingCodeDetection() const
{
return m_selfModifyingCodeDetection;
}
void ValgrindBaseSettings::setNumCallers(int numCallers)
{
if (m_numCallers != numCallers) {
m_numCallers = numCallers;
emit numCallersChanged(numCallers);
}
}
void ValgrindBaseSettings::setLeakCheckOnFinish(int leakCheckOnFinish)
{
if (m_leakCheckOnFinish != leakCheckOnFinish) {
m_leakCheckOnFinish = (LeakCheckOnFinish) leakCheckOnFinish;
emit leakCheckOnFinishChanged(leakCheckOnFinish);
}
}
void ValgrindBaseSettings::setShowReachable(bool showReachable)
{
if (m_showReachable != showReachable) {
m_showReachable = showReachable;
emit showReachableChanged(showReachable);
}
}
void ValgrindBaseSettings::setTrackOrigins(bool trackOrigins)
{
if (m_trackOrigins != trackOrigins) {
m_trackOrigins = trackOrigins;
emit trackOriginsChanged(trackOrigins);
}
}
void ValgrindBaseSettings::setFilterExternalIssues(bool filterExternalIssues)
{
if (m_filterExternalIssues != filterExternalIssues) {
m_filterExternalIssues = filterExternalIssues;
emit filterExternalIssuesChanged(filterExternalIssues);
}
}
void ValgrindBaseSettings::setVisibleErrorKinds(const QList<int> &visibleErrorKinds)
{
if (m_visibleErrorKinds != visibleErrorKinds) {
m_visibleErrorKinds = visibleErrorKinds;
emit visibleErrorKindsChanged(visibleErrorKinds);
}
}
void ValgrindBaseSettings::setEnableCacheSim(bool enable)
{
if (m_enableCacheSim == enable)
return;
m_enableCacheSim = enable;
emit enableCacheSimChanged(enable);
}
void ValgrindBaseSettings::setEnableBranchSim(bool enable)
{
if (m_enableBranchSim == enable)
return;
m_enableBranchSim = enable;
emit enableBranchSimChanged(enable);
}
void ValgrindBaseSettings::setCollectSystime(bool collect)
{
if (m_collectSystime == collect)
return;
m_collectSystime = collect;
emit collectSystimeChanged(collect);
}
void ValgrindBaseSettings::setCollectBusEvents(bool collect)
{
if (m_collectBusEvents == collect)
return;
m_collectBusEvents = collect;
emit collectBusEventsChanged(collect);
}
void ValgrindBaseSettings::setEnableEventToolTips(bool enable)
{
if (m_enableEventToolTips == enable)
return;
m_enableEventToolTips = enable;
emit enableEventToolTipsChanged(enable);
}
void ValgrindBaseSettings::setMinimumInclusiveCostRatio(
double minimumInclusiveCostRatio)
{
if (m_minimumInclusiveCostRatio == minimumInclusiveCostRatio)
return;
m_minimumInclusiveCostRatio = qBound(0.0, minimumInclusiveCostRatio, 100.0);
emit minimumInclusiveCostRatioChanged(minimumInclusiveCostRatio);
}
void ValgrindBaseSettings::setVisualisationMinimumInclusiveCostRatio(
double minimumInclusiveCostRatio)
{
if (m_visualisationMinimumInclusiveCostRatio == minimumInclusiveCostRatio)
return;
m_visualisationMinimumInclusiveCostRatio = qBound(0.0, minimumInclusiveCostRatio, 100.0);
emit visualisationMinimumInclusiveCostRatioChanged(minimumInclusiveCostRatio);
}
//////////////////////////////////////////////////////////////////
//
// ValgrindGlobalSettings
//
//////////////////////////////////////////////////////////////////
ValgrindGlobalSettings::ValgrindGlobalSettings()
{
readSettings();
}
QWidget *ValgrindGlobalSettings::createConfigWidget(QWidget *parent)
{
return new ValgrindConfigWidget(this, parent, true);
}
void ValgrindGlobalSettings::fromMap(const QVariantMap &map)
{
ValgrindBaseSettings::fromMap(map);
// Memcheck
m_suppressionFiles = map.value(QLatin1String(suppressionFilesC)).toStringList();
m_lastSuppressionDirectory = map.value(QLatin1String(lastSuppressionDirectoryC)).toString();
m_lastSuppressionHistory = map.value(QLatin1String(lastSuppressionHistoryC)).toStringList();
// Callgrind
// special code as the default one does not cope with the enum properly
if (map.contains(QLatin1String(callgrindCostFormatC)))
m_costFormat = static_cast<CostDelegate::CostFormat>(map.value(QLatin1String(callgrindCostFormatC)).toInt());
setIfPresent(map, QLatin1String(callgrindCycleDetectionC), &m_detectCycles);
setIfPresent(map, QLatin1String(callgrindShortenTemplates), &m_shortenTemplates);
}
void ValgrindGlobalSettings::toMap(QVariantMap &map) const
{
ValgrindBaseSettings::toMap(map);
// Memcheck
map.insert(QLatin1String(suppressionFilesC), m_suppressionFiles);
map.insert(QLatin1String(lastSuppressionDirectoryC), m_lastSuppressionDirectory);
map.insert(QLatin1String(lastSuppressionHistoryC), m_lastSuppressionHistory);
// Callgrind
map.insert(QLatin1String(callgrindCostFormatC), m_costFormat);
map.insert(QLatin1String(callgrindCycleDetectionC), m_detectCycles);
map.insert(QLatin1String(callgrindShortenTemplates), m_shortenTemplates);
}
//
// Memcheck
//
QStringList ValgrindGlobalSettings::suppressionFiles() const
{
return m_suppressionFiles;
}
void ValgrindGlobalSettings::addSuppressionFiles(const QStringList &suppressions)
{
foreach (const QString &s, suppressions)
if (!m_suppressionFiles.contains(s))
m_suppressionFiles.append(s);
}
void ValgrindGlobalSettings::removeSuppressionFiles(const QStringList &suppressions)
{
foreach (const QString &s, suppressions)
m_suppressionFiles.removeAll(s);
}
QString ValgrindGlobalSettings::lastSuppressionDialogDirectory() const
{
return m_lastSuppressionDirectory;
}
void ValgrindGlobalSettings::setLastSuppressionDialogDirectory(const QString &directory)
{
m_lastSuppressionDirectory = directory;
}
QStringList ValgrindGlobalSettings::lastSuppressionDialogHistory() const
{
return m_lastSuppressionHistory;
}
void ValgrindGlobalSettings::setLastSuppressionDialogHistory(const QStringList &history)
{
m_lastSuppressionHistory = history;
}
static const char groupC[] = "Analyzer";
void ValgrindGlobalSettings::readSettings()
{
QVariantMap defaults;
// General
defaults.insert(QLatin1String(valgrindExeC), QLatin1String("valgrind"));
defaults.insert(QLatin1String(selfModifyingCodeDetectionC), DetectSmcStackOnly);
// Memcheck
defaults.insert(QLatin1String(numCallersC), 25);
defaults.insert(QLatin1String(leakCheckOnFinishC), LeakCheckOnFinishSummaryOnly);
defaults.insert(QLatin1String(showReachableC), false);
defaults.insert(QLatin1String(trackOriginsC), true);
defaults.insert(QLatin1String(filterExternalIssuesC), true);
QVariantList defaultErrorKinds;
for (int i = 0; i < Valgrind::XmlProtocol::MemcheckErrorKindCount; ++i)
defaultErrorKinds << i;
defaults.insert(QLatin1String(visibleErrorKindsC), defaultErrorKinds);
defaults.insert(QLatin1String(suppressionFilesC), QStringList());
defaults.insert(QLatin1String(lastSuppressionDirectoryC), QString());
defaults.insert(QLatin1String(lastSuppressionHistoryC), QStringList());
// Callgrind
defaults.insert(QLatin1String(callgrindEnableCacheSimC), false);
defaults.insert(QLatin1String(callgrindEnableBranchSimC), false);
defaults.insert(QLatin1String(callgrindCollectSystimeC), false);
defaults.insert(QLatin1String(callgrindCollectBusEventsC), false);
defaults.insert(QLatin1String(callgrindEnableEventToolTipsC), true);
defaults.insert(QLatin1String(callgrindMinimumCostRatioC), 0.01);
defaults.insert(QLatin1String(callgrindVisualisationMinimumCostRatioC), 10.0);
defaults.insert(QLatin1String(callgrindCostFormatC), CostDelegate::FormatRelative);
defaults.insert(QLatin1String(callgrindCycleDetectionC), true);
// Read stored values
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(groupC));
QVariantMap map = defaults;
for (QVariantMap::ConstIterator it = defaults.constBegin(); it != defaults.constEnd(); ++it)
map.insert(it.key(), settings->value(it.key(), it.value()));
settings->endGroup();
fromMap(map);
}
void ValgrindGlobalSettings::writeSettings() const
{
QSettings *settings = Core::ICore::settings();
settings->beginGroup(QLatin1String(groupC));
QVariantMap map;
toMap(map);
for (QVariantMap::ConstIterator it = map.begin(); it != map.end(); ++it)
settings->setValue(it.key(), it.value());
settings->endGroup();
}
//
// Callgrind
//
CostDelegate::CostFormat ValgrindGlobalSettings::costFormat() const
{
return m_costFormat;
}
void ValgrindGlobalSettings::setCostFormat(CostDelegate::CostFormat format)
{
m_costFormat = format;
writeSettings();
}
bool ValgrindGlobalSettings::detectCycles() const
{
return m_detectCycles;
}
void ValgrindGlobalSettings::setDetectCycles(bool on)
{
m_detectCycles = on;
writeSettings();
}
bool ValgrindGlobalSettings::shortenTemplates() const
{
return m_shortenTemplates;
}
void ValgrindGlobalSettings::setShortenTemplates(bool on)
{
m_shortenTemplates = on;
writeSettings();
}
//////////////////////////////////////////////////////////////////
//
// ValgrindProjectSettings
//
//////////////////////////////////////////////////////////////////
QWidget *ValgrindProjectSettings::createConfigWidget(QWidget *parent)
{
return new ValgrindConfigWidget(this, parent, false);
}
void ValgrindProjectSettings::fromMap(const QVariantMap &map)
{
ValgrindBaseSettings::fromMap(map);
// Memcheck
setIfPresent(map, QLatin1String(addedSuppressionFilesC), &m_addedSuppressionFiles);
setIfPresent(map, QLatin1String(removedSuppressionFilesC), &m_disabledGlobalSuppressionFiles);
}
void ValgrindProjectSettings::toMap(QVariantMap &map) const
{
ValgrindBaseSettings::toMap(map);
// Memcheck
map.insert(QLatin1String(addedSuppressionFilesC), m_addedSuppressionFiles);
map.insert(QLatin1String(removedSuppressionFilesC), m_disabledGlobalSuppressionFiles);
}
//
// Memcheck
//
void ValgrindProjectSettings::addSuppressionFiles(const QStringList &suppressions)
{
QStringList globalSuppressions = ValgrindPlugin::globalSettings()->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 ValgrindProjectSettings::removeSuppressionFiles(const QStringList &suppressions)
{
QStringList globalSuppressions = ValgrindPlugin::globalSettings()->suppressionFiles();
foreach (const QString &s, suppressions) {
m_addedSuppressionFiles.removeAll(s);
if (globalSuppressions.contains(s))
m_disabledGlobalSuppressionFiles.append(s);
}
}
QStringList ValgrindProjectSettings::suppressionFiles() const
{
QStringList ret = ValgrindPlugin::globalSettings()->suppressionFiles();
foreach (const QString &s, m_disabledGlobalSuppressionFiles)
ret.removeAll(s);
ret.append(m_addedSuppressionFiles);
return ret;
}
} // namespace Internal
} // namespace Valgrind
|