sanitizer_suppressions.h revision 1.1
1//===-- sanitizer_suppressions.h --------------------------------*- C++ -*-===//
2//
3// This file is distributed under the University of Illinois Open Source
4// License. See LICENSE.TXT for details.
5//
6//===----------------------------------------------------------------------===//
7//
8// Suppression parsing/matching code shared between TSan and LSan.
9//
10//===----------------------------------------------------------------------===//
11#ifndef SANITIZER_SUPPRESSIONS_H
12#define SANITIZER_SUPPRESSIONS_H
13
14#include "sanitizer_common.h"
15#include "sanitizer_internal_defs.h"
16
17namespace __sanitizer {
18
19enum SuppressionType {
20  SuppressionNone,
21  SuppressionRace,
22  SuppressionMutex,
23  SuppressionThread,
24  SuppressionSignal,
25  SuppressionLeak,
26  SuppressionLib,
27  SuppressionDeadlock,
28  SuppressionVptrCheck,
29  SuppressionTypeCount
30};
31
32struct Suppression {
33  SuppressionType type;
34  char *templ;
35  unsigned hit_count;
36  uptr weight;
37};
38
39class SuppressionContext {
40 public:
41  void Parse(const char *str);
42  bool Match(const char* str, SuppressionType type, Suppression **s);
43  uptr SuppressionCount() const;
44  const Suppression *SuppressionAt(uptr i) const;
45  void GetMatched(InternalMmapVector<Suppression *> *matched);
46
47  // Create a SuppressionContext singleton if it hasn't been created earlier.
48  // Not thread safe. Must be called early during initialization (but after
49  // runtime flags are parsed).
50  static void InitIfNecessary();
51  // Returns a SuppressionContext singleton.
52  static SuppressionContext *Get();
53
54 private:
55  SuppressionContext() : suppressions_(1), can_parse_(true) {}
56  InternalMmapVector<Suppression> suppressions_;
57  bool can_parse_;
58
59  friend class SuppressionContextTest;
60};
61
62const char *SuppressionTypeString(SuppressionType t);
63
64bool TemplateMatch(char *templ, const char *str);
65
66}  // namespace __sanitizer
67
68#endif  // SANITIZER_SUPPRESSIONS_H
69