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 | { |
bart | fca00e5 | 2008-07-09 12:43:35 +0000 | [diff] [blame] | 137 | char sect_name[64]; |
| 138 | VgSectKind sect_kind; |
| 139 | |
| 140 | sect_kind = VG_(seginfo_sect_kind)(sect_name, sizeof(sect_name), dri->addr); |
| 141 | if (sect_kind != Vg_SectUnknown) |
| 142 | { |
| 143 | VG_(message)(Vg_UserMsg, |
| 144 | "Allocation context: %s section of %s", |
| 145 | VG_(pp_SectKind)(sect_kind), |
| 146 | sect_name); |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | VG_(message)(Vg_UserMsg, "Allocation context: unknown."); |
| 151 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 152 | } |
bart | 16d76e5 | 2008-03-18 17:08:08 +0000 | [diff] [blame] | 153 | if (s_drd_show_conflicting_segments) |
| 154 | { |
| 155 | thread_report_conflicting_segments(dri->tid, |
| 156 | dri->addr, dri->size, dri->access_type); |
| 157 | } |
bart | f993b87 | 2008-04-01 18:19:50 +0000 | [diff] [blame] | 158 | |
| 159 | VG_(free)(descr2); |
| 160 | VG_(free)(descr1); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static Bool drd_tool_error_eq(VgRes res, Error* e1, Error* e2) |
| 164 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 165 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static void drd_tool_error_pp(Error* const e) |
| 169 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 170 | switch (VG_(get_error_kind)(e)) |
| 171 | { |
| 172 | case DataRaceErr: { |
| 173 | drd_report_data_race2(e, VG_(get_error_extra)(e)); |
| 174 | break; |
| 175 | } |
| 176 | case MutexErr: { |
| 177 | MutexErrInfo* p = (MutexErrInfo*)(VG_(get_error_extra)(e)); |
| 178 | tl_assert(p); |
bart | 6b71761 | 2008-03-24 09:29:38 +0000 | [diff] [blame] | 179 | if (p->recursion_count >= 0) |
| 180 | { |
| 181 | VG_(message)(Vg_UserMsg, |
| 182 | "%s: mutex 0x%lx, recursion count %d, owner %d.", |
| 183 | VG_(get_error_string)(e), |
| 184 | p->mutex, |
| 185 | p->recursion_count, |
| 186 | p->owner); |
| 187 | } |
| 188 | else |
| 189 | { |
| 190 | VG_(message)(Vg_UserMsg, |
bart | 52e8291 | 2008-03-24 19:31:33 +0000 | [diff] [blame] | 191 | "The object at address 0x%lx is not a mutex.", |
bart | 6b71761 | 2008-03-24 09:29:38 +0000 | [diff] [blame] | 192 | p->mutex); |
| 193 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 194 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 195 | first_observed(p->mutex); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 196 | break; |
| 197 | } |
| 198 | case CondErr: { |
| 199 | CondErrInfo* cdei =(CondErrInfo*)(VG_(get_error_extra)(e)); |
| 200 | VG_(message)(Vg_UserMsg, |
| 201 | "%s: cond 0x%lx", |
bart | be8a12c | 2008-03-17 18:36:55 +0000 | [diff] [blame] | 202 | VG_(get_error_string)(e), |
| 203 | cdei->cond); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 204 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 205 | first_observed(cdei->cond); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 206 | break; |
| 207 | } |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 208 | case CondDestrErr: { |
| 209 | CondDestrErrInfo* cdi = (CondDestrErrInfo*)(VG_(get_error_extra)(e)); |
| 210 | VG_(message)(Vg_UserMsg, |
| 211 | "%s: cond 0x%lx, mutex 0x%lx locked by thread %d/%d", |
| 212 | VG_(get_error_string)(e), |
| 213 | cdi->cond, cdi->mutex, |
| 214 | DrdThreadIdToVgThreadId(cdi->tid), cdi->tid); |
| 215 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 216 | first_observed(cdi->mutex); |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 217 | break; |
| 218 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 219 | case CondRaceErr: { |
| 220 | CondRaceErrInfo* cei = (CondRaceErrInfo*)(VG_(get_error_extra)(e)); |
| 221 | VG_(message)(Vg_UserMsg, |
bart | 46b5fce | 2008-06-28 13:01:30 +0000 | [diff] [blame] | 222 | "Probably a race condition: condition variable 0x%lx has been" |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 223 | " signaled but the associated mutex 0x%lx is not locked" |
| 224 | " by the signalling thread.", |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 225 | cei->cond, cei->mutex); |
| 226 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 227 | first_observed(cei->cond); |
| 228 | first_observed(cei->mutex); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 229 | break; |
| 230 | } |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 231 | case CondWaitErr: { |
| 232 | CondWaitErrInfo* cwei = (CondWaitErrInfo*)(VG_(get_error_extra)(e)); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 233 | VG_(message)(Vg_UserMsg, |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 234 | "%s: condition variable 0x%lx, mutexes 0x%lx and 0x%lx", |
bart | be8a12c | 2008-03-17 18:36:55 +0000 | [diff] [blame] | 235 | VG_(get_error_string)(e), |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 236 | cwei->cond, |
| 237 | cwei->mutex1, |
| 238 | cwei->mutex2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 239 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 240 | first_observed(cwei->cond); |
| 241 | first_observed(cwei->mutex1); |
| 242 | first_observed(cwei->mutex2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 243 | break; |
| 244 | } |
| 245 | case SemaphoreErr: { |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 246 | SemaphoreErrInfo* sei = (SemaphoreErrInfo*)(VG_(get_error_extra)(e)); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 247 | tl_assert(sei); |
| 248 | VG_(message)(Vg_UserMsg, |
| 249 | "%s: semaphore 0x%lx", |
| 250 | VG_(get_error_string)(e), |
| 251 | sei->semaphore); |
| 252 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | b48b4c5 | 2008-07-03 12:29:16 +0000 | [diff] [blame] | 253 | first_observed(sei->semaphore); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 254 | break; |
| 255 | } |
| 256 | case BarrierErr: { |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 257 | BarrierErrInfo* bei =(BarrierErrInfo*)(VG_(get_error_extra)(e)); |
| 258 | tl_assert(bei); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 259 | VG_(message)(Vg_UserMsg, |
| 260 | "%s: barrier 0x%lx", |
| 261 | VG_(get_error_string)(e), |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 262 | bei->barrier); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 263 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 264 | first_observed(bei->barrier); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 265 | break; |
| 266 | } |
| 267 | case RwlockErr: { |
| 268 | RwlockErrInfo* p = (RwlockErrInfo*)(VG_(get_error_extra)(e)); |
| 269 | tl_assert(p); |
| 270 | VG_(message)(Vg_UserMsg, |
| 271 | "%s: rwlock 0x%lx.", |
| 272 | VG_(get_error_string)(e), |
| 273 | p->rwlock); |
| 274 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 275 | first_observed(p->rwlock); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 276 | break; |
| 277 | } |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 278 | case HoldtimeErr: { |
| 279 | HoldtimeErrInfo* p =(HoldtimeErrInfo*)(VG_(get_error_extra)(e)); |
| 280 | tl_assert(p); |
| 281 | tl_assert(p->acquired_at); |
| 282 | VG_(message)(Vg_UserMsg, "Acquired at:"); |
| 283 | VG_(pp_ExeContext)(p->acquired_at); |
| 284 | VG_(message)(Vg_UserMsg, |
| 285 | "Lock on %s 0x%lx was held during %d ms (threshold: %d ms).", |
| 286 | VG_(get_error_string)(e), |
| 287 | p->synchronization_object, |
| 288 | p->hold_time_ms, |
| 289 | p->threshold_ms); |
| 290 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
bart | 391d9dc | 2008-07-03 10:57:30 +0000 | [diff] [blame] | 291 | first_observed(p->synchronization_object); |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 292 | break; |
| 293 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 294 | case GenericErr: { |
| 295 | //GenericErrInfo* gei =(GenericErrInfo*)(VG_(get_error_extra)(e)); |
| 296 | VG_(message)(Vg_UserMsg, "%s", VG_(get_error_string)(e)); |
| 297 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 298 | break; |
| 299 | } |
| 300 | default: |
| 301 | VG_(message)(Vg_UserMsg, |
| 302 | "%s", |
| 303 | VG_(get_error_string)(e)); |
| 304 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 305 | break; |
| 306 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | static UInt drd_tool_error_update_extra(Error* e) |
| 310 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 311 | switch (VG_(get_error_kind)(e)) |
| 312 | { |
| 313 | case DataRaceErr: |
| 314 | return sizeof(DataRaceErrInfo); |
| 315 | case MutexErr: |
| 316 | return sizeof(MutexErrInfo); |
| 317 | case CondErr: |
| 318 | return sizeof(CondErrInfo); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 319 | case CondDestrErr: |
| 320 | return sizeof(CondDestrErrInfo); |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 321 | case CondRaceErr: |
| 322 | return sizeof(CondRaceErrInfo); |
| 323 | case CondWaitErr: |
| 324 | return sizeof(CondWaitErrInfo); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 325 | case SemaphoreErr: |
| 326 | return sizeof(SemaphoreErrInfo); |
| 327 | case BarrierErr: |
| 328 | return sizeof(BarrierErrInfo); |
| 329 | case RwlockErr: |
| 330 | return sizeof(RwlockErrInfo); |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 331 | case HoldtimeErr: |
| 332 | return sizeof(HoldtimeErrInfo); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 333 | case GenericErr: |
| 334 | return sizeof(GenericErrInfo); |
| 335 | default: |
| 336 | tl_assert(False); |
| 337 | break; |
| 338 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static Bool drd_tool_error_recog(Char* const name, Supp* const supp) |
| 342 | { |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 343 | SuppKind skind = 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 344 | |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 345 | if (VG_(strcmp)(name, STR_DataRaceErr) == 0) |
| 346 | ; |
| 347 | else if (VG_(strcmp)(name, STR_MutexErr) == 0) |
| 348 | ; |
| 349 | else if (VG_(strcmp)(name, STR_CondErr) == 0) |
| 350 | ; |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 351 | else if (VG_(strcmp)(name, STR_CondDestrErr) == 0) |
| 352 | ; |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 353 | else if (VG_(strcmp)(name, STR_CondRaceErr) == 0) |
| 354 | ; |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 355 | else if (VG_(strcmp)(name, STR_CondWaitErr) == 0) |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 356 | ; |
| 357 | else if (VG_(strcmp)(name, STR_SemaphoreErr) == 0) |
| 358 | ; |
| 359 | else if (VG_(strcmp)(name, STR_BarrierErr) == 0) |
| 360 | ; |
| 361 | else if (VG_(strcmp)(name, STR_RwlockErr) == 0) |
| 362 | ; |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 363 | else if (VG_(strcmp)(name, STR_HoldtimeErr) == 0) |
| 364 | ; |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 365 | else if (VG_(strcmp)(name, STR_GenericErr) == 0) |
| 366 | ; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 367 | else |
| 368 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 369 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 370 | VG_(set_supp_kind)(supp, skind); |
| 371 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static Bool drd_tool_error_read_extra(Int fd, Char* buf, Int nBuf, Supp* supp) |
| 375 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 376 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static Bool drd_tool_error_matches(Error* const e, Supp* const supp) |
| 380 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 381 | switch (VG_(get_supp_kind)(supp)) |
| 382 | { |
| 383 | } |
| 384 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | static Char* drd_tool_error_name(Error* e) |
| 388 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 389 | switch (VG_(get_error_kind)(e)) |
| 390 | { |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 391 | case DataRaceErr: return VGAPPEND(STR_, DataRaceErr); |
| 392 | case MutexErr: return VGAPPEND(STR_, MutexErr); |
| 393 | case CondErr: return VGAPPEND(STR_, CondErr); |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 394 | case CondDestrErr: return VGAPPEND(STR_, CondDestrErr); |
bart | 3bb1cec | 2008-06-28 16:01:43 +0000 | [diff] [blame] | 395 | case CondRaceErr: return VGAPPEND(STR_, CondRaceErr); |
| 396 | case CondWaitErr: return VGAPPEND(STR_, CondWaitErr); |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 397 | case SemaphoreErr: return VGAPPEND(STR_, SemaphoreErr); |
| 398 | case BarrierErr: return VGAPPEND(STR_, BarrierErr); |
| 399 | case RwlockErr: return VGAPPEND(STR_, RwlockErr); |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 400 | case HoldtimeErr: return VGAPPEND(STR_, HoldtimeErr); |
bart | 5fc70e6 | 2008-03-23 07:54:02 +0000 | [diff] [blame] | 401 | case GenericErr: return VGAPPEND(STR_, GenericErr); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 402 | default: |
| 403 | tl_assert(0); |
| 404 | } |
| 405 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | static void drd_tool_error_print_extra(Error* e) |
| 409 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 410 | switch (VG_(get_error_kind)(e)) |
| 411 | { |
| 412 | // VG_(printf)(" %s\n", VG_(get_error_string)(err)); |
| 413 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void drd_register_error_handlers(void) |
| 417 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 418 | // Tool error reporting. |
| 419 | VG_(needs_tool_errors)(drd_tool_error_eq, |
| 420 | drd_tool_error_pp, |
| 421 | True, |
| 422 | drd_tool_error_update_extra, |
| 423 | drd_tool_error_recog, |
| 424 | drd_tool_error_read_extra, |
| 425 | drd_tool_error_matches, |
| 426 | drd_tool_error_name, |
| 427 | drd_tool_error_print_extra); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 428 | } |