sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 2 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 3 | |
sewardj | 03f8d3f | 2012-08-05 15:46:46 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2012 Bart Van Assche <bvanassche@acm.org>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 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 | |
bart | b515eb1 | 2008-03-07 18:52:38 +0000 | [diff] [blame] | 29 | #include "pub_drd_bitmap.h" // BmAccessTypeT |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 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 { |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 39 | #define STR_DataRaceErr "ConflictingAccess" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 40 | DataRaceErr = 1, |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 41 | #define STR_MutexErr "MutexErr" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 42 | MutexErr = 2, |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 43 | #define STR_CondErr "CondErr" |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 44 | CondErr = 3, |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 45 | #define STR_CondDestrErr "CondDestrErr" |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 46 | CondDestrErr = 4, |
| 47 | #define STR_CondRaceErr "CondRaceErr" |
| 48 | CondRaceErr = 5, |
| 49 | #define STR_CondWaitErr "CondWaitErr" |
| 50 | CondWaitErr = 6, |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 51 | #define STR_SemaphoreErr "SemaphoreErr" |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 52 | SemaphoreErr = 7, |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 53 | #define STR_BarrierErr "BarrierErr" |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 54 | BarrierErr = 8, |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 55 | #define STR_RwlockErr "RwlockErr" |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 56 | RwlockErr = 9, |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 57 | #define STR_HoldtimeErr "HoldtimeErr" |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 58 | HoldtimeErr = 10, |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 59 | #define STR_GenericErr "GenericErr" |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 60 | GenericErr = 11, |
bart | b48bde2 | 2009-07-31 08:26:17 +0000 | [diff] [blame] | 61 | #define STR_InvalidThreadId "InvalidThreadId" |
| 62 | InvalidThreadId = 12, |
bart | 141a7ed | 2010-03-21 17:28:10 +0000 | [diff] [blame] | 63 | #define STR_UnimpHgClReq "UnimpHgClReq" |
| 64 | UnimpHgClReq = 13, |
| 65 | #define STR_UnimpDrdClReq "UnimpDrdClReq" |
| 66 | UnimpDrdClReq = 14, |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 67 | } DrdErrorKind; |
| 68 | |
| 69 | /* The classification of a faulting address. */ |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 70 | typedef |
| 71 | enum { |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 72 | //Undescribed, // as-yet unclassified |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 73 | eStack, |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 74 | eUnknown, // classification yielded nothing useful |
| 75 | //Freed, |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 76 | eMallocd, |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 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 |
njn | c4431bf | 2009-01-15 21:29:24 +0000 | [diff] [blame] | 89 | PtrdiffT rwoffset; // ALL |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 90 | ExeContext* lastchange; // Mallocd |
| 91 | DrdThreadId stack_tid; // Stack |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 92 | DebugInfo* debuginfo; // Segment |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 93 | Char name[256]; // Segment |
| 94 | Char descr[256]; // Segment |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 95 | } AddrInfo; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 96 | |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 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 | */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 101 | typedef struct { |
bart | 354009c | 2008-03-16 10:42:33 +0000 | [diff] [blame] | 102 | DrdThreadId tid; // Thread ID of the running thread. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 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 { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 109 | DrdThreadId tid; |
| 110 | Addr mutex; |
| 111 | Int recursion_count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 112 | DrdThreadId owner; |
| 113 | } MutexErrInfo; |
| 114 | |
| 115 | typedef struct { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 116 | DrdThreadId tid; |
| 117 | Addr cond; |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 118 | } CondErrInfo; |
| 119 | |
| 120 | typedef struct { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 121 | DrdThreadId tid; |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 122 | Addr cond; |
| 123 | Addr mutex; |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 124 | DrdThreadId owner; |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 125 | } CondDestrErrInfo; |
| 126 | |
| 127 | typedef struct { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 128 | DrdThreadId tid; |
| 129 | Addr cond; |
| 130 | Addr mutex; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 131 | } CondRaceErrInfo; |
| 132 | |
| 133 | typedef struct { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 134 | DrdThreadId tid; |
| 135 | Addr cond; |
| 136 | Addr mutex1; |
| 137 | Addr mutex2; |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 138 | } CondWaitErrInfo; |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 139 | |
| 140 | typedef struct { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 141 | DrdThreadId tid; |
| 142 | Addr semaphore; |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 143 | } SemaphoreErrInfo; |
| 144 | |
| 145 | typedef struct { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 146 | DrdThreadId tid; |
bart | d2c5eae | 2009-02-21 15:27:04 +0000 | [diff] [blame] | 147 | Addr barrier; |
| 148 | DrdThreadId other_tid; |
| 149 | ExeContext* other_context; |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 150 | } BarrierErrInfo; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 151 | |
bart | e883bc8 | 2008-02-26 19:13:04 +0000 | [diff] [blame] | 152 | typedef struct { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 153 | DrdThreadId tid; |
| 154 | Addr rwlock; |
bart | 777f7fe | 2008-03-02 17:43:18 +0000 | [diff] [blame] | 155 | } RwlockErrInfo; |
| 156 | |
| 157 | typedef struct { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 158 | DrdThreadId tid; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 159 | Addr synchronization_object; |
| 160 | ExeContext* acquired_at; |
| 161 | UInt hold_time_ms; |
| 162 | UInt threshold_ms; |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 163 | } HoldtimeErrInfo; |
| 164 | |
| 165 | typedef struct { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 166 | DrdThreadId tid; |
bart | 62cc232 | 2010-03-07 10:54:21 +0000 | [diff] [blame] | 167 | Addr addr; |
bart | e883bc8 | 2008-02-26 19:13:04 +0000 | [diff] [blame] | 168 | } GenericErrInfo; |
| 169 | |
bart | b48bde2 | 2009-07-31 08:26:17 +0000 | [diff] [blame] | 170 | typedef struct { |
| 171 | DrdThreadId tid; |
| 172 | ULong ptid; |
| 173 | } InvalidThreadIdInfo; |
bart | 16d76e5 | 2008-03-18 17:08:08 +0000 | [diff] [blame] | 174 | |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 175 | typedef struct { |
| 176 | DrdThreadId tid; |
| 177 | Char* descr; |
| 178 | } UnimpClReqInfo; |
| 179 | |
bart | 246fbf2 | 2009-02-15 14:46:17 +0000 | [diff] [blame] | 180 | void DRD_(set_show_conflicting_segments)(const Bool scs); |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 181 | void DRD_(register_error_handlers)(void); |
bart | b92ff0f | 2011-10-08 08:29:29 +0000 | [diff] [blame] | 182 | void DRD_(trace_msg)(const char* format, ...) PRINTF_CHECK(1, 2); |
bart | ad994e8 | 2011-10-13 18:04:30 +0000 | [diff] [blame] | 183 | void DRD_(trace_msg_w_bt)(const char* format, ...) PRINTF_CHECK(1, 2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 184 | |
| 185 | |
| 186 | #endif /* __DRD_ERROR_H */ |