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