1145937Sglebius//===-- tsan_report.h -------------------------------------------*- C++ -*-===//
2145937Sglebius//
3145937Sglebius//                     The LLVM Compiler Infrastructure
4145937Sglebius//
5145937Sglebius// This file is distributed under the University of Illinois Open Source
6145937Sglebius// License. See LICENSE.TXT for details.
7145937Sglebius//
8145937Sglebius//===----------------------------------------------------------------------===//
9145937Sglebius//
10145937Sglebius// This file is a part of ThreadSanitizer (TSan), a race detector.
11145937Sglebius//
12145937Sglebius//===----------------------------------------------------------------------===//
13145937Sglebius#ifndef TSAN_REPORT_H
14145937Sglebius#define TSAN_REPORT_H
15145937Sglebius
16145937Sglebius#include "sanitizer_common/sanitizer_symbolizer.h"
17145937Sglebius#include "sanitizer_common/sanitizer_vector.h"
18145937Sglebius#include "tsan_defs.h"
19145937Sglebius
20145937Sglebiusnamespace __tsan {
21145937Sglebius
22145937Sglebiusenum ReportType {
23145937Sglebius  ReportTypeRace,
24145937Sglebius  ReportTypeVptrRace,
25145937Sglebius  ReportTypeUseAfterFree,
26145937Sglebius  ReportTypeVptrUseAfterFree,
27145937Sglebius  ReportTypeExternalRace,
28145937Sglebius  ReportTypeThreadLeak,
29145937Sglebius  ReportTypeMutexDestroyLocked,
30145937Sglebius  ReportTypeMutexDoubleLock,
31145937Sglebius  ReportTypeMutexInvalidAccess,
32145937Sglebius  ReportTypeMutexBadUnlock,
33145937Sglebius  ReportTypeMutexBadReadLock,
34145937Sglebius  ReportTypeMutexBadReadUnlock,
35145937Sglebius  ReportTypeSignalUnsafe,
36145937Sglebius  ReportTypeErrnoInSignal,
37145937Sglebius  ReportTypeDeadlock
38};
39
40struct ReportStack {
41  SymbolizedStack *frames;
42  bool suppressable;
43  static ReportStack *New();
44
45 private:
46  ReportStack();
47};
48
49struct ReportMopMutex {
50  u64 id;
51  bool write;
52};
53
54struct ReportMop {
55  int tid;
56  uptr addr;
57  int size;
58  bool write;
59  bool atomic;
60  uptr external_tag;
61  Vector<ReportMopMutex> mset;
62  ReportStack *stack;
63
64  ReportMop();
65};
66
67enum ReportLocationType {
68  ReportLocationGlobal,
69  ReportLocationHeap,
70  ReportLocationStack,
71  ReportLocationTLS,
72  ReportLocationFD
73};
74
75struct ReportLocation {
76  ReportLocationType type;
77  DataInfo global;
78  uptr heap_chunk_start;
79  uptr heap_chunk_size;
80  uptr external_tag;
81  int tid;
82  int fd;
83  bool suppressable;
84  ReportStack *stack;
85
86  static ReportLocation *New(ReportLocationType type);
87 private:
88  explicit ReportLocation(ReportLocationType type);
89};
90
91struct ReportThread {
92  int id;
93  tid_t os_id;
94  bool running;
95  bool workerthread;
96  char *name;
97  u32 parent_tid;
98  ReportStack *stack;
99};
100
101struct ReportMutex {
102  u64 id;
103  uptr addr;
104  bool destroyed;
105  ReportStack *stack;
106};
107
108class ReportDesc {
109 public:
110  ReportType typ;
111  uptr tag;
112  Vector<ReportStack*> stacks;
113  Vector<ReportMop*> mops;
114  Vector<ReportLocation*> locs;
115  Vector<ReportMutex*> mutexes;
116  Vector<ReportThread*> threads;
117  Vector<int> unique_tids;
118  ReportStack *sleep;
119  int count;
120
121  ReportDesc();
122  ~ReportDesc();
123
124 private:
125  ReportDesc(const ReportDesc&);
126  void operator = (const ReportDesc&);
127};
128
129// Format and output the report to the console/log. No additional logic.
130void PrintReport(const ReportDesc *rep);
131void PrintStack(const ReportStack *stack);
132
133}  // namespace __tsan
134
135#endif  // TSAN_REPORT_H
136