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
166d1862363c88c183b0ed7740fca876342cf0474bStephen Hines#include "sanitizer_common/sanitizer_symbolizer.h"
177ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "tsan_defs.h"
187ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "tsan_vector.h"
197ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
207ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanynamespace __tsan {
217ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
227ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyenum ReportType {
237ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportTypeRace,
240dc47b652dfbe0d61d153eded02bae9487a7b539Dmitry Vyukov  ReportTypeVptrRace,
25069ce828e3057819ee34426496ea7080f7cc52f0Dmitry Vyukov  ReportTypeUseAfterFree,
266d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  ReportTypeVptrUseAfterFree,
277ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportTypeThreadLeak,
287ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportTypeMutexDestroyLocked,
292d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  ReportTypeMutexDoubleLock,
30c58a43648cd6121c51a2e795a28e2ef90d7813e6Pirama Arumuga Nainar  ReportTypeMutexInvalidAccess,
312d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  ReportTypeMutexBadUnlock,
322d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  ReportTypeMutexBadReadLock,
332d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  ReportTypeMutexBadReadUnlock,
347ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportTypeSignalUnsafe,
352d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  ReportTypeErrnoInSignal,
362d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  ReportTypeDeadlock
377ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
387ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
397ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct ReportStack {
4086277eb844c4983c81de62d7c050e92fe7155788Stephen Hines  SymbolizedStack *frames;
416a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines  bool suppressable;
4286277eb844c4983c81de62d7c050e92fe7155788Stephen Hines  static ReportStack *New();
436d1862363c88c183b0ed7740fca876342cf0474bStephen Hines
446d1862363c88c183b0ed7740fca876342cf0474bStephen Hines private:
456d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  ReportStack();
467ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
477ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
48ad9da372f962495b3487685232d09390be841b1cDmitry Vyukovstruct ReportMopMutex {
49ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  u64 id;
50ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  bool write;
51ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov};
52ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov
537ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct ReportMop {
547ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int tid;
557ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  uptr addr;
567ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int size;
577ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  bool write;
580a07b354fe95d50911c620b42fc031868ef15cc1Dmitry Vyukov  bool atomic;
59ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  Vector<ReportMopMutex> mset;
607ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportStack *stack;
61ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov
62ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  ReportMop();
637ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
647ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
657ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyenum ReportLocationType {
667ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportLocationGlobal,
677ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportLocationHeap,
68c2234cd922bbd94e276e0bebb08004d63cbc5cf2Dmitry Vyukov  ReportLocationStack,
69fb917e9069ea44f7103f50c658be84a8f66de56cDmitry Vyukov  ReportLocationTLS,
70c2234cd922bbd94e276e0bebb08004d63cbc5cf2Dmitry Vyukov  ReportLocationFD
717ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
727ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
737ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct ReportLocation {
747ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportLocationType type;
756d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  DataInfo global;
766d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  uptr heap_chunk_start;
776d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  uptr heap_chunk_size;
787ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int tid;
79c2234cd922bbd94e276e0bebb08004d63cbc5cf2Dmitry Vyukov  int fd;
806a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines  bool suppressable;
817ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportStack *stack;
826d1862363c88c183b0ed7740fca876342cf0474bStephen Hines
836d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  static ReportLocation *New(ReportLocationType type);
846d1862363c88c183b0ed7740fca876342cf0474bStephen Hines private:
856d1862363c88c183b0ed7740fca876342cf0474bStephen Hines  explicit ReportLocation(ReportLocationType type);
867ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
877ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
887ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct ReportThread {
897ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  int id;
90c58a43648cd6121c51a2e795a28e2ef90d7813e6Pirama Arumuga Nainar  uptr os_id;
917ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  bool running;
927ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  char *name;
93da3503782901d30bd6e48885055b51b38cf5126cDmitry Vyukov  int parent_tid;
947ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportStack *stack;
957ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
967ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
977ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct ReportMutex {
98ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  u64 id;
992d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  uptr addr;
100ad9da372f962495b3487685232d09390be841b1cDmitry Vyukov  bool destroyed;
1017ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportStack *stack;
1027ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
1037ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1047ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyclass ReportDesc {
1057ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany public:
1067ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportType typ;
1077ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Vector<ReportStack*> stacks;
1087ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Vector<ReportMop*> mops;
1097ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Vector<ReportLocation*> locs;
1107ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Vector<ReportMutex*> mutexes;
1117ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  Vector<ReportThread*> threads;
1122d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  Vector<int> unique_tids;
113848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov  ReportStack *sleep;
1144536cb1fa7734133f404acb413589d7a6d314f4aDmitry Vyukov  int count;
1157ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1167ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportDesc();
1177ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ~ReportDesc();
1187ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1197ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany private:
1207ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ReportDesc(const ReportDesc&);
1217ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  void operator = (const ReportDesc&);
1227ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
1237ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1247ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// Format and output the report to the console/log. No additional logic.
1257ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyvoid PrintReport(const ReportDesc *rep);
1261da1056127d1dbcacdd035eb4149257848f7c4dfDmitry Vyukovvoid PrintStack(const ReportStack *stack);
1277ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1287ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany}  // namespace __tsan
1297ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1307ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#endif  // TSAN_REPORT_H
131