bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1 | /* -*- mode: C; c-basic-offset: 3; -*- */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 2 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 3 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 4 | |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 5 | Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 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 | |
bart | d2c5eae | 2009-02-21 15:27:04 +0000 | [diff] [blame] | 46 | static Bool s_show_conflicting_segments = True; |
bart | 16d76e5 | 2008-03-18 17:08:08 +0000 | [diff] [blame] | 47 | |
| 48 | |
bart | 246fbf2 | 2009-02-15 14:46:17 +0000 | [diff] [blame] | 49 | void DRD_(set_show_conflicting_segments)(const Bool scs) |
bart | 16d76e5 | 2008-03-18 17:08:08 +0000 | [diff] [blame] | 50 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 51 | s_show_conflicting_segments = scs; |
bart | 16d76e5 | 2008-03-18 17:08:08 +0000 | [diff] [blame] | 52 | } |
| 53 | |
bart | 246fbf2 | 2009-02-15 14:46:17 +0000 | [diff] [blame] | 54 | /** |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 55 | * Describe the client address a as good as possible, 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 | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 58 | void describe_malloced_addr(Addr const a, AddrInfo* const ai) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 59 | { |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 60 | Addr heap_block_start; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 61 | |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 62 | if (DRD_(heap_addrinfo)(a, &heap_block_start, &ai->size, &ai->lastchange)) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 63 | { |
| 64 | ai->akind = eMallocd; |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 65 | ai->rwoffset = a - heap_block_start; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 66 | } |
| 67 | else |
| 68 | { |
| 69 | ai->akind = eUnknown; |
| 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 | /** |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 74 | * Report where a client synchronization object has been observed for the first |
| 75 | * time. The printed call stack will either refer to a pthread_*_init() or a |
| 76 | * pthread_*lock() 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 | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 80 | DrdClientobj* cl; |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 81 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 82 | cl = DRD_(clientobj_get_any)(obj); |
| 83 | if (cl) |
| 84 | { |
| 85 | tl_assert(cl->any.first_observed_at); |
| 86 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 87 | "%s 0x%lx was first observed at:\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 88 | DRD_(clientobj_type_name)(cl->any.type), |
| 89 | obj); |
| 90 | VG_(pp_ExeContext)(cl->any.first_observed_at); |
| 91 | } |
bart | 886b87c | 2008-06-28 13:40:41 +0000 | [diff] [blame] | 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 | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 97 | AddrInfo ai; |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 98 | |
| 99 | XArray* /* of HChar */ descr1 |
| 100 | = VG_(newXA)( VG_(malloc), "drd.error.drdr2.1", |
| 101 | VG_(free), sizeof(HChar) ); |
| 102 | XArray* /* of HChar */ descr2 |
| 103 | = VG_(newXA)( VG_(malloc), "drd.error.drdr2.2", |
| 104 | VG_(free), sizeof(HChar) ); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 105 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 106 | tl_assert(dri); |
| 107 | tl_assert(dri->addr); |
| 108 | tl_assert(dri->size > 0); |
| 109 | tl_assert(descr1); |
| 110 | tl_assert(descr2); |
bart | b515eb1 | 2008-03-07 18:52:38 +0000 | [diff] [blame] | 111 | |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 112 | (void) VG_(get_data_description)(descr1, descr2, dri->addr); |
| 113 | /* If there's nothing in descr1/2, free them. Why is it safe to to |
| 114 | VG_(indexXA) at zero here? Because VG_(get_data_description) |
| 115 | guarantees to zero terminate descr1/2 regardless of the outcome |
| 116 | of the call. So there's always at least one element in each XA |
| 117 | after the call. |
| 118 | */ |
| 119 | if (0 == VG_(strlen)( VG_(indexXA)( descr1, 0 ))) { |
| 120 | VG_(deleteXA)( descr1 ); |
| 121 | descr1 = NULL; |
| 122 | } |
| 123 | if (0 == VG_(strlen)( VG_(indexXA)( descr2, 0 ))) { |
| 124 | VG_(deleteXA)( descr2 ); |
| 125 | descr2 = NULL; |
| 126 | } |
| 127 | /* Assume (assert) that VG_(get_data_description) fills in descr1 |
| 128 | before it fills in descr2 */ |
| 129 | if (descr1 == NULL) |
| 130 | tl_assert(descr2 == NULL); |
| 131 | /* So anyway. Do we have something useful? */ |
| 132 | if (descr1 == NULL) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 133 | { |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 134 | /* No. Do Plan B. */ |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 135 | describe_malloced_addr(dri->addr, &ai); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 136 | } |
| 137 | VG_(message)(Vg_UserMsg, |
bart | 63c92ea | 2009-07-19 17:53:56 +0000 | [diff] [blame] | 138 | "Conflicting %s by thread %d at 0x%08lx size %ld\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 139 | dri->access_type == eStore ? "store" : "load", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 140 | dri->tid, |
| 141 | dri->addr, |
| 142 | dri->size); |
| 143 | VG_(pp_ExeContext)(VG_(get_error_where)(err)); |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 144 | if (descr1 != NULL) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 145 | { |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 146 | VG_(message)(Vg_UserMsg, "%s\n", (HChar*)VG_(indexXA)(descr1, 0)); |
| 147 | if (descr2 != NULL) |
| 148 | VG_(message)(Vg_UserMsg, "%s\n", (HChar*)VG_(indexXA)(descr2, 0)); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 149 | } |
| 150 | else if (ai.akind == eMallocd && ai.lastchange) |
| 151 | { |
bart | fca00e5 | 2008-07-09 12:43:35 +0000 | [diff] [blame] | 152 | VG_(message)(Vg_UserMsg, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 153 | "Address 0x%lx is at offset %ld from 0x%lx." |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 154 | " Allocation context:\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 155 | dri->addr, ai.rwoffset, dri->addr - ai.rwoffset); |
| 156 | VG_(pp_ExeContext)(ai.lastchange); |
| 157 | } |
| 158 | else |
| 159 | { |
| 160 | char sect_name[64]; |
| 161 | VgSectKind sect_kind; |
bart | f993b87 | 2008-04-01 18:19:50 +0000 | [diff] [blame] | 162 | |
sewardj | e3f1e59 | 2009-07-31 09:41:29 +0000 | [diff] [blame] | 163 | sect_kind = VG_(DebugInfo_sect_kind)(sect_name, sizeof(sect_name), |
| 164 | dri->addr); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 165 | if (sect_kind != Vg_SectUnknown) |
| 166 | { |
| 167 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 168 | "Allocation context: %s section of %s\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 169 | VG_(pp_SectKind)(sect_kind), |
| 170 | sect_name); |
| 171 | } |
| 172 | else |
| 173 | { |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 174 | VG_(message)(Vg_UserMsg, "Allocation context: unknown.\n"); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | if (s_show_conflicting_segments) |
| 178 | { |
| 179 | DRD_(thread_report_conflicting_segments)(dri->tid, |
| 180 | dri->addr, dri->size, |
| 181 | dri->access_type); |
| 182 | } |
| 183 | |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 184 | if (descr2) |
| 185 | VG_(deleteXA)(descr2); |
| 186 | if (descr1) |
| 187 | VG_(deleteXA)(descr1); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 188 | } |
| 189 | |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 190 | /** |
| 191 | * Compare two error contexts. The core function VG_(maybe_record_error)() |
| 192 | * calls this function to compare error contexts such that errors that occur |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame^] | 193 | * repeatedly are only printed once. This function is only called by the core |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 194 | * if the error kind of e1 and e2 matches and if the ExeContext's of e1 and |
| 195 | * e2 also match. |
| 196 | */ |
| 197 | static Bool drd_compare_error_contexts(VgRes res, Error* e1, Error* e2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 198 | { |
bart | b80fa96 | 2009-07-31 08:45:02 +0000 | [diff] [blame] | 199 | tl_assert(VG_(get_error_kind)(e1) == VG_(get_error_kind)(e2)); |
| 200 | |
| 201 | switch (VG_(get_error_kind)(e1)) |
| 202 | { |
| 203 | case DataRaceErr: |
| 204 | { |
| 205 | const DataRaceErrInfo* const dri1 = VG_(get_error_extra)(e1); |
| 206 | const DataRaceErrInfo* const dri2 = VG_(get_error_extra)(e2); |
| 207 | return dri1->access_type == dri2->access_type |
| 208 | && dri1->size == dri2->size; |
| 209 | } |
bart | 94fb8d2 | 2009-07-31 18:45:49 +0000 | [diff] [blame] | 210 | case MutexErr: |
| 211 | { |
| 212 | const MutexErrInfo* const mei1 = VG_(get_error_extra)(e1); |
| 213 | const MutexErrInfo* const mei2 = VG_(get_error_extra)(e2); |
| 214 | return mei1->mutex == mei2->mutex; |
| 215 | } |
bart | b80fa96 | 2009-07-31 08:45:02 +0000 | [diff] [blame] | 216 | default: |
| 217 | return True; |
| 218 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 219 | } |
| 220 | |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 221 | /** |
| 222 | * Called by the core just before an error message will be printed. Used by |
| 223 | * DRD to print the thread number as a preamble. |
| 224 | */ |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 225 | static void drd_tool_error_before_pp(Error* const e) |
| 226 | { |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 227 | static DrdThreadId s_last_tid_printed = 1; |
| 228 | DrdThreadId* err_extra; |
| 229 | |
| 230 | err_extra = VG_(get_error_extra)(e); |
| 231 | |
| 232 | if (err_extra && *err_extra != s_last_tid_printed) |
| 233 | { |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 234 | VG_(umsg)("%s:\n", DRD_(thread_get_name)(*err_extra)); |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 235 | s_last_tid_printed = *err_extra; |
| 236 | } |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 237 | } |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 238 | |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 239 | /** Report an error to the user. */ |
| 240 | static void drd_tool_error_pp(Error* const e) |
| 241 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 242 | switch (VG_(get_error_kind)(e)) |
| 243 | { |
| 244 | case DataRaceErr: { |
| 245 | drd_report_data_race(e, VG_(get_error_extra)(e)); |
| 246 | break; |
| 247 | } |
| 248 | case MutexErr: { |
| 249 | MutexErrInfo* p = (MutexErrInfo*)(VG_(get_error_extra)(e)); |
| 250 | tl_assert(p); |
| 251 | if (p->recursion_count >= 0) |
| 252 | { |
| 253 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 254 | "%s: mutex 0x%lx, recursion count %d, owner %d.\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 255 | VG_(get_error_string)(e), |
| 256 | p->mutex, |
| 257 | p->recursion_count, |
| 258 | p->owner); |
| 259 | } |
| 260 | else |
| 261 | { |
| 262 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 263 | "The object at address 0x%lx is not a mutex.\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 264 | p->mutex); |
| 265 | } |
| 266 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 267 | first_observed(p->mutex); |
| 268 | break; |
| 269 | } |
| 270 | case CondErr: { |
| 271 | CondErrInfo* cdei =(CondErrInfo*)(VG_(get_error_extra)(e)); |
bart | 6b71761 | 2008-03-24 09:29:38 +0000 | [diff] [blame] | 272 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 273 | "%s: cond 0x%lx\n", |
bart | 6b71761 | 2008-03-24 09:29:38 +0000 | [diff] [blame] | 274 | VG_(get_error_string)(e), |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 275 | cdei->cond); |
| 276 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 277 | first_observed(cdei->cond); |
| 278 | break; |
| 279 | } |
| 280 | case CondDestrErr: { |
| 281 | CondDestrErrInfo* cdi = (CondDestrErrInfo*)(VG_(get_error_extra)(e)); |
bart | 6b71761 | 2008-03-24 09:29:38 +0000 | [diff] [blame] | 282 | VG_(message)(Vg_UserMsg, |
bart | 63c92ea | 2009-07-19 17:53:56 +0000 | [diff] [blame] | 283 | "%s: cond 0x%lx, mutex 0x%lx locked by thread %d\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 284 | VG_(get_error_string)(e), |
| 285 | cdi->cond, cdi->mutex, |
bart | 63c92ea | 2009-07-19 17:53:56 +0000 | [diff] [blame] | 286 | cdi->owner); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 287 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 288 | first_observed(cdi->mutex); |
| 289 | break; |
| 290 | } |
| 291 | case CondRaceErr: { |
| 292 | CondRaceErrInfo* cei = (CondRaceErrInfo*)(VG_(get_error_extra)(e)); |
bart | d2c5eae | 2009-02-21 15:27:04 +0000 | [diff] [blame] | 293 | VG_(message)(Vg_UserMsg, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 294 | "Probably a race condition: condition variable 0x%lx has" |
| 295 | " been signaled but the associated mutex 0x%lx is not" |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 296 | " locked by the signalling thread.\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 297 | cei->cond, cei->mutex); |
| 298 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 299 | first_observed(cei->cond); |
| 300 | first_observed(cei->mutex); |
| 301 | break; |
| 302 | } |
| 303 | case CondWaitErr: { |
| 304 | CondWaitErrInfo* cwei = (CondWaitErrInfo*)(VG_(get_error_extra)(e)); |
| 305 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 306 | "%s: condition variable 0x%lx, mutexes 0x%lx and 0x%lx\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 307 | VG_(get_error_string)(e), |
| 308 | cwei->cond, |
| 309 | cwei->mutex1, |
| 310 | cwei->mutex2); |
| 311 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 312 | first_observed(cwei->cond); |
| 313 | first_observed(cwei->mutex1); |
| 314 | first_observed(cwei->mutex2); |
| 315 | break; |
| 316 | } |
| 317 | case SemaphoreErr: { |
| 318 | SemaphoreErrInfo* sei = (SemaphoreErrInfo*)(VG_(get_error_extra)(e)); |
| 319 | tl_assert(sei); |
| 320 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 321 | "%s: semaphore 0x%lx\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 322 | VG_(get_error_string)(e), |
| 323 | sei->semaphore); |
| 324 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 325 | first_observed(sei->semaphore); |
| 326 | break; |
| 327 | } |
| 328 | case BarrierErr: { |
| 329 | BarrierErrInfo* bei = (BarrierErrInfo*)(VG_(get_error_extra)(e)); |
| 330 | tl_assert(bei); |
| 331 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 332 | "%s: barrier 0x%lx\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 333 | VG_(get_error_string)(e), |
| 334 | bei->barrier); |
| 335 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 336 | if (bei->other_context) |
| 337 | { |
| 338 | VG_(message)(Vg_UserMsg, |
bart | 63c92ea | 2009-07-19 17:53:56 +0000 | [diff] [blame] | 339 | "Conflicting wait call by thread %d:\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 340 | bei->other_tid); |
| 341 | VG_(pp_ExeContext)(bei->other_context); |
| 342 | } |
| 343 | first_observed(bei->barrier); |
| 344 | break; |
| 345 | } |
| 346 | case RwlockErr: { |
| 347 | RwlockErrInfo* p = (RwlockErrInfo*)(VG_(get_error_extra)(e)); |
| 348 | tl_assert(p); |
| 349 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 350 | "%s: rwlock 0x%lx.\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 351 | VG_(get_error_string)(e), |
| 352 | p->rwlock); |
| 353 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 354 | first_observed(p->rwlock); |
| 355 | break; |
| 356 | } |
| 357 | case HoldtimeErr: { |
| 358 | HoldtimeErrInfo* p =(HoldtimeErrInfo*)(VG_(get_error_extra)(e)); |
| 359 | tl_assert(p); |
| 360 | tl_assert(p->acquired_at); |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 361 | VG_(message)(Vg_UserMsg, "Acquired at:\n"); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 362 | VG_(pp_ExeContext)(p->acquired_at); |
| 363 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 364 | "Lock on %s 0x%lx was held during %d ms (threshold: %d ms).\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 365 | VG_(get_error_string)(e), |
| 366 | p->synchronization_object, |
| 367 | p->hold_time_ms, |
| 368 | p->threshold_ms); |
| 369 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 370 | first_observed(p->synchronization_object); |
| 371 | break; |
| 372 | } |
| 373 | case GenericErr: { |
| 374 | //GenericErrInfo* gei =(GenericErrInfo*)(VG_(get_error_extra)(e)); |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 375 | VG_(message)(Vg_UserMsg, "%s\n", VG_(get_error_string)(e)); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 376 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 377 | break; |
| 378 | } |
bart | b48bde2 | 2009-07-31 08:26:17 +0000 | [diff] [blame] | 379 | case InvalidThreadId: { |
| 380 | InvalidThreadIdInfo* iti =(InvalidThreadIdInfo*)(VG_(get_error_extra)(e)); |
| 381 | VG_(message)(Vg_UserMsg, |
| 382 | "%s 0x%llx\n", VG_(get_error_string)(e), iti->ptid); |
| 383 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 384 | break; |
| 385 | } |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 386 | case UnimpClReq: { |
| 387 | UnimpClReqInfo* uicr =(UnimpClReqInfo*)(VG_(get_error_extra)(e)); |
| 388 | VG_(message)(Vg_UserMsg, |
| 389 | "The annotation macro %s has not yet been implemented in" |
bart | ffb9d02 | 2009-08-27 06:16:24 +0000 | [diff] [blame] | 390 | " <valgrind/helgrind.h>\n", |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 391 | /*VG_(get_error_string)(e),*/ uicr->descr); |
| 392 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 393 | break; |
| 394 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 395 | default: |
| 396 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 397 | "%s\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 398 | VG_(get_error_string)(e)); |
| 399 | VG_(pp_ExeContext)(VG_(get_error_where)(e)); |
| 400 | break; |
| 401 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 402 | } |
| 403 | |
bart | d2c5eae | 2009-02-21 15:27:04 +0000 | [diff] [blame] | 404 | static UInt drd_tool_error_update_extra(Error* e) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 405 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 406 | switch (VG_(get_error_kind)(e)) |
| 407 | { |
| 408 | case DataRaceErr: |
| 409 | return sizeof(DataRaceErrInfo); |
| 410 | case MutexErr: |
| 411 | return sizeof(MutexErrInfo); |
| 412 | case CondErr: |
| 413 | return sizeof(CondErrInfo); |
| 414 | case CondDestrErr: |
| 415 | return sizeof(CondDestrErrInfo); |
| 416 | case CondRaceErr: |
| 417 | return sizeof(CondRaceErrInfo); |
| 418 | case CondWaitErr: |
| 419 | return sizeof(CondWaitErrInfo); |
| 420 | case SemaphoreErr: |
| 421 | return sizeof(SemaphoreErrInfo); |
| 422 | case BarrierErr: |
| 423 | return sizeof(BarrierErrInfo); |
| 424 | case RwlockErr: |
| 425 | return sizeof(RwlockErrInfo); |
| 426 | case HoldtimeErr: |
| 427 | return sizeof(HoldtimeErrInfo); |
| 428 | case GenericErr: |
| 429 | return sizeof(GenericErrInfo); |
bart | b48bde2 | 2009-07-31 08:26:17 +0000 | [diff] [blame] | 430 | case InvalidThreadId: |
| 431 | return sizeof(InvalidThreadIdInfo); |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 432 | case UnimpClReq: |
| 433 | return sizeof(UnimpClReqInfo); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 434 | default: |
| 435 | tl_assert(False); |
| 436 | break; |
| 437 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 438 | } |
| 439 | |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 440 | /** |
| 441 | * Parse suppression name. |
| 442 | * |
| 443 | * The suppression types recognized by DRD are the same types as the error |
| 444 | * types supported by DRD. So try to match the suppression name against the |
| 445 | * names of DRD error types. |
| 446 | */ |
| 447 | static Bool drd_is_recognized_suppression(Char* const name, Supp* const supp) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 448 | { |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 449 | DrdErrorKind skind = 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 450 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 451 | if (VG_(strcmp)(name, STR_DataRaceErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 452 | skind = DataRaceErr; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 453 | else if (VG_(strcmp)(name, STR_MutexErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 454 | skind = MutexErr; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 455 | else if (VG_(strcmp)(name, STR_CondErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 456 | skind = CondErr; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 457 | else if (VG_(strcmp)(name, STR_CondDestrErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 458 | skind = CondDestrErr; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 459 | else if (VG_(strcmp)(name, STR_CondRaceErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 460 | skind = CondRaceErr; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 461 | else if (VG_(strcmp)(name, STR_CondWaitErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 462 | skind = CondWaitErr; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 463 | else if (VG_(strcmp)(name, STR_SemaphoreErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 464 | skind = SemaphoreErr; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 465 | else if (VG_(strcmp)(name, STR_BarrierErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 466 | skind = BarrierErr; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 467 | else if (VG_(strcmp)(name, STR_RwlockErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 468 | skind = RwlockErr; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 469 | else if (VG_(strcmp)(name, STR_HoldtimeErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 470 | skind = HoldtimeErr; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 471 | else if (VG_(strcmp)(name, STR_GenericErr) == 0) |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 472 | skind = GenericErr; |
bart | b48bde2 | 2009-07-31 08:26:17 +0000 | [diff] [blame] | 473 | else if (VG_(strcmp)(name, STR_InvalidThreadId) == 0) |
| 474 | skind = InvalidThreadId; |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 475 | else if (VG_(strcmp)(name, STR_UnimpClReq) == 0) |
| 476 | skind = UnimpClReq; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 477 | else |
| 478 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 479 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 480 | VG_(set_supp_kind)(supp, skind); |
| 481 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 482 | } |
| 483 | |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 484 | /** |
| 485 | * Read additional suppression information from the suppression file. |
| 486 | * |
| 487 | * None of the suppression patterns recognized by DRD has 'extra' lines |
| 488 | * of information in the suppression file, so just return True to indicate |
| 489 | * that reading the 'extra' lines succeeded. |
| 490 | */ |
bart | 246fbf2 | 2009-02-15 14:46:17 +0000 | [diff] [blame] | 491 | static |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 492 | Bool drd_read_extra_suppression_info(Int fd, Char** bufpp, |
| 493 | SizeT* nBufp, Supp* supp) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 494 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 495 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 496 | } |
| 497 | |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 498 | /** |
| 499 | * Determine whether or not the types of the given error message and the |
| 500 | * given suppression match. |
| 501 | */ |
| 502 | static Bool drd_error_matches_suppression(Error* const e, Supp* const supp) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 503 | { |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 504 | return VG_(get_supp_kind)(supp) == VG_(get_error_kind)(e); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 505 | } |
| 506 | |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 507 | static Char* drd_get_error_name(Error* e) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 508 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 509 | switch (VG_(get_error_kind)(e)) |
| 510 | { |
| 511 | case DataRaceErr: return VGAPPEND(STR_, DataRaceErr); |
| 512 | case MutexErr: return VGAPPEND(STR_, MutexErr); |
| 513 | case CondErr: return VGAPPEND(STR_, CondErr); |
| 514 | case CondDestrErr: return VGAPPEND(STR_, CondDestrErr); |
| 515 | case CondRaceErr: return VGAPPEND(STR_, CondRaceErr); |
| 516 | case CondWaitErr: return VGAPPEND(STR_, CondWaitErr); |
| 517 | case SemaphoreErr: return VGAPPEND(STR_, SemaphoreErr); |
| 518 | case BarrierErr: return VGAPPEND(STR_, BarrierErr); |
| 519 | case RwlockErr: return VGAPPEND(STR_, RwlockErr); |
| 520 | case HoldtimeErr: return VGAPPEND(STR_, HoldtimeErr); |
| 521 | case GenericErr: return VGAPPEND(STR_, GenericErr); |
bart | b48bde2 | 2009-07-31 08:26:17 +0000 | [diff] [blame] | 522 | case InvalidThreadId: return VGAPPEND(STR_, InvalidThreadId); |
bart | 66f196d | 2009-08-15 10:50:35 +0000 | [diff] [blame] | 523 | case UnimpClReq: return VGAPPEND(STR_, UnimpClReq); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 524 | default: |
| 525 | tl_assert(0); |
| 526 | } |
| 527 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 528 | } |
| 529 | |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 530 | /** |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 531 | * Return extra suppression information. |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 532 | * |
| 533 | * Invoked while printing a suppression pattern because the user |
| 534 | * specified --gen-suppressions=yes or all on the command line. DRD does not |
| 535 | * define any 'extra' suppression information. |
| 536 | */ |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 537 | static |
| 538 | Bool drd_get_extra_suppression_info(Error* e, |
| 539 | /*OUT*/Char* buf, Int nBuf) |
| 540 | { |
| 541 | return False; |
| 542 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 543 | |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 544 | /** Tell the Valgrind core about DRD's error handlers. */ |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 545 | void DRD_(register_error_handlers)(void) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 546 | { |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 547 | VG_(needs_tool_errors)(drd_compare_error_contexts, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 548 | drd_tool_error_before_pp, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 549 | drd_tool_error_pp, |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 550 | False, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 551 | drd_tool_error_update_extra, |
bart | 61d36ff | 2009-07-27 14:17:33 +0000 | [diff] [blame] | 552 | drd_is_recognized_suppression, |
| 553 | drd_read_extra_suppression_info, |
| 554 | drd_error_matches_suppression, |
| 555 | drd_get_error_name, |
sewardj | 588adef | 2009-08-15 22:41:51 +0000 | [diff] [blame] | 556 | drd_get_extra_suppression_info); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 557 | } |