tsan_report.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. ReportTypeMutexHeldWrongContext
  36. };
  37. struct ReportStack {
  38. SymbolizedStack *frames = nullptr;
  39. bool suppressable = false;
  40. };
  41. struct ReportMopMutex {
  42. int id;
  43. bool write;
  44. };
  45. struct ReportMop {
  46. int tid;
  47. uptr addr;
  48. int size;
  49. bool write;
  50. bool atomic;
  51. uptr external_tag;
  52. Vector<ReportMopMutex> mset;
  53. ReportStack *stack;
  54. ReportMop();
  55. };
  56. enum ReportLocationType {
  57. ReportLocationGlobal,
  58. ReportLocationHeap,
  59. ReportLocationStack,
  60. ReportLocationTLS,
  61. ReportLocationFD
  62. };
  63. struct ReportLocation {
  64. ReportLocationType type = ReportLocationGlobal;
  65. DataInfo global = {};
  66. uptr heap_chunk_start = 0;
  67. uptr heap_chunk_size = 0;
  68. uptr external_tag = 0;
  69. Tid tid = kInvalidTid;
  70. int fd = 0;
  71. bool fd_closed = false;
  72. bool suppressable = false;
  73. ReportStack *stack = nullptr;
  74. };
  75. struct ReportThread {
  76. Tid id;
  77. tid_t os_id;
  78. bool running;
  79. ThreadType thread_type;
  80. char *name;
  81. Tid parent_tid;
  82. ReportStack *stack;
  83. };
  84. struct ReportMutex {
  85. int id;
  86. uptr addr;
  87. ReportStack *stack;
  88. };
  89. class ReportDesc {
  90. public:
  91. ReportType typ;
  92. uptr tag;
  93. Vector<ReportStack*> stacks;
  94. Vector<ReportMop*> mops;
  95. Vector<ReportLocation*> locs;
  96. Vector<ReportMutex*> mutexes;
  97. Vector<ReportThread*> threads;
  98. Vector<Tid> unique_tids;
  99. ReportStack *sleep;
  100. int count;
  101. int signum = 0;
  102. ReportDesc();
  103. ~ReportDesc();
  104. private:
  105. ReportDesc(const ReportDesc&);
  106. void operator = (const ReportDesc&);
  107. };
  108. // Format and output the report to the console/log. No additional logic.
  109. void PrintReport(const ReportDesc *rep);
  110. void PrintStack(const ReportStack *stack);
  111. } // namespace __tsan
  112. #endif // TSAN_REPORT_H