blob: 4b1c2fad9d6c4737d6a7827ed2601d9d9b8899d2 [file] [log] [blame]
bartbedfd232009-03-26 19:07:15 +00001/* -*- mode: C; c-basic-offset: 3; -*- */
sewardjaf44c822007-11-25 14:01:38 +00002/*
bart86562bd2009-02-16 19:43:56 +00003 This file is part of drd, a thread error detector.
sewardjaf44c822007-11-25 14:01:38 +00004
bart86562bd2009-02-16 19:43:56 +00005 Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>.
sewardjaf44c822007-11-25 14:01:38 +00006
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
bart886b87c2008-06-28 13:40:41 +000026#include "drd_clientobj.h" /* struct mutex_info */
sewardjaf44c822007-11-25 14:01:38 +000027#include "drd_error.h"
28#include "drd_malloc_wrappers.h"
bart886b87c2008-06-28 13:40:41 +000029#include "drd_mutex.h"
30#include "drd_suppression.h" /* drd_start_suppression() */
31#include "pub_drd_bitmap.h" /* LHS_W, ... */
sewardjaf44c822007-11-25 14:01:38 +000032#include "pub_tool_vki.h"
33#include "pub_tool_basics.h"
bart886b87c2008-06-28 13:40:41 +000034#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)() */
sewardjaf44c822007-11-25 14:01:38 +000038#include "pub_tool_machine.h"
bart886b87c2008-06-28 13:40:41 +000039#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)() */
sewardjaf44c822007-11-25 14:01:38 +000042
43
bart16d76e52008-03-18 17:08:08 +000044/* Local variables. */
45
bartd2c5eae2009-02-21 15:27:04 +000046static Bool s_show_conflicting_segments = True;
bart16d76e52008-03-18 17:08:08 +000047
48
bart246fbf22009-02-15 14:46:17 +000049void DRD_(set_show_conflicting_segments)(const Bool scs)
bart16d76e52008-03-18 17:08:08 +000050{
bartbedfd232009-03-26 19:07:15 +000051 s_show_conflicting_segments = scs;
bart16d76e52008-03-18 17:08:08 +000052}
53
bart246fbf22009-02-15 14:46:17 +000054/**
bart61d36ff2009-07-27 14:17:33 +000055 * Describe the client address a as good as possible, putting the result in ai.
bart886b87c2008-06-28 13:40:41 +000056 */
bartff1252a2008-03-16 17:27:25 +000057static
bart61d36ff2009-07-27 14:17:33 +000058void describe_malloced_addr(Addr const a, AddrInfo* const ai)
sewardjaf44c822007-11-25 14:01:38 +000059{
bart61d36ff2009-07-27 14:17:33 +000060 Addr heap_block_start;
sewardjaf44c822007-11-25 14:01:38 +000061
bart61d36ff2009-07-27 14:17:33 +000062 if (DRD_(heap_addrinfo)(a, &heap_block_start, &ai->size, &ai->lastchange))
bartbedfd232009-03-26 19:07:15 +000063 {
64 ai->akind = eMallocd;
bart61d36ff2009-07-27 14:17:33 +000065 ai->rwoffset = a - heap_block_start;
bartbedfd232009-03-26 19:07:15 +000066 }
67 else
68 {
69 ai->akind = eUnknown;
70 }
sewardjaf44c822007-11-25 14:01:38 +000071}
72
bart246fbf22009-02-15 14:46:17 +000073/**
bart61d36ff2009-07-27 14:17:33 +000074 * 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.
bart886b87c2008-06-28 13:40:41 +000077 */
bartd2c5eae2009-02-21 15:27:04 +000078static void first_observed(const Addr obj)
bart886b87c2008-06-28 13:40:41 +000079{
bartbedfd232009-03-26 19:07:15 +000080 DrdClientobj* cl;
bart886b87c2008-06-28 13:40:41 +000081
bartbedfd232009-03-26 19:07:15 +000082 cl = DRD_(clientobj_get_any)(obj);
83 if (cl)
84 {
85 tl_assert(cl->any.first_observed_at);
86 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +000087 "%s 0x%lx was first observed at:\n",
bartbedfd232009-03-26 19:07:15 +000088 DRD_(clientobj_type_name)(cl->any.type),
89 obj);
90 VG_(pp_ExeContext)(cl->any.first_observed_at);
91 }
bart886b87c2008-06-28 13:40:41 +000092}
93
sewardjaf44c822007-11-25 14:01:38 +000094static
bartd2c5eae2009-02-21 15:27:04 +000095void drd_report_data_race(Error* const err, const DataRaceErrInfo* const dri)
sewardjaf44c822007-11-25 14:01:38 +000096{
bartbedfd232009-03-26 19:07:15 +000097 AddrInfo ai;
sewardj1e29ebc2009-07-15 14:49:17 +000098
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) );
sewardjaf44c822007-11-25 14:01:38 +0000105
bartbedfd232009-03-26 19:07:15 +0000106 tl_assert(dri);
107 tl_assert(dri->addr);
108 tl_assert(dri->size > 0);
109 tl_assert(descr1);
110 tl_assert(descr2);
bartb515eb12008-03-07 18:52:38 +0000111
sewardj1e29ebc2009-07-15 14:49:17 +0000112 (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)
bartbedfd232009-03-26 19:07:15 +0000133 {
sewardj1e29ebc2009-07-15 14:49:17 +0000134 /* No. Do Plan B. */
bart61d36ff2009-07-27 14:17:33 +0000135 describe_malloced_addr(dri->addr, &ai);
bartbedfd232009-03-26 19:07:15 +0000136 }
137 VG_(message)(Vg_UserMsg,
bart63c92ea2009-07-19 17:53:56 +0000138 "Conflicting %s by thread %d at 0x%08lx size %ld\n",
bartbedfd232009-03-26 19:07:15 +0000139 dri->access_type == eStore ? "store" : "load",
bartbedfd232009-03-26 19:07:15 +0000140 dri->tid,
141 dri->addr,
142 dri->size);
143 VG_(pp_ExeContext)(VG_(get_error_where)(err));
sewardj1e29ebc2009-07-15 14:49:17 +0000144 if (descr1 != NULL)
bartbedfd232009-03-26 19:07:15 +0000145 {
sewardj1e29ebc2009-07-15 14:49:17 +0000146 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));
bartbedfd232009-03-26 19:07:15 +0000149 }
150 else if (ai.akind == eMallocd && ai.lastchange)
151 {
bartfca00e52008-07-09 12:43:35 +0000152 VG_(message)(Vg_UserMsg,
bartbedfd232009-03-26 19:07:15 +0000153 "Address 0x%lx is at offset %ld from 0x%lx."
sewardj1e29ebc2009-07-15 14:49:17 +0000154 " Allocation context:\n",
bartbedfd232009-03-26 19:07:15 +0000155 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;
bartf993b872008-04-01 18:19:50 +0000162
sewardje3f1e592009-07-31 09:41:29 +0000163 sect_kind = VG_(DebugInfo_sect_kind)(sect_name, sizeof(sect_name),
164 dri->addr);
bartbedfd232009-03-26 19:07:15 +0000165 if (sect_kind != Vg_SectUnknown)
166 {
167 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000168 "Allocation context: %s section of %s\n",
bartbedfd232009-03-26 19:07:15 +0000169 VG_(pp_SectKind)(sect_kind),
170 sect_name);
171 }
172 else
173 {
sewardj1e29ebc2009-07-15 14:49:17 +0000174 VG_(message)(Vg_UserMsg, "Allocation context: unknown.\n");
bartbedfd232009-03-26 19:07:15 +0000175 }
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
sewardj1e29ebc2009-07-15 14:49:17 +0000184 if (descr2)
185 VG_(deleteXA)(descr2);
186 if (descr1)
187 VG_(deleteXA)(descr1);
sewardjaf44c822007-11-25 14:01:38 +0000188}
189
bart61d36ff2009-07-27 14:17:33 +0000190/**
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
193 * repeatedly are only printed once. This function is only called by the core
194 * if the error kind of e1 and e2 matches and if the ExeContext's of e1 and
195 * e2 also match.
196 */
197static Bool drd_compare_error_contexts(VgRes res, Error* e1, Error* e2)
sewardjaf44c822007-11-25 14:01:38 +0000198{
bartb80fa962009-07-31 08:45:02 +0000199 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 }
bart94fb8d22009-07-31 18:45:49 +0000210 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 }
bartb80fa962009-07-31 08:45:02 +0000216 default:
217 return True;
218 }
sewardjaf44c822007-11-25 14:01:38 +0000219}
220
bart61d36ff2009-07-27 14:17:33 +0000221/**
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 */
sewardj1e29ebc2009-07-15 14:49:17 +0000225static void drd_tool_error_before_pp(Error* const e)
226{
bartd45d9952009-05-31 18:53:54 +0000227 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 {
sewardj1e29ebc2009-07-15 14:49:17 +0000234 VG_(umsg)("%s:\n", DRD_(thread_get_name)(*err_extra));
bartd45d9952009-05-31 18:53:54 +0000235 s_last_tid_printed = *err_extra;
236 }
bart61d36ff2009-07-27 14:17:33 +0000237}
bartd45d9952009-05-31 18:53:54 +0000238
bart61d36ff2009-07-27 14:17:33 +0000239/** Report an error to the user. */
240static void drd_tool_error_pp(Error* const e)
241{
bartbedfd232009-03-26 19:07:15 +0000242 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,
sewardj1e29ebc2009-07-15 14:49:17 +0000254 "%s: mutex 0x%lx, recursion count %d, owner %d.\n",
bartbedfd232009-03-26 19:07:15 +0000255 VG_(get_error_string)(e),
256 p->mutex,
257 p->recursion_count,
258 p->owner);
259 }
260 else
261 {
262 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000263 "The object at address 0x%lx is not a mutex.\n",
bartbedfd232009-03-26 19:07:15 +0000264 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));
bart6b717612008-03-24 09:29:38 +0000272 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000273 "%s: cond 0x%lx\n",
bart6b717612008-03-24 09:29:38 +0000274 VG_(get_error_string)(e),
bartbedfd232009-03-26 19:07:15 +0000275 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));
bart6b717612008-03-24 09:29:38 +0000282 VG_(message)(Vg_UserMsg,
bart63c92ea2009-07-19 17:53:56 +0000283 "%s: cond 0x%lx, mutex 0x%lx locked by thread %d\n",
bartbedfd232009-03-26 19:07:15 +0000284 VG_(get_error_string)(e),
285 cdi->cond, cdi->mutex,
bart63c92ea2009-07-19 17:53:56 +0000286 cdi->owner);
bartbedfd232009-03-26 19:07:15 +0000287 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));
bartd2c5eae2009-02-21 15:27:04 +0000293 VG_(message)(Vg_UserMsg,
bartbedfd232009-03-26 19:07:15 +0000294 "Probably a race condition: condition variable 0x%lx has"
295 " been signaled but the associated mutex 0x%lx is not"
sewardj1e29ebc2009-07-15 14:49:17 +0000296 " locked by the signalling thread.\n",
bartbedfd232009-03-26 19:07:15 +0000297 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,
sewardj1e29ebc2009-07-15 14:49:17 +0000306 "%s: condition variable 0x%lx, mutexes 0x%lx and 0x%lx\n",
bartbedfd232009-03-26 19:07:15 +0000307 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,
sewardj1e29ebc2009-07-15 14:49:17 +0000321 "%s: semaphore 0x%lx\n",
bartbedfd232009-03-26 19:07:15 +0000322 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,
sewardj1e29ebc2009-07-15 14:49:17 +0000332 "%s: barrier 0x%lx\n",
bartbedfd232009-03-26 19:07:15 +0000333 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,
bart63c92ea2009-07-19 17:53:56 +0000339 "Conflicting wait call by thread %d:\n",
bartbedfd232009-03-26 19:07:15 +0000340 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,
sewardj1e29ebc2009-07-15 14:49:17 +0000350 "%s: rwlock 0x%lx.\n",
bartbedfd232009-03-26 19:07:15 +0000351 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);
sewardj1e29ebc2009-07-15 14:49:17 +0000361 VG_(message)(Vg_UserMsg, "Acquired at:\n");
bartbedfd232009-03-26 19:07:15 +0000362 VG_(pp_ExeContext)(p->acquired_at);
363 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000364 "Lock on %s 0x%lx was held during %d ms (threshold: %d ms).\n",
bartbedfd232009-03-26 19:07:15 +0000365 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));
sewardj1e29ebc2009-07-15 14:49:17 +0000375 VG_(message)(Vg_UserMsg, "%s\n", VG_(get_error_string)(e));
bartbedfd232009-03-26 19:07:15 +0000376 VG_(pp_ExeContext)(VG_(get_error_where)(e));
377 break;
378 }
bartb48bde22009-07-31 08:26:17 +0000379 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 }
bart66f196d2009-08-15 10:50:35 +0000386 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"
390 " <helgrind/helgrind.h>\n",
391 /*VG_(get_error_string)(e),*/ uicr->descr);
392 VG_(pp_ExeContext)(VG_(get_error_where)(e));
393 break;
394 }
bartbedfd232009-03-26 19:07:15 +0000395 default:
396 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000397 "%s\n",
bartbedfd232009-03-26 19:07:15 +0000398 VG_(get_error_string)(e));
399 VG_(pp_ExeContext)(VG_(get_error_where)(e));
400 break;
401 }
sewardjaf44c822007-11-25 14:01:38 +0000402}
403
bartd2c5eae2009-02-21 15:27:04 +0000404static UInt drd_tool_error_update_extra(Error* e)
sewardjaf44c822007-11-25 14:01:38 +0000405{
bartbedfd232009-03-26 19:07:15 +0000406 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);
bartb48bde22009-07-31 08:26:17 +0000430 case InvalidThreadId:
431 return sizeof(InvalidThreadIdInfo);
bart66f196d2009-08-15 10:50:35 +0000432 case UnimpClReq:
433 return sizeof(UnimpClReqInfo);
bartbedfd232009-03-26 19:07:15 +0000434 default:
435 tl_assert(False);
436 break;
437 }
sewardjaf44c822007-11-25 14:01:38 +0000438}
439
bart61d36ff2009-07-27 14:17:33 +0000440/**
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 */
447static Bool drd_is_recognized_suppression(Char* const name, Supp* const supp)
sewardjaf44c822007-11-25 14:01:38 +0000448{
bart61d36ff2009-07-27 14:17:33 +0000449 DrdErrorKind skind = 0;
sewardjaf44c822007-11-25 14:01:38 +0000450
bartbedfd232009-03-26 19:07:15 +0000451 if (VG_(strcmp)(name, STR_DataRaceErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000452 skind = DataRaceErr;
bartbedfd232009-03-26 19:07:15 +0000453 else if (VG_(strcmp)(name, STR_MutexErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000454 skind = MutexErr;
bartbedfd232009-03-26 19:07:15 +0000455 else if (VG_(strcmp)(name, STR_CondErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000456 skind = CondErr;
bartbedfd232009-03-26 19:07:15 +0000457 else if (VG_(strcmp)(name, STR_CondDestrErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000458 skind = CondDestrErr;
bartbedfd232009-03-26 19:07:15 +0000459 else if (VG_(strcmp)(name, STR_CondRaceErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000460 skind = CondRaceErr;
bartbedfd232009-03-26 19:07:15 +0000461 else if (VG_(strcmp)(name, STR_CondWaitErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000462 skind = CondWaitErr;
bartbedfd232009-03-26 19:07:15 +0000463 else if (VG_(strcmp)(name, STR_SemaphoreErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000464 skind = SemaphoreErr;
bartbedfd232009-03-26 19:07:15 +0000465 else if (VG_(strcmp)(name, STR_BarrierErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000466 skind = BarrierErr;
bartbedfd232009-03-26 19:07:15 +0000467 else if (VG_(strcmp)(name, STR_RwlockErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000468 skind = RwlockErr;
bartbedfd232009-03-26 19:07:15 +0000469 else if (VG_(strcmp)(name, STR_HoldtimeErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000470 skind = HoldtimeErr;
bartbedfd232009-03-26 19:07:15 +0000471 else if (VG_(strcmp)(name, STR_GenericErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000472 skind = GenericErr;
bartb48bde22009-07-31 08:26:17 +0000473 else if (VG_(strcmp)(name, STR_InvalidThreadId) == 0)
474 skind = InvalidThreadId;
bart66f196d2009-08-15 10:50:35 +0000475 else if (VG_(strcmp)(name, STR_UnimpClReq) == 0)
476 skind = UnimpClReq;
bartbedfd232009-03-26 19:07:15 +0000477 else
478 return False;
sewardjaf44c822007-11-25 14:01:38 +0000479
bartbedfd232009-03-26 19:07:15 +0000480 VG_(set_supp_kind)(supp, skind);
481 return True;
sewardjaf44c822007-11-25 14:01:38 +0000482}
483
bart61d36ff2009-07-27 14:17:33 +0000484/**
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 */
bart246fbf22009-02-15 14:46:17 +0000491static
bart61d36ff2009-07-27 14:17:33 +0000492Bool drd_read_extra_suppression_info(Int fd, Char** bufpp,
493 SizeT* nBufp, Supp* supp)
sewardjaf44c822007-11-25 14:01:38 +0000494{
bartbedfd232009-03-26 19:07:15 +0000495 return True;
sewardjaf44c822007-11-25 14:01:38 +0000496}
497
bart61d36ff2009-07-27 14:17:33 +0000498/**
499 * Determine whether or not the types of the given error message and the
500 * given suppression match.
501 */
502static Bool drd_error_matches_suppression(Error* const e, Supp* const supp)
sewardjaf44c822007-11-25 14:01:38 +0000503{
bart61d36ff2009-07-27 14:17:33 +0000504 return VG_(get_supp_kind)(supp) == VG_(get_error_kind)(e);
sewardjaf44c822007-11-25 14:01:38 +0000505}
506
bart61d36ff2009-07-27 14:17:33 +0000507static Char* drd_get_error_name(Error* e)
sewardjaf44c822007-11-25 14:01:38 +0000508{
bartbedfd232009-03-26 19:07:15 +0000509 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);
bartb48bde22009-07-31 08:26:17 +0000522 case InvalidThreadId: return VGAPPEND(STR_, InvalidThreadId);
bart66f196d2009-08-15 10:50:35 +0000523 case UnimpClReq: return VGAPPEND(STR_, UnimpClReq);
bartbedfd232009-03-26 19:07:15 +0000524 default:
525 tl_assert(0);
526 }
527 return 0;
sewardjaf44c822007-11-25 14:01:38 +0000528}
529
bart61d36ff2009-07-27 14:17:33 +0000530/**
531 * Print extra suppression information.
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 */
537static void drd_print_extra_suppression_info(Error* e)
bart246fbf22009-02-15 14:46:17 +0000538{ }
sewardjaf44c822007-11-25 14:01:38 +0000539
bart61d36ff2009-07-27 14:17:33 +0000540/** Tell the Valgrind core about DRD's error handlers. */
bart1335ecc2009-02-14 16:10:53 +0000541void DRD_(register_error_handlers)(void)
sewardjaf44c822007-11-25 14:01:38 +0000542{
bart61d36ff2009-07-27 14:17:33 +0000543 VG_(needs_tool_errors)(drd_compare_error_contexts,
sewardj1e29ebc2009-07-15 14:49:17 +0000544 drd_tool_error_before_pp,
bartbedfd232009-03-26 19:07:15 +0000545 drd_tool_error_pp,
bartd45d9952009-05-31 18:53:54 +0000546 False,
bartbedfd232009-03-26 19:07:15 +0000547 drd_tool_error_update_extra,
bart61d36ff2009-07-27 14:17:33 +0000548 drd_is_recognized_suppression,
549 drd_read_extra_suppression_info,
550 drd_error_matches_suppression,
551 drd_get_error_name,
552 drd_print_extra_suppression_info);
sewardjaf44c822007-11-25 14:01:38 +0000553}