• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- tsan_report.h -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef TSAN_REPORT_H
14 #define TSAN_REPORT_H
15 
16 #include "tsan_defs.h"
17 #include "tsan_vector.h"
18 
19 namespace __tsan {
20 
21 enum ReportType {
22   ReportTypeRace,
23   ReportTypeUseAfterFree,
24   ReportTypeThreadLeak,
25   ReportTypeMutexDestroyLocked,
26   ReportTypeSignalUnsafe,
27   ReportTypeErrnoInSignal
28 };
29 
30 struct ReportStack {
31   ReportStack *next;
32   char *module;
33   uptr offset;
34   uptr pc;
35   char *func;
36   char *file;
37   int line;
38   int col;
39 };
40 
41 struct ReportMopMutex {
42   u64 id;
43   bool write;
44 };
45 
46 struct ReportMop {
47   int tid;
48   uptr addr;
49   int size;
50   bool write;
51   bool atomic;
52   Vector<ReportMopMutex> mset;
53   ReportStack *stack;
54 
55   ReportMop();
56 };
57 
58 enum ReportLocationType {
59   ReportLocationGlobal,
60   ReportLocationHeap,
61   ReportLocationStack,
62   ReportLocationTLS,
63   ReportLocationFD
64 };
65 
66 struct ReportLocation {
67   ReportLocationType type;
68   uptr addr;
69   uptr size;
70   char *module;
71   uptr offset;
72   int tid;
73   int fd;
74   char *name;
75   char *file;
76   int line;
77   ReportStack *stack;
78 };
79 
80 struct ReportThread {
81   int id;
82   uptr pid;
83   bool running;
84   char *name;
85   int parent_tid;
86   ReportStack *stack;
87 };
88 
89 struct ReportMutex {
90   u64 id;
91   bool destroyed;
92   ReportStack *stack;
93 };
94 
95 class ReportDesc {
96  public:
97   ReportType typ;
98   Vector<ReportStack*> stacks;
99   Vector<ReportMop*> mops;
100   Vector<ReportLocation*> locs;
101   Vector<ReportMutex*> mutexes;
102   Vector<ReportThread*> threads;
103   ReportStack *sleep;
104 
105   ReportDesc();
106   ~ReportDesc();
107 
108  private:
109   ReportDesc(const ReportDesc&);
110   void operator = (const ReportDesc&);
111 };
112 
113 // Format and output the report to the console/log. No additional logic.
114 void PrintReport(const ReportDesc *rep);
115 void PrintStack(const ReportStack *stack);
116 
117 }  // namespace __tsan
118 
119 #endif  // TSAN_REPORT_H
120