1 /* 2 This file is part of drd, a thread error detector. 3 4 Copyright (C) 2006-2013 Bart Van Assche <bvanassche@acm.org>. 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License as 8 published by the Free Software Foundation; either version 2 of the 9 License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 02111-1307, USA. 20 21 The GNU General Public License is contained in the file COPYING. 22 */ 23 24 25 #ifndef __DRD_ERROR_H 26 #define __DRD_ERROR_H 27 28 29 #include "pub_drd_bitmap.h" // BmAccessTypeT 30 #include "drd_thread.h" // DrdThreadId 31 #include "pub_tool_basics.h" // SizeT 32 #include "pub_tool_debuginfo.h" // SegInfo 33 #include "pub_tool_errormgr.h" // ExeContext 34 35 36 /* DRD error types. */ 37 38 typedef enum { 39 #define STR_DataRaceErr "ConflictingAccess" 40 DataRaceErr = 1, 41 #define STR_MutexErr "MutexErr" 42 MutexErr = 2, 43 #define STR_CondErr "CondErr" 44 CondErr = 3, 45 #define STR_CondDestrErr "CondDestrErr" 46 CondDestrErr = 4, 47 #define STR_CondRaceErr "CondRaceErr" 48 CondRaceErr = 5, 49 #define STR_CondWaitErr "CondWaitErr" 50 CondWaitErr = 6, 51 #define STR_SemaphoreErr "SemaphoreErr" 52 SemaphoreErr = 7, 53 #define STR_BarrierErr "BarrierErr" 54 BarrierErr = 8, 55 #define STR_RwlockErr "RwlockErr" 56 RwlockErr = 9, 57 #define STR_HoldtimeErr "HoldtimeErr" 58 HoldtimeErr = 10, 59 #define STR_GenericErr "GenericErr" 60 GenericErr = 11, 61 #define STR_InvalidThreadId "InvalidThreadId" 62 InvalidThreadId = 12, 63 #define STR_UnimpHgClReq "UnimpHgClReq" 64 UnimpHgClReq = 13, 65 #define STR_UnimpDrdClReq "UnimpDrdClReq" 66 UnimpDrdClReq = 14, 67 } DrdErrorKind; 68 69 /* The classification of a faulting address. */ 70 typedef 71 enum { 72 //Undescribed, // as-yet unclassified 73 eStack, 74 eUnknown, // classification yielded nothing useful 75 //Freed, 76 eMallocd, 77 eSegment, // in a segment (as defined in pub_tool_debuginfo.h) 78 //UserG, // in a user-defined block 79 //Mempool, // in a mempool 80 //Register, // in a register; for Param errors only 81 } 82 AddrKind; 83 84 /* Records info about a faulting address. */ 85 typedef 86 struct { // Used by: 87 AddrKind akind; // ALL 88 SizeT size; // ALL 89 PtrdiffT rwoffset; // ALL 90 ExeContext* lastchange; // Mallocd 91 DrdThreadId stack_tid; // Stack 92 DebugInfo* debuginfo; // Segment 93 HChar name[256]; // Segment 94 HChar descr[256]; // Segment 95 } AddrInfo; 96 97 /* 98 * NOTE: the first member of each error info structure MUST be the thread ID 99 * in which the error has been observed. 100 */ 101 typedef struct { 102 DrdThreadId tid; // Thread ID of the running thread. 103 Addr addr; // Conflicting address in current thread. 104 SizeT size; // Size in bytes of conflicting operation. 105 BmAccessTypeT access_type; // Access type: load or store. 106 } DataRaceErrInfo; 107 108 typedef struct { 109 DrdThreadId tid; 110 Addr mutex; 111 Int recursion_count; 112 DrdThreadId owner; 113 } MutexErrInfo; 114 115 typedef struct { 116 DrdThreadId tid; 117 Addr cond; 118 } CondErrInfo; 119 120 typedef struct { 121 DrdThreadId tid; 122 Addr cond; 123 Addr mutex; 124 DrdThreadId owner; 125 } CondDestrErrInfo; 126 127 typedef struct { 128 DrdThreadId tid; 129 Addr cond; 130 Addr mutex; 131 } CondRaceErrInfo; 132 133 typedef struct { 134 DrdThreadId tid; 135 Addr cond; 136 Addr mutex1; 137 Addr mutex2; 138 } CondWaitErrInfo; 139 140 typedef struct { 141 DrdThreadId tid; 142 Addr semaphore; 143 } SemaphoreErrInfo; 144 145 typedef struct { 146 DrdThreadId tid; 147 Addr barrier; 148 DrdThreadId other_tid; 149 ExeContext* other_context; 150 } BarrierErrInfo; 151 152 typedef struct { 153 DrdThreadId tid; 154 Addr rwlock; 155 } RwlockErrInfo; 156 157 typedef struct { 158 DrdThreadId tid; 159 Addr synchronization_object; 160 ExeContext* acquired_at; 161 UInt hold_time_ms; 162 UInt threshold_ms; 163 } HoldtimeErrInfo; 164 165 typedef struct { 166 DrdThreadId tid; 167 Addr addr; 168 } GenericErrInfo; 169 170 typedef struct { 171 DrdThreadId tid; 172 ULong ptid; 173 } InvalidThreadIdInfo; 174 175 typedef struct { 176 DrdThreadId tid; 177 HChar* descr; 178 } UnimpClReqInfo; 179 180 void DRD_(set_show_conflicting_segments)(const Bool scs); 181 void DRD_(register_error_handlers)(void); 182 void DRD_(trace_msg)(const HChar* format, ...) PRINTF_CHECK(1, 2); 183 void DRD_(trace_msg_w_bt)(const HChar* format, ...) PRINTF_CHECK(1, 2); 184 185 186 #endif /* __DRD_ERROR_H */ 187