tsan_trace.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //===-- tsan_trace.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_TRACE_H
  12. #define TSAN_TRACE_H
  13. #include "tsan_defs.h"
  14. #include "tsan_mutex.h"
  15. #include "tsan_stack_trace.h"
  16. #include "tsan_mutexset.h"
  17. namespace __tsan {
  18. const int kTracePartSizeBits = 14;
  19. const int kTracePartSize = 1 << kTracePartSizeBits;
  20. const int kTraceParts = 4 * 1024 * 1024 / kTracePartSize;
  21. const int kTraceSize = kTracePartSize * kTraceParts;
  22. // Must fit into 3 bits.
  23. enum EventType {
  24. EventTypeMop,
  25. EventTypeFuncEnter,
  26. EventTypeFuncExit,
  27. EventTypeLock,
  28. EventTypeUnlock,
  29. EventTypeRLock,
  30. EventTypeRUnlock
  31. };
  32. // Represents a thread event (from most significant bit):
  33. // u64 typ : 3; // EventType.
  34. // u64 addr : 61; // Associated pc.
  35. typedef u64 Event;
  36. struct TraceHeader {
  37. #ifndef TSAN_GO
  38. BufferedStackTrace stack0; // Start stack for the trace.
  39. #else
  40. VarSizeStackTrace stack0;
  41. #endif
  42. u64 epoch0; // Start epoch for the trace.
  43. MutexSet mset0;
  44. TraceHeader() : stack0(), epoch0() {}
  45. };
  46. struct Trace {
  47. TraceHeader headers[kTraceParts];
  48. Mutex mtx;
  49. #ifndef TSAN_GO
  50. // Must be last to catch overflow as paging fault.
  51. // Go shadow stack is dynamically allocated.
  52. uptr shadow_stack[kShadowStackSize];
  53. #endif
  54. Trace()
  55. : mtx(MutexTypeTrace, StatMtxTrace) {
  56. }
  57. };
  58. } // namespace __tsan
  59. #endif // TSAN_TRACE_H