1 /* Copyright (c) 2008-2010, Google Inc. 2 * All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Neither the name of Google Inc. nor the names of its 11 * contributors may be used to endorse or promote products derived from 12 * this software without specific prior written permission. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 // This file is part of ThreadSanitizer, a dynamic data race detector. 28 // Author: Konstantin Serebryany. 29 // Author: Timur Iskhodzhanov. 30 31 #ifndef TS_EVENTS_H_ 32 #define TS_EVENTS_H_ 33 34 // Each event contains tid (the id of the current thread). 35 // Most events contain pc (the program counter). 36 // Some events contain: 37 // * addr, a memory address, a lock address, etc 38 // * size of a memory range 39 // Few events contain a string (e.g. SET_THREAD_NAME). 40 41 enum EventType { 42 NOOP, // Should not appear. 43 READ, // {tid, pc, addr, size} 44 WRITE, // {tid, pc, addr, size} 45 READER_LOCK, // {tid, pc, lock, 0} 46 WRITER_LOCK, // {tid, pc, lock, 0} 47 UNLOCK, // {tid, pc, lock, 0} 48 UNLOCK_OR_INIT, // {tid, pc, lock, 0} 49 LOCK_CREATE, // {tid, pc, lock, 0} 50 LOCK_DESTROY, // {tid, pc, lock, 0} 51 THR_CREATE_BEFORE, // Parent thread's event. {tid, pc, 0, 0} 52 THR_CREATE_AFTER, // Parent thread's event. {tid, 0, 0, child_tid} 53 THR_START, // Child thread's event {tid, CallStack, 0, parent_tid} 54 THR_FIRST_INSN, // Used only by valgrind. 55 THR_END, // {tid, 0, 0, 0} 56 THR_JOIN_AFTER, // {tid, pc, joined_tid} 57 THR_STACK_TOP, // {tid, pc, stack_top, stack_size_if_known} 58 RTN_EXIT, // {tid, 0, 0, 0} 59 RTN_CALL, // {tid, pc, 0, 0} 60 SBLOCK_ENTER, // {tid, pc, 0, 0} 61 SIGNAL, // {tid, pc, obj, 0} 62 WAIT, // {tid, pc, obj, 0} 63 CYCLIC_BARRIER_INIT, // {tid, pc, obj, n} 64 CYCLIC_BARRIER_WAIT_BEFORE, // {tid, pc, obj, 0} 65 CYCLIC_BARRIER_WAIT_AFTER, // {tid, pc, obj, 0} 66 PCQ_CREATE, // {tid, pc, pcq_addr, 0} 67 PCQ_DESTROY, // {tid, pc, pcq_addr, 0} 68 PCQ_PUT, // {tid, pc, pcq_addr, 0} 69 PCQ_GET, // {tid, pc, pcq_addr, 0} 70 STACK_MEM_DIE, // deprecated. 71 MALLOC, // {tid, pc, addr, size} 72 FREE, // {tid, pc, addr, 0} 73 MMAP, // {tid, pc, addr, size} 74 MUNMAP, // {tid, pc, addr, size} 75 PUBLISH_RANGE, // may be deprecated later. 76 UNPUBLISH_RANGE, // deprecated. TODO(kcc): get rid of this. 77 HB_LOCK, // {tid, pc, addr, 0} 78 NON_HB_LOCK, // {tid, pc, addr, 0} 79 IGNORE_READS_BEG, // {tid, pc, 0, 0} 80 IGNORE_READS_END, // {tid, pc, 0, 0} 81 IGNORE_WRITES_BEG, // {tid, pc, 0, 0} 82 IGNORE_WRITES_END, // {tid, pc, 0, 0} 83 SET_THREAD_NAME, // {tid, pc, name_str, 0} 84 SET_LOCK_NAME, // {tid, pc, lock, lock_name_str} 85 TRACE_MEM, // {tid, pc, addr, 0} 86 EXPECT_RACE, // {tid, descr_str, ptr, size} 87 BENIGN_RACE, // {tid, descr_str, ptr, size} 88 EXPECT_RACE_BEGIN, // {tid, pc, 0, 0} 89 EXPECT_RACE_END, // {tid, pc, 0, 0} 90 VERBOSITY, // Used for debugging. 91 STACK_TRACE, // {tid, pc, 0, 0}, for debugging. 92 FLUSH_STATE, // {tid, pc, 0, 0} 93 PC_DESCRIPTION, // {0, pc, descr_str, 0}, for ts_offline. 94 PRINT_MESSAGE, // {tid, pc, message_str, 0}, for ts_offline. 95 FLUSH_EXPECTED_RACES, // {0, 0, 0, 0} 96 LAST_EVENT // Should not appear. 97 }; 98 99 #include "ts_event_names.h" // generated from this file by sed. 100 101 class Event { 102 public: 103 Event(EventType type, int32_t tid, uintptr_t pc, uintptr_t a, uintptr_t info) 104 : type_(type), 105 tid_(tid), 106 pc_(pc), 107 a_(a), 108 info_(info) { 109 } 110 Event() {} // Not initialized. 111 112 void Init(EventType type, int32_t tid, uintptr_t pc, uintptr_t a, uintptr_t info) { 113 type_ = type; 114 tid_ = tid; 115 pc_ = pc; 116 a_ = a; 117 info_ = info; 118 } 119 120 121 EventType type() const { return type_; } 122 int32_t tid() const { return tid_; } 123 uintptr_t a() const { return a_; } 124 uintptr_t pc() const { return pc_; } 125 uintptr_t info() const { return info_; } 126 void Print() const { 127 Printf("T%d: %s [pc=%p; a=%p; i=%p]\n", 128 tid(), TypeString(type()), pc(), a(), info()); 129 130 } 131 static const char *TypeString(EventType type) { 132 return kEventNames[type]; 133 } 134 private: 135 EventType type_; 136 int32_t tid_; 137 uintptr_t pc_; 138 uintptr_t a_; 139 uintptr_t info_; 140 }; 141 142 143 // end. {{{1 144 #endif // TS_EVENTS_H_ 145 // vim:shiftwidth=2:softtabstop=2:expandtab:tw=80 146