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