17ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===-- tsan_report.h -------------------------------------------*- C++ -*-===//
27ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//
37ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//                     The LLVM Compiler Infrastructure
47ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//
57ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// This file is distributed under the University of Illinois Open Source
67ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// License. See LICENSE.TXT for details.
77ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//
87ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===----------------------------------------------------------------------===//
97ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//
107ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// This file is a part of ThreadSanitizer (TSan), a race detector.
117ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//
127ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===----------------------------------------------------------------------===//
137ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#ifndef TSAN_REPORT_H
147ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#define TSAN_REPORT_H
157ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
167ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "tsan_defs.h"
177ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "tsan_vector.h"
187ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
197ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanynamespace __tsan {
207ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
217ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyenum ReportType {
227ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportTypeRace,
230dc47b652dfbe0d61d153eded02bae9487a7b539Dmitry Vyukov  ReportTypeVptrRace,
24069ce828e3057819ee34426496ea7080f7cc52f0Dmitry Vyukov  ReportTypeUseAfterFree,
257ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportTypeThreadLeak,
267ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportTypeMutexDestroyLocked,
277ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportTypeSignalUnsafe,
282135d8a7f4ba30fe35ed02d5e6ffd59a95b26219Alexey Samsonov  ReportTypeErrnoInSignal
297ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
307ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
317ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct ReportStack {
327ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportStack *next;
337ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  char *module;
347ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  uptr offset;
357ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  uptr pc;
367ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  char *func;
377ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  char *file;
387ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int line;
397ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int col;
407ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
417ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
42ad9da372f962495b3487685232d09390be841b1cDmitry Vyukovstruct ReportMopMutex {
43ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  u64 id;
44ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  bool write;
45ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov};
46ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov
477ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct ReportMop {
487ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int tid;
497ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  uptr addr;
507ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int size;
517ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  bool write;
520a07b354fe95d50911c620b42fc031868ef15cc1Dmitry Vyukov  bool atomic;
53ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  Vector<ReportMopMutex> mset;
547ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportStack *stack;
55ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov
56ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  ReportMop();
577ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
587ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
597ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyenum ReportLocationType {
607ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportLocationGlobal,
617ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportLocationHeap,
62c2234cd922bbd94e276e0bebb08004d63cbc5cf2Dmitry Vyukov  ReportLocationStack,
63fb917e9069ea44f7103f50c658be84a8f66de56cDmitry Vyukov  ReportLocationTLS,
64c2234cd922bbd94e276e0bebb08004d63cbc5cf2Dmitry Vyukov  ReportLocationFD
657ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
667ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
677ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct ReportLocation {
687ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportLocationType type;
697ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  uptr addr;
707ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  uptr size;
71433c219f8772c35dc4e6bd32bb4131dbc07fdfd6Dmitry Vyukov  char *module;
72433c219f8772c35dc4e6bd32bb4131dbc07fdfd6Dmitry Vyukov  uptr offset;
737ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int tid;
74c2234cd922bbd94e276e0bebb08004d63cbc5cf2Dmitry Vyukov  int fd;
757ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  char *name;
767ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  char *file;
777ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int line;
787ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportStack *stack;
797ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
807ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
817ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct ReportThread {
827ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int id;
83e0023f74ea88efee329f68391b70f8adc6b21617Dmitry Vyukov  uptr pid;
847ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  bool running;
857ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  char *name;
86da3503782901d30bd6e48885055b51b38cf5126cDmitry Vyukov  int parent_tid;
877ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportStack *stack;
887ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
897ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
907ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct ReportMutex {
91ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  u64 id;
92ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  bool destroyed;
937ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportStack *stack;
947ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
957ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
967ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyclass ReportDesc {
977ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany public:
987ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportType typ;
997ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Vector<ReportStack*> stacks;
1007ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Vector<ReportMop*> mops;
1017ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Vector<ReportLocation*> locs;
1027ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Vector<ReportMutex*> mutexes;
1037ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Vector<ReportThread*> threads;
104848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov  ReportStack *sleep;
1054536cb1fa7734133f404acb413589d7a6d314f4aDmitry Vyukov  int count;
1067ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1077ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportDesc();
1087ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ~ReportDesc();
1097ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1107ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany private:
1117ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportDesc(const ReportDesc&);
1127ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  void operator = (const ReportDesc&);
1137ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
1147ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1157ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// Format and output the report to the console/log. No additional logic.
1167ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyvoid PrintReport(const ReportDesc *rep);
1171da1056127d1dbcacdd035eb4149257848f7c4dfDmitry Vyukovvoid PrintStack(const ReportStack *stack);
1187ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1197ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany}  // namespace __tsan
1207ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1217ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#endif  // TSAN_REPORT_H
122