tsan_report.h 2.5 KB

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