tsan_report.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 suppressable = false;
  71. ReportStack *stack = nullptr;
  72. };
  73. struct ReportThread {
  74. Tid id;
  75. tid_t os_id;
  76. bool running;
  77. ThreadType thread_type;
  78. char *name;
  79. Tid parent_tid;
  80. ReportStack *stack;
  81. };
  82. struct ReportMutex {
  83. int id;
  84. uptr addr;
  85. ReportStack *stack;
  86. };
  87. class ReportDesc {
  88. public:
  89. ReportType typ;
  90. uptr tag;
  91. Vector<ReportStack*> stacks;
  92. Vector<ReportMop*> mops;
  93. Vector<ReportLocation*> locs;
  94. Vector<ReportMutex*> mutexes;
  95. Vector<ReportThread*> threads;
  96. Vector<Tid> 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