sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | This file is part of drd, a data race detector. |
| 3 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2008 Bart Van Assche |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | bart.vanassche@gmail.com |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU General Public License as |
| 9 | published by the Free Software Foundation; either version 2 of the |
| 10 | License, or (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, but |
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307, USA. |
| 21 | |
| 22 | The GNU General Public License is contained in the file COPYING. |
| 23 | */ |
| 24 | |
| 25 | |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 26 | #include "drd_clientobj.h" /* struct mutex_info */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 27 | #include "drd_error.h" |
| 28 | #include "drd_malloc_wrappers.h" |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 29 | #include "drd_mutex.h" |
| 30 | #include "drd_suppression.h" /* drd_start_suppression() */ |
| 31 | #include "pub_drd_bitmap.h" /* LHS_W, ... */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 32 | #include "pub_tool_vki.h" |
| 33 | #include "pub_tool_basics.h" |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 34 | #include "pub_tool_libcassert.h" /* tl_assert() */ |
| 35 | #include "pub_tool_libcbase.h" /* strlen() */ |
| 36 | #include "pub_tool_libcfile.h" /* VG_(get_startup_wd)() */ |
| 37 | #include "pub_tool_libcprint.h" /* VG_(printf)() */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 38 | #include "pub_tool_machine.h" |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 39 | #include "pub_tool_mallocfree.h" /* VG_(malloc), VG_(free) */ |
| 40 | #include "pub_tool_threadstate.h" /* VG_(get_pthread_id)() */ |
| 41 | #include "pub_tool_tooliface.h" /* VG_(needs_tool_errors)() */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 42 | |
| 43 | |
bart | 16d76e5 | 2008-03-18 17:08:08 +0000 | [diff] [blame] | 44 | /* Local variables. */ |
| 45 | |
| 46 | static Bool s_drd_show_conflicting_segments = True; |
| 47 | |
| 48 | |
| 49 | void set_show_conflicting_segments(const Bool scs) |
| 50 | { |
| 51 | s_drd_show_conflicting_segments = scs; |
| 52 | } |
| 53 | |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 54 | /** Describe a data address range [a,a+len[ as good as possible, for error |
| 55 | * messages, putting the result in ai. |
| 56 | */ |
bart | ff1252a | 2008-03-16 17:27:25 +0000 | [diff] [blame] | 57 | static |
| 58 | void describe_malloced_addr(Addr const a, SizeT const len, AddrInfo* const ai) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 59 | { |
bart | ff1252a | 2008-03-16 17:27:25 +0000 | [diff] [blame] | 60 | Addr data; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 61 | |
bart | ff1252a | 2008-03-16 17:27:25 +0000 | [diff] [blame] | 62 | if (drd_heap_addrinfo(a, &data, &ai->size, &ai->lastchange)) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 63 | { |
bart | ff1252a | 2008-03-16 17:27:25 +0000 | [diff] [blame] | 64 | ai->akind = eMallocd; |
| 65 | ai->rwoffset = a - data; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 66 | } |
bart | ff1252a | 2008-03-16 17:27:25 +0000 | [diff] [blame] | 67 | else |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 68 | { |
bart | ff1252a | 2008-03-16 17:27:25 +0000 | [diff] [blame] | 69 | ai->akind = eUnknown; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 70 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 71 | } |
| 72 | |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 73 | /** Report where an object has been observed for the first time. The printed |
| 74 | * call stack will either refer to a pthread_*_init() or a pthread_*lock() |
| 75 | * call. |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 76 | */ |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 77 | static void first_observed(const Addr obj) |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 78 | { |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 79 | DrdClientobj* cl; |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 80 | |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 81 | cl = clientobj_get_any(obj); |
| 82 | if (cl) |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 83 | { |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 84 | tl_assert(cl->any.first_observed_at); |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 85 | VG_(message)(Vg_UserMsg, |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 86 | "%s 0x%lx was first observed at:", |
| 87 | clientobj_type_name(cl->any.type), |
| 88 | obj); |
| 89 | VG_(pp_ExeContext)(cl->any.first_observed_at); |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 93 | static |
| 94 | void drd_report_data_race2(Error* const err, const DataRaceErrInfo* const dri) |
| 95 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 96 | AddrInfo ai; |
bart | f993b87 | 2008-04-01 18:19:50 +0000 | [diff] [blame] | 97 | const unsigned descr_size = 256; |
| 98 | Char* descr1 = VG_(malloc)(descr_size); |
| 99 | Char* descr2 = VG_(malloc)(descr_size); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 100 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 101 | tl_assert(dri); |
| 102 | tl_assert(dri->addr); |
| 103 | tl_assert(dri->size > 0); |
bart | fdd8d4e | 2008-04-01 18:38:29 +0000 | [diff] [blame] | 104 | tl_assert(descr1); |
| 105 | tl_assert(descr2); |
bart | b515eb1 | 2008-03-07 18:52:38 +0000 | [diff] [blame] | 106 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 107 | descr1[0] = 0; |
| 108 | descr2[0] = 0; |
bart | f993b87 | 2008-04-01 18:19:50 +0000 | [diff] [blame] | 109 | VG_(get_data_description)(descr1, descr2, descr_size, dri->addr); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 110 | if (descr1[0] == 0) |
| 111 | { |
bart | ff1252a | 2008-03-16 17:27:25 +0000 | [diff] [blame] | 112 | describe_malloced_addr(dri->addr, dri->size, &ai); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 113 | } |
| 114 | VG_(message)(Vg_UserMsg, |
bart | aa97a54 | 2008-03-16 17:57:01 +0000 | [diff] [blame] | 115 | "Conflicting %s by thread %d/%d at 0x%08lx size %ld", |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 116 | dri->access_type == eStore ? "store" : "load", |
bart | 354009c | 2008-03-16 10:42:33 +0000 | [diff] [blame] | 117 | DrdThreadIdToVgThreadId(dri->tid), |
bart | aa97a54 | 2008-03-16 17:57:01 +0000 | [diff] [blame] | 118 | dri->tid, |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 119 | dri->addr, |
| 120 | dri->size); |
| 121 | VG_(pp_ExeContext)(VG_(get_error_where)(err)); |
| 122 | if (descr1[0]) |
| 123 | { |
| 124 | VG_(message)(Vg_UserMsg, "%s", descr1); |
| 125 | VG_(message)(Vg_UserMsg, "%s", descr2); |
| 126 | } |
| 127 | else if (ai.akind == eMallocd && ai.lastchange) |
| 128 | { |
| 129 | VG_(message)(Vg_UserMsg, |
| 130 | "Address 0x%lx is at offset %ld from 0x%lx." |
| 131 | " Allocation context:", |
| 132 | dri->addr, ai.rwoffset, dri->addr - ai.rwoffset); |
| 133 | VG_(pp_ExeContext)(ai.lastchange); |
| 134 | } |
| 135 | else |
| 136 | { |
| 137 | VG_(message)(Vg_UserMsg, "Allocation context: unknown."); |
| 138 | } |
bart | 16d76e5 | 2008-03-18 17:08:08 +0000 | [diff] [blame] | 139 | if (s_drd_show_conflicting_segments) |
| 140 | { |
| 141 | thread_report_conflicting_segments(dri->tid, |
| 142 | dri->addr, dri->size, dri->access_type); |
| 143 | } |
bart | f993b87 | 2008-04-01 18:19:50 +0000 | [diff] [blame] | 144 | |
| 145 | VG_(free)(descr2); |
| 146 | VG_(free)(descr1); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static Bool drd_tool_error_eq(VgRes res, Error* e1, Error* e2) |
| 150 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 151 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static void drd_tool_error_pp(Error* const e) |
| 155 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 156 | switch (VG_(get_error_kind)(e)) |
| 157 | { |
| 158 | case DataRaceErr: { |
| 159 | drd_report_data_race2(e, VG_(get_error_extra)(e)); |
| 160 | break; |
| 161 | } |
| 162 | case MutexErr: { |
| 163 | MutexErrInfo* p = (MutexErrInfo*)(VG_(get_error_extra)(e)); |
| 164 | tl_assert(p); |
bart | 6b71761 | 2008-03-24 09:29:38 +0000 | [diff] [blame] | 165 | if (p->recursion_count >= 0) |
| 166 | { |
| 167 | VG_(message)(Vg_UserMsg, |
| 168 | "%s: mutex 0x%lx, recursion count %d, owner %d.", |
| 169 | VG_(get_error_string)(e), |
| 170 | p->mutex, |
| 171 | p->recursion_count, |
| 172 | p->owner); |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | VG_(message)(Vg_UserMsg, |
bart | 52e8291 | 2008-03-24 19:31:33 +0000 | [diff] [blame] | 177 | "The object at address 0x%lx is not a mutex.", |
bart | 6b71761 | 2008-03-24 09:29:38 +0000 | [diff] [blame] | 178 | p->mutex); |
| 179 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 180 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 181 | first_observed(p->mutex); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 182 | break; |
| 183 | } |
| 184 | case CondErr: { |
| 185 | CondErrInfo* cdei =(CondErrInfo*)(VG_(get_error_extra)(e)); |
| 186 | VG_(message)(Vg_UserMsg, |
| 187 | "%s: cond 0x%lx", |
bart | be8a12c | 2008-03-17 18:36:55 +0000 | [diff] [blame] | 188 | VG_(get_error_string)(e), |
| 189 | cdei->cond); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 190 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 191 | first_observed(cdei->cond); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 192 | break; |
| 193 | } |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 194 | case CondDestrErr: { |
| 195 | CondDestrErrInfo* cdi = (CondDestrErrInfo*)(VG_(get_error_extra)(e)); |
| 196 | VG_(message)(Vg_UserMsg, |
| 197 | "%s: cond 0x%lx, mutex 0x%lx locked by thread %d/%d", |
| 198 | VG_(get_error_string)(e), |
| 199 | cdi->cond, cdi->mutex, |
| 200 | DrdThreadIdToVgThreadId(cdi->tid), cdi->tid); |
| 201 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 202 | first_observed(cdi->mutex); |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 203 | break; |
| 204 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 205 | case CondRaceErr: { |
| 206 | CondRaceErrInfo* cei = (CondRaceErrInfo*)(VG_(get_error_extra)(e)); |
| 207 | VG_(message)(Vg_UserMsg, |
bart | 46b5fce | 2008-06-28 13:01:30 +0000 | [diff] [blame] | 208 | "Probably a race condition: condition variable 0x%lx has been" |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 209 | " signaled but the associated mutex 0x%lx is not locked" |
| 210 | " by the signalling thread.", |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 211 | cei->cond, cei->mutex); |
| 212 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 213 | first_observed(cei->cond); |
| 214 | first_observed(cei->mutex); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 215 | break; |
| 216 | } |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 217 | case CondWaitErr: { |
| 218 | CondWaitErrInfo* cwei = (CondWaitErrInfo*)(VG_(get_error_extra)(e)); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 219 | VG_(message)(Vg_UserMsg, |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 220 | "%s: condition variable 0x%lx, mutexes 0x%lx and 0x%lx", |
bart | be8a12c | 2008-03-17 18:36:55 +0000 | [diff] [blame] | 221 | VG_(get_error_string)(e), |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 222 | cwei->cond, |
| 223 | cwei->mutex1, |
| 224 | cwei->mutex2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 225 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 226 | first_observed(cwei->cond); |
| 227 | first_observed(cwei->mutex1); |
| 228 | first_observed(cwei->mutex2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 229 | break; |
| 230 | } |
| 231 | case SemaphoreErr: { |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 232 | SemaphoreErrInfo* sei = (SemaphoreErrInfo*)(VG_(get_error_extra)(e)); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 233 | tl_assert(sei); |
| 234 | VG_(message)(Vg_UserMsg, |
| 235 | "%s: semaphore 0x%lx", |
| 236 | VG_(get_error_string)(e), |
| 237 | sei->semaphore); |
| 238 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | b48b4c5 | 2008-07-03 12:29:16 +0000 | [diff] [blame^] | 239 | first_observed(sei->semaphore); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 240 | break; |
| 241 | } |
| 242 | case BarrierErr: { |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 243 | BarrierErrInfo* bei =(BarrierErrInfo*)(VG_(get_error_extra)(e)); |
| 244 | tl_assert(bei); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 245 | VG_(message)(Vg_UserMsg, |
| 246 | "%s: barrier 0x%lx", |
| 247 | VG_(get_error_string)(e), |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 248 | bei->barrier); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 249 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 250 | first_observed(bei->barrier); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 251 | break; |
| 252 | } |
| 253 | case RwlockErr: { |
| 254 | RwlockErrInfo* p = (RwlockErrInfo*)(VG_(get_error_extra)(e)); |
| 255 | tl_assert(p); |
| 256 | VG_(message)(Vg_UserMsg, |
| 257 | "%s: rwlock 0x%lx.", |
| 258 | VG_(get_error_string)(e), |
| 259 | p->rwlock); |
| 260 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 261 | first_observed(p->rwlock); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 262 | break; |
| 263 | } |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 264 | case HoldtimeErr: { |
| 265 | HoldtimeErrInfo* p =(HoldtimeErrInfo*)(VG_(get_error_extra)(e)); |
| 266 | tl_assert(p); |
| 267 | tl_assert(p->acquired_at); |
| 268 | VG_(message)(Vg_UserMsg, "Acquired at:"); |
| 269 | VG_(pp_ExeContext)(p->acquired_at); |
| 270 | VG_(message)(Vg_UserMsg, |
| 271 | "Lock on %s 0x%lx was held during %d ms (threshold: %d ms).", |
| 272 | VG_(get_error_string)(e), |
| 273 | p->synchronization_object, |
| 274 | p->hold_time_ms, |
| 275 | p->threshold_ms); |
| 276 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 277 | first_observed(p->synchronization_object); |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 278 | break; |
| 279 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 280 | case GenericErr: { |
| 281 | //GenericErrInfo* gei =(GenericErrInfo*)(VG_(get_error_extra)(e)); |
| 282 | VG_(message)(Vg_UserMsg, "%s", VG_(get_error_string)(e)); |
| 283 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 284 | break; |
| 285 | } |
| 286 | default: |
| 287 | VG_(message)(Vg_UserMsg, |
| 288 | "%s", |
| 289 | VG_(get_error_string)(e)); |
| 290 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 291 | break; |
| 292 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static UInt drd_tool_error_update_extra(Error* e) |
| 296 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 297 | switch (VG_(get_error_kind)(e)) |
| 298 | { |
| 299 | case DataRaceErr: |
| 300 | return sizeof(DataRaceErrInfo); |
| 301 | case MutexErr: |
| 302 | return sizeof(MutexErrInfo); |
| 303 | case CondErr: |
| 304 | return sizeof(CondErrInfo); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 305 | case CondDestrErr: |
| 306 | return sizeof(CondDestrErrInfo); |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 307 | case CondRaceErr: |
| 308 | return sizeof(CondRaceErrInfo); |
| 309 | case CondWaitErr: |
| 310 | return sizeof(CondWaitErrInfo); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 311 | case SemaphoreErr: |
| 312 | return sizeof(SemaphoreErrInfo); |
| 313 | case BarrierErr: |
| 314 | return sizeof(BarrierErrInfo); |
| 315 | case RwlockErr: |
| 316 | return sizeof(RwlockErrInfo); |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 317 | case HoldtimeErr: |
| 318 | return sizeof(HoldtimeErrInfo); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 319 | case GenericErr: |
| 320 | return sizeof(GenericErrInfo); |
| 321 | default: |
| 322 | tl_assert(False); |
| 323 | break; |
| 324 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | static Bool drd_tool_error_recog(Char* const name, Supp* const supp) |
| 328 | { |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 329 | SuppKind skind = 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 330 | |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 331 | if (VG_(strcmp)(name, STR_DataRaceErr) == 0) |
| 332 | ; |
| 333 | else if (VG_(strcmp)(name, STR_MutexErr) == 0) |
| 334 | ; |
| 335 | else if (VG_(strcmp)(name, STR_CondErr) == 0) |
| 336 | ; |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 337 | else if (VG_(strcmp)(name, STR_CondDestrErr) == 0) |
| 338 | ; |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 339 | else if (VG_(strcmp)(name, STR_CondRaceErr) == 0) |
| 340 | ; |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 341 | else if (VG_(strcmp)(name, STR_CondWaitErr) == 0) |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 342 | ; |
| 343 | else if (VG_(strcmp)(name, STR_SemaphoreErr) == 0) |
| 344 | ; |
| 345 | else if (VG_(strcmp)(name, STR_BarrierErr) == 0) |
| 346 | ; |
| 347 | else if (VG_(strcmp)(name, STR_RwlockErr) == 0) |
| 348 | ; |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 349 | else if (VG_(strcmp)(name, STR_HoldtimeErr) == 0) |
| 350 | ; |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 351 | else if (VG_(strcmp)(name, STR_GenericErr) == 0) |
| 352 | ; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 353 | else |
| 354 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 355 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 356 | VG_(set_supp_kind)(supp, skind); |
| 357 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static Bool drd_tool_error_read_extra(Int fd, Char* buf, Int nBuf, Supp* supp) |
| 361 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 362 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static Bool drd_tool_error_matches(Error* const e, Supp* const supp) |
| 366 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 367 | switch (VG_(get_supp_kind)(supp)) |
| 368 | { |
| 369 | } |
| 370 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | static Char* drd_tool_error_name(Error* e) |
| 374 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 375 | switch (VG_(get_error_kind)(e)) |
| 376 | { |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 377 | case DataRaceErr: return VGAPPEND(STR_, DataRaceErr); |
| 378 | case MutexErr: return VGAPPEND(STR_, MutexErr); |
| 379 | case CondErr: return VGAPPEND(STR_, CondErr); |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 380 | case CondDestrErr: return VGAPPEND(STR_, CondDestrErr); |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 381 | case CondRaceErr: return VGAPPEND(STR_, CondRaceErr); |
| 382 | case CondWaitErr: return VGAPPEND(STR_, CondWaitErr); |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 383 | case SemaphoreErr: return VGAPPEND(STR_, SemaphoreErr); |
| 384 | case BarrierErr: return VGAPPEND(STR_, BarrierErr); |
| 385 | case RwlockErr: return VGAPPEND(STR_, RwlockErr); |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 386 | case HoldtimeErr: return VGAPPEND(STR_, HoldtimeErr); |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 387 | case GenericErr: return VGAPPEND(STR_, GenericErr); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 388 | default: |
| 389 | tl_assert(0); |
| 390 | } |
| 391 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static void drd_tool_error_print_extra(Error* e) |
| 395 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 396 | switch (VG_(get_error_kind)(e)) |
| 397 | { |
| 398 | // VG_(printf)(" %s\n", VG_(get_error_string)(err)); |
| 399 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | void drd_register_error_handlers(void) |
| 403 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 404 | // Tool error reporting. |
| 405 | VG_(needs_tool_errors)(drd_tool_error_eq, |
| 406 | drd_tool_error_pp, |
| 407 | True, |
| 408 | drd_tool_error_update_extra, |
| 409 | drd_tool_error_recog, |
| 410 | drd_tool_error_read_extra, |
| 411 | drd_tool_error_matches, |
| 412 | drd_tool_error_name, |
| 413 | drd_tool_error_print_extra); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 414 | } |