1 //===-- tsan_trace.h --------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file is a part of ThreadSanitizer (TSan), a race detector. 11 // 12 //===----------------------------------------------------------------------===// 13 #ifndef TSAN_TRACE_H 14 #define TSAN_TRACE_H 15 16 #include "tsan_defs.h" 17 #include "tsan_mutex.h" 18 #include "tsan_sync.h" 19 20 namespace __tsan { 21 22 #ifndef TSAN_HISTORY_SIZE // in kibitraces 23 #define TSAN_HISTORY_SIZE 128 24 #endif 25 26 const int kTracePartSize = 16 * 1024; 27 const int kTraceParts = TSAN_HISTORY_SIZE * 1024 / kTracePartSize; 28 const int kTraceSize = kTracePartSize * kTraceParts; 29 30 // Must fit into 3 bits. 31 enum EventType { 32 EventTypeMop, 33 EventTypeFuncEnter, 34 EventTypeFuncExit, 35 EventTypeLock, 36 EventTypeUnlock, 37 EventTypeRLock, 38 EventTypeRUnlock, 39 }; 40 41 // Represents a thread event (from most significant bit): 42 // u64 typ : 3; // EventType. 43 // u64 addr : 61; // Associated pc. 44 typedef u64 Event; 45 46 struct TraceHeader { 47 StackTrace stack0; // Start stack for the trace. 48 u64 epoch0; // Start epoch for the trace. 49 #ifndef TSAN_GO 50 uptr stack0buf[kTraceStackSize]; 51 #endif 52 TraceHeaderTraceHeader53 TraceHeader() 54 #ifndef TSAN_GO 55 : stack0(stack0buf, kTraceStackSize) 56 #else 57 : stack0() 58 #endif 59 , epoch0() { 60 } 61 }; 62 63 struct Trace { 64 Event events[kTraceSize]; 65 TraceHeader headers[kTraceParts]; 66 Mutex mtx; 67 TraceTrace68 Trace() 69 : mtx(MutexTypeTrace, StatMtxTrace) { 70 } 71 }; 72 73 } // namespace __tsan 74 75 #endif // TSAN_TRACE_H 76