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