libsanitizer merge from upstream r209283
[gcc.git] / libsanitizer / tsan / tsan_report.h
1 //===-- tsan_report.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 // This file is a part of ThreadSanitizer (TSan), a race detector.
9 //
10 //===----------------------------------------------------------------------===//
11 #ifndef TSAN_REPORT_H
12 #define TSAN_REPORT_H
13
14 #include "tsan_defs.h"
15 #include "tsan_vector.h"
16
17 namespace __tsan {
18
19 enum ReportType {
20 ReportTypeRace,
21 ReportTypeVptrRace,
22 ReportTypeUseAfterFree,
23 ReportTypeThreadLeak,
24 ReportTypeMutexDestroyLocked,
25 ReportTypeMutexDoubleLock,
26 ReportTypeMutexBadUnlock,
27 ReportTypeMutexBadReadLock,
28 ReportTypeMutexBadReadUnlock,
29 ReportTypeSignalUnsafe,
30 ReportTypeErrnoInSignal,
31 ReportTypeDeadlock
32 };
33
34 struct ReportStack {
35 ReportStack *next;
36 char *module;
37 uptr offset;
38 uptr pc;
39 char *func;
40 char *file;
41 int line;
42 int col;
43 };
44
45 struct ReportMopMutex {
46 u64 id;
47 bool write;
48 };
49
50 struct ReportMop {
51 int tid;
52 uptr addr;
53 int size;
54 bool write;
55 bool atomic;
56 Vector<ReportMopMutex> mset;
57 ReportStack *stack;
58
59 ReportMop();
60 };
61
62 enum ReportLocationType {
63 ReportLocationGlobal,
64 ReportLocationHeap,
65 ReportLocationStack,
66 ReportLocationTLS,
67 ReportLocationFD
68 };
69
70 struct ReportLocation {
71 ReportLocationType type;
72 uptr addr;
73 uptr size;
74 char *module;
75 uptr offset;
76 int tid;
77 int fd;
78 char *name;
79 char *file;
80 int line;
81 ReportStack *stack;
82 };
83
84 struct ReportThread {
85 int id;
86 uptr pid;
87 bool running;
88 char *name;
89 int parent_tid;
90 ReportStack *stack;
91 };
92
93 struct ReportMutex {
94 u64 id;
95 uptr addr;
96 bool destroyed;
97 ReportStack *stack;
98 };
99
100 class ReportDesc {
101 public:
102 ReportType typ;
103 Vector<ReportStack*> stacks;
104 Vector<ReportMop*> mops;
105 Vector<ReportLocation*> locs;
106 Vector<ReportMutex*> mutexes;
107 Vector<ReportThread*> threads;
108 Vector<int> unique_tids;
109 ReportStack *sleep;
110 int count;
111
112 ReportDesc();
113 ~ReportDesc();
114
115 private:
116 ReportDesc(const ReportDesc&);
117 void operator = (const ReportDesc&);
118 };
119
120 // Format and output the report to the console/log. No additional logic.
121 void PrintReport(const ReportDesc *rep);
122 void PrintStack(const ReportStack *stack);
123
124 } // namespace __tsan
125
126 #endif // TSAN_REPORT_H