]>
Commit | Line | Data |
---|---|---|
cd0be65c WM |
1 | //===-- tsan_report.h -------------------------------------------*- C++ -*-===// |
2 | // | |
b667dd70 ML |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. | |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
cd0be65c WM |
6 | // |
7 | //===----------------------------------------------------------------------===// | |
8 | // | |
9 | // This file is a part of ThreadSanitizer (TSan), a race detector. | |
10 | // | |
11 | //===----------------------------------------------------------------------===// | |
12 | #ifndef TSAN_REPORT_H | |
13 | #define TSAN_REPORT_H | |
14 | ||
c5be964a | 15 | #include "sanitizer_common/sanitizer_symbolizer.h" |
b667dd70 | 16 | #include "sanitizer_common/sanitizer_thread_registry.h" |
eac97531 | 17 | #include "sanitizer_common/sanitizer_vector.h" |
cd0be65c | 18 | #include "tsan_defs.h" |
cd0be65c WM |
19 | |
20 | namespace __tsan { | |
21 | ||
22 | enum ReportType { | |
23 | ReportTypeRace, | |
ef1b3fda | 24 | ReportTypeVptrRace, |
cd0be65c | 25 | ReportTypeUseAfterFree, |
c5be964a | 26 | ReportTypeVptrUseAfterFree, |
5d3805fc | 27 | ReportTypeExternalRace, |
cd0be65c WM |
28 | ReportTypeThreadLeak, |
29 | ReportTypeMutexDestroyLocked, | |
dee5ea7a | 30 | ReportTypeMutexDoubleLock, |
10189819 | 31 | ReportTypeMutexInvalidAccess, |
dee5ea7a KS |
32 | ReportTypeMutexBadUnlock, |
33 | ReportTypeMutexBadReadLock, | |
34 | ReportTypeMutexBadReadUnlock, | |
cd0be65c | 35 | ReportTypeSignalUnsafe, |
dee5ea7a | 36 | ReportTypeErrnoInSignal, |
28219f7f JJ |
37 | ReportTypeDeadlock, |
38 | ReportTypeMutexHeldWrongContext | |
cd0be65c WM |
39 | }; |
40 | ||
41 | struct ReportStack { | |
76288e1c L |
42 | SymbolizedStack *frames = nullptr; |
43 | bool suppressable = false; | |
cd0be65c WM |
44 | }; |
45 | ||
e9772e16 | 46 | struct ReportMopMutex { |
f732bf6a | 47 | int id; |
e9772e16 KS |
48 | bool write; |
49 | }; | |
50 | ||
cd0be65c WM |
51 | struct ReportMop { |
52 | int tid; | |
53 | uptr addr; | |
54 | int size; | |
55 | bool write; | |
b4ab7d34 | 56 | bool atomic; |
5d3805fc | 57 | uptr external_tag; |
e9772e16 | 58 | Vector<ReportMopMutex> mset; |
cd0be65c | 59 | ReportStack *stack; |
e9772e16 KS |
60 | |
61 | ReportMop(); | |
cd0be65c WM |
62 | }; |
63 | ||
64 | enum ReportLocationType { | |
65 | ReportLocationGlobal, | |
66 | ReportLocationHeap, | |
e9772e16 | 67 | ReportLocationStack, |
2660d12d | 68 | ReportLocationTLS, |
e9772e16 | 69 | ReportLocationFD |
cd0be65c WM |
70 | }; |
71 | ||
72 | struct ReportLocation { | |
76288e1c L |
73 | ReportLocationType type = ReportLocationGlobal; |
74 | DataInfo global = {}; | |
75 | uptr heap_chunk_start = 0; | |
76 | uptr heap_chunk_size = 0; | |
77 | uptr external_tag = 0; | |
78 | Tid tid = kInvalidTid; | |
79 | int fd = 0; | |
600413c4 | 80 | bool fd_closed = false; |
76288e1c L |
81 | bool suppressable = false; |
82 | ReportStack *stack = nullptr; | |
cd0be65c WM |
83 | }; |
84 | ||
85 | struct ReportThread { | |
76288e1c | 86 | Tid id; |
5d3805fc | 87 | tid_t os_id; |
cd0be65c | 88 | bool running; |
b667dd70 | 89 | ThreadType thread_type; |
cd0be65c | 90 | char *name; |
76288e1c | 91 | Tid parent_tid; |
cd0be65c WM |
92 | ReportStack *stack; |
93 | }; | |
94 | ||
95 | struct ReportMutex { | |
f732bf6a | 96 | int id; |
dee5ea7a | 97 | uptr addr; |
cd0be65c WM |
98 | ReportStack *stack; |
99 | }; | |
100 | ||
101 | class ReportDesc { | |
102 | public: | |
103 | ReportType typ; | |
5d3805fc | 104 | uptr tag; |
cd0be65c WM |
105 | Vector<ReportStack*> stacks; |
106 | Vector<ReportMop*> mops; | |
107 | Vector<ReportLocation*> locs; | |
108 | Vector<ReportMutex*> mutexes; | |
109 | Vector<ReportThread*> threads; | |
76288e1c | 110 | Vector<Tid> unique_tids; |
cd0be65c | 111 | ReportStack *sleep; |
ef1b3fda | 112 | int count; |
f732bf6a | 113 | int signum = 0; |
cd0be65c WM |
114 | |
115 | ReportDesc(); | |
116 | ~ReportDesc(); | |
117 | ||
118 | private: | |
119 | ReportDesc(const ReportDesc&); | |
120 | void operator = (const ReportDesc&); | |
121 | }; | |
122 | ||
123 | // Format and output the report to the console/log. No additional logic. | |
124 | void PrintReport(const ReportDesc *rep); | |
125 | void PrintStack(const ReportStack *stack); | |
126 | ||
127 | } // namespace __tsan | |
128 | ||
129 | #endif // TSAN_REPORT_H |