tsan_report.h 2.7 KB

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