blob: eeea48445357f3b69f7b81f9f27424b9a5493e63 [file] [log] [blame]
bart922304f2011-03-13 12:02:44 +00001/* -*- mode: C; c-basic-offset: 3; indent-tabs-mode: nil; -*- */
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
bart922304f2011-03-13 12:02:44 +00005 Copyright (C) 2006-2011 Bart Van Assche <bvanassche@acm.org>.
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) */
bartb92ff0f2011-10-08 08:29:29 +000040#include "pub_tool_options.h" /* VG_(clo_xml) */
bart886b87c2008-06-28 13:40:41 +000041#include "pub_tool_threadstate.h" /* VG_(get_pthread_id)() */
42#include "pub_tool_tooliface.h" /* VG_(needs_tool_errors)() */
sewardjaf44c822007-11-25 14:01:38 +000043
44
barte7086002011-10-11 19:08:39 +000045/* Local function declarations. */
46
47static Char* drd_get_error_name(Error* e);
48
49
bart16d76e52008-03-18 17:08:08 +000050/* Local variables. */
51
bartd2c5eae2009-02-21 15:27:04 +000052static Bool s_show_conflicting_segments = True;
bart16d76e52008-03-18 17:08:08 +000053
54
bart246fbf22009-02-15 14:46:17 +000055void DRD_(set_show_conflicting_segments)(const Bool scs)
bart16d76e52008-03-18 17:08:08 +000056{
bartbedfd232009-03-26 19:07:15 +000057 s_show_conflicting_segments = scs;
bart16d76e52008-03-18 17:08:08 +000058}
59
bartb92ff0f2011-10-08 08:29:29 +000060void DRD_(trace_msg)(const char* format, ...)
61{
62 va_list vargs;
63 va_start(vargs, format);
barte7086002011-10-11 19:08:39 +000064 if (VG_(clo_xml)) {
65 VG_(printf_xml)("<traceline>\n ");
66 VG_(vprintf_xml)(format, vargs);
67 VG_(printf_xml)("</traceline>\n");
68 } else {
69 VG_(vmessage)(Vg_UserMsg, format, vargs);
70 }
71 va_end(vargs);
72}
73
74/**
75 * Emit error message detail in the format requested by the user.
76 */
77static void print_err_detail(const char* format, ...) PRINTF_CHECK(1, 2);
78static void print_err_detail(const char* format, ...)
79{
80 va_list vargs;
81 va_start(vargs, format);
82 if (VG_(clo_xml))
83 VG_(vprintf_xml)(format, vargs);
84 else
85 VG_(vmessage)(Vg_UserMsg, format, vargs);
bartb92ff0f2011-10-08 08:29:29 +000086 va_end(vargs);
87}
88
bart246fbf22009-02-15 14:46:17 +000089/**
bart61d36ff2009-07-27 14:17:33 +000090 * Describe the client address a as good as possible, putting the result in ai.
bart886b87c2008-06-28 13:40:41 +000091 */
bartff1252a2008-03-16 17:27:25 +000092static
bart61d36ff2009-07-27 14:17:33 +000093void describe_malloced_addr(Addr const a, AddrInfo* const ai)
sewardjaf44c822007-11-25 14:01:38 +000094{
bart61d36ff2009-07-27 14:17:33 +000095 Addr heap_block_start;
sewardjaf44c822007-11-25 14:01:38 +000096
bart61d36ff2009-07-27 14:17:33 +000097 if (DRD_(heap_addrinfo)(a, &heap_block_start, &ai->size, &ai->lastchange))
bartbedfd232009-03-26 19:07:15 +000098 {
99 ai->akind = eMallocd;
bart61d36ff2009-07-27 14:17:33 +0000100 ai->rwoffset = a - heap_block_start;
bartbedfd232009-03-26 19:07:15 +0000101 }
102 else
103 {
104 ai->akind = eUnknown;
105 }
sewardjaf44c822007-11-25 14:01:38 +0000106}
107
bart246fbf22009-02-15 14:46:17 +0000108/**
bart61d36ff2009-07-27 14:17:33 +0000109 * Report where a client synchronization object has been observed for the first
110 * time. The printed call stack will either refer to a pthread_*_init() or a
111 * pthread_*lock() call.
bart886b87c2008-06-28 13:40:41 +0000112 */
bartd2c5eae2009-02-21 15:27:04 +0000113static void first_observed(const Addr obj)
bart886b87c2008-06-28 13:40:41 +0000114{
bartbedfd232009-03-26 19:07:15 +0000115 DrdClientobj* cl;
bart886b87c2008-06-28 13:40:41 +0000116
bartbedfd232009-03-26 19:07:15 +0000117 cl = DRD_(clientobj_get_any)(obj);
barte7086002011-10-11 19:08:39 +0000118 if (cl) {
bartbedfd232009-03-26 19:07:15 +0000119 tl_assert(cl->any.first_observed_at);
barte7086002011-10-11 19:08:39 +0000120 if (VG_(clo_xml)) {
121 print_err_detail(" <first_observed_at>\n"
122 " <what>%pS</what>\n"
123 " <address>0x%lx</address>\n",
124 DRD_(clientobj_type_name)(cl->any.type), obj);
125 VG_(pp_ExeContext)(cl->any.first_observed_at);
126 print_err_detail(" </first_observed_at>\n");
127 } else {
128 print_err_detail("%s 0x%lx was first observed at:\n",
129 DRD_(clientobj_type_name)(cl->any.type), obj);
130 VG_(pp_ExeContext)(cl->any.first_observed_at);
131 }
bartbedfd232009-03-26 19:07:15 +0000132 }
bart886b87c2008-06-28 13:40:41 +0000133}
134
sewardjaf44c822007-11-25 14:01:38 +0000135static
bartd2c5eae2009-02-21 15:27:04 +0000136void drd_report_data_race(Error* const err, const DataRaceErrInfo* const dri)
sewardjaf44c822007-11-25 14:01:38 +0000137{
barte7086002011-10-11 19:08:39 +0000138 const Bool xml = VG_(clo_xml);
139 const char* const what_prefix = xml ? " <what>" : "";
140 const char* const what_suffix = xml ? "</what>" : "";
bartca7285e2011-10-13 16:42:49 +0000141 const char* const auxwhat_prefix = xml ? " <auxwhat>" : "";
142 const char* const auxwhat_suffix = xml ? "</auxwhat>" : "";
barte7086002011-10-11 19:08:39 +0000143 const char* const indent = xml ? " " : "";
bartbedfd232009-03-26 19:07:15 +0000144 AddrInfo ai;
sewardj1e29ebc2009-07-15 14:49:17 +0000145
146 XArray* /* of HChar */ descr1
147 = VG_(newXA)( VG_(malloc), "drd.error.drdr2.1",
148 VG_(free), sizeof(HChar) );
149 XArray* /* of HChar */ descr2
150 = VG_(newXA)( VG_(malloc), "drd.error.drdr2.2",
151 VG_(free), sizeof(HChar) );
sewardjaf44c822007-11-25 14:01:38 +0000152
bartbedfd232009-03-26 19:07:15 +0000153 tl_assert(dri);
154 tl_assert(dri->addr);
155 tl_assert(dri->size > 0);
156 tl_assert(descr1);
157 tl_assert(descr2);
bartb515eb12008-03-07 18:52:38 +0000158
sewardj1e29ebc2009-07-15 14:49:17 +0000159 (void) VG_(get_data_description)(descr1, descr2, dri->addr);
160 /* If there's nothing in descr1/2, free them. Why is it safe to to
161 VG_(indexXA) at zero here? Because VG_(get_data_description)
162 guarantees to zero terminate descr1/2 regardless of the outcome
163 of the call. So there's always at least one element in each XA
164 after the call.
165 */
166 if (0 == VG_(strlen)( VG_(indexXA)( descr1, 0 ))) {
167 VG_(deleteXA)( descr1 );
168 descr1 = NULL;
169 }
170 if (0 == VG_(strlen)( VG_(indexXA)( descr2, 0 ))) {
171 VG_(deleteXA)( descr2 );
172 descr2 = NULL;
173 }
174 /* Assume (assert) that VG_(get_data_description) fills in descr1
175 before it fills in descr2 */
176 if (descr1 == NULL)
177 tl_assert(descr2 == NULL);
178 /* So anyway. Do we have something useful? */
179 if (descr1 == NULL)
bartbedfd232009-03-26 19:07:15 +0000180 {
sewardj1e29ebc2009-07-15 14:49:17 +0000181 /* No. Do Plan B. */
bart61d36ff2009-07-27 14:17:33 +0000182 describe_malloced_addr(dri->addr, &ai);
bartbedfd232009-03-26 19:07:15 +0000183 }
barte7086002011-10-11 19:08:39 +0000184
185 print_err_detail("%sConflicting %s by thread %d at 0x%08lx size %ld%s\n",
186 what_prefix, dri->access_type == eStore ? "store" : "load",
187 dri->tid, dri->addr, dri->size, what_suffix);
188
bartbedfd232009-03-26 19:07:15 +0000189 VG_(pp_ExeContext)(VG_(get_error_where)(err));
barte7086002011-10-11 19:08:39 +0000190 if (descr1 != NULL) {
191 print_err_detail("%s%s\n", indent, (HChar*)VG_(indexXA)(descr1, 0));
sewardj1e29ebc2009-07-15 14:49:17 +0000192 if (descr2 != NULL)
barte7086002011-10-11 19:08:39 +0000193 print_err_detail("%s%s\n", indent, (HChar*)VG_(indexXA)(descr2, 0));
194 } else if (ai.akind == eMallocd && ai.lastchange) {
bartca7285e2011-10-13 16:42:49 +0000195 print_err_detail("%sAddress 0x%lx is at offset %ld from 0x%lx.%s%s",
196 auxwhat_prefix, dri->addr, ai.rwoffset,
197 dri->addr - ai.rwoffset, auxwhat_suffix,
198 xml ? "\n" : "");
barte7086002011-10-11 19:08:39 +0000199 if (xml)
bartca7285e2011-10-13 16:42:49 +0000200 print_err_detail(" <allocation_context>\n");
barte7086002011-10-11 19:08:39 +0000201 else
202 print_err_detail(" Allocation context:\n");
bartbedfd232009-03-26 19:07:15 +0000203 VG_(pp_ExeContext)(ai.lastchange);
barte7086002011-10-11 19:08:39 +0000204 if (xml)
bartca7285e2011-10-13 16:42:49 +0000205 print_err_detail(" </allocation_context>\n");
barte7086002011-10-11 19:08:39 +0000206 } else {
bartbedfd232009-03-26 19:07:15 +0000207 char sect_name[64];
208 VgSectKind sect_kind;
bartf993b872008-04-01 18:19:50 +0000209
sewardje3f1e592009-07-31 09:41:29 +0000210 sect_kind = VG_(DebugInfo_sect_kind)(sect_name, sizeof(sect_name),
211 dri->addr);
bartca7285e2011-10-13 16:42:49 +0000212 if (sect_kind != Vg_SectUnknown) {
213 print_err_detail("%sAllocation context: %ps section of %ps%s\n",
214 auxwhat_prefix, VG_(pp_SectKind)(sect_kind),
215 sect_name, auxwhat_suffix);
barte7086002011-10-11 19:08:39 +0000216 } else {
bartca7285e2011-10-13 16:42:49 +0000217 print_err_detail("%sAllocation context: unknown.%s\n",
218 auxwhat_prefix, auxwhat_suffix);
bartbedfd232009-03-26 19:07:15 +0000219 }
220 }
221 if (s_show_conflicting_segments)
222 {
223 DRD_(thread_report_conflicting_segments)(dri->tid,
224 dri->addr, dri->size,
225 dri->access_type);
226 }
227
sewardj1e29ebc2009-07-15 14:49:17 +0000228 if (descr2)
229 VG_(deleteXA)(descr2);
230 if (descr1)
231 VG_(deleteXA)(descr1);
sewardjaf44c822007-11-25 14:01:38 +0000232}
233
bart61d36ff2009-07-27 14:17:33 +0000234/**
235 * Compare two error contexts. The core function VG_(maybe_record_error)()
236 * calls this function to compare error contexts such that errors that occur
bart31b983d2010-02-21 14:52:59 +0000237 * repeatedly are only printed once. This function is only called by the core
bart61d36ff2009-07-27 14:17:33 +0000238 * if the error kind of e1 and e2 matches and if the ExeContext's of e1 and
239 * e2 also match.
240 */
241static Bool drd_compare_error_contexts(VgRes res, Error* e1, Error* e2)
sewardjaf44c822007-11-25 14:01:38 +0000242{
bartb80fa962009-07-31 08:45:02 +0000243 tl_assert(VG_(get_error_kind)(e1) == VG_(get_error_kind)(e2));
244
245 switch (VG_(get_error_kind)(e1))
246 {
247 case DataRaceErr:
248 {
249 const DataRaceErrInfo* const dri1 = VG_(get_error_extra)(e1);
250 const DataRaceErrInfo* const dri2 = VG_(get_error_extra)(e2);
251 return dri1->access_type == dri2->access_type
252 && dri1->size == dri2->size;
253 }
bart94fb8d22009-07-31 18:45:49 +0000254 case MutexErr:
255 {
256 const MutexErrInfo* const mei1 = VG_(get_error_extra)(e1);
257 const MutexErrInfo* const mei2 = VG_(get_error_extra)(e2);
258 return mei1->mutex == mei2->mutex;
259 }
bartb80fa962009-07-31 08:45:02 +0000260 default:
261 return True;
262 }
sewardjaf44c822007-11-25 14:01:38 +0000263}
264
bart61d36ff2009-07-27 14:17:33 +0000265/**
266 * Called by the core just before an error message will be printed. Used by
267 * DRD to print the thread number as a preamble.
268 */
sewardj1e29ebc2009-07-15 14:49:17 +0000269static void drd_tool_error_before_pp(Error* const e)
270{
bartd45d9952009-05-31 18:53:54 +0000271 static DrdThreadId s_last_tid_printed = 1;
272 DrdThreadId* err_extra;
273
274 err_extra = VG_(get_error_extra)(e);
275
barte7086002011-10-11 19:08:39 +0000276 if (err_extra && *err_extra != s_last_tid_printed && !VG_(clo_xml)) {
sewardj1e29ebc2009-07-15 14:49:17 +0000277 VG_(umsg)("%s:\n", DRD_(thread_get_name)(*err_extra));
bartd45d9952009-05-31 18:53:54 +0000278 s_last_tid_printed = *err_extra;
279 }
bart61d36ff2009-07-27 14:17:33 +0000280}
bartd45d9952009-05-31 18:53:54 +0000281
bart61d36ff2009-07-27 14:17:33 +0000282/** Report an error to the user. */
283static void drd_tool_error_pp(Error* const e)
284{
barte7086002011-10-11 19:08:39 +0000285 const Bool xml = VG_(clo_xml);
286 const char* const what_prefix = xml ? " <what>" : "";
287 const char* const what_suffix = xml ? "</what>" : "";
288
289 if (xml)
290 VG_(printf_xml)( " <kind>%pS</kind>\n", drd_get_error_name(e));
291
bartbedfd232009-03-26 19:07:15 +0000292 switch (VG_(get_error_kind)(e))
293 {
294 case DataRaceErr: {
295 drd_report_data_race(e, VG_(get_error_extra)(e));
296 break;
297 }
298 case MutexErr: {
299 MutexErrInfo* p = (MutexErrInfo*)(VG_(get_error_extra)(e));
300 tl_assert(p);
barte7086002011-10-11 19:08:39 +0000301 if (p->recursion_count >= 0) {
302 print_err_detail("%s%s: mutex 0x%lx, recursion count %d, owner %d."
303 "%s\n", what_prefix, VG_(get_error_string)(e),
304 p->mutex, p->recursion_count, p->owner, what_suffix);
305 } else {
306 print_err_detail("%sThe object at address 0x%lx is not a mutex.%s\n",
307 what_prefix, p->mutex, what_suffix);
bartbedfd232009-03-26 19:07:15 +0000308 }
309 VG_(pp_ExeContext)(VG_(get_error_where)(e));
310 first_observed(p->mutex);
311 break;
312 }
313 case CondErr: {
314 CondErrInfo* cdei =(CondErrInfo*)(VG_(get_error_extra)(e));
barte7086002011-10-11 19:08:39 +0000315 print_err_detail("%s%s: cond 0x%lx%s\n", what_prefix,
316 VG_(get_error_string)(e), cdei->cond, what_suffix);
bartbedfd232009-03-26 19:07:15 +0000317 VG_(pp_ExeContext)(VG_(get_error_where)(e));
318 first_observed(cdei->cond);
319 break;
320 }
321 case CondDestrErr: {
322 CondDestrErrInfo* cdi = (CondDestrErrInfo*)(VG_(get_error_extra)(e));
barte7086002011-10-11 19:08:39 +0000323 print_err_detail("%s%s: cond 0x%lx, mutex 0x%lx locked by thread %d%s\n",
324 what_prefix, VG_(get_error_string)(e), cdi->cond,
325 cdi->mutex, cdi->owner, what_suffix);
bartbedfd232009-03-26 19:07:15 +0000326 VG_(pp_ExeContext)(VG_(get_error_where)(e));
327 first_observed(cdi->mutex);
328 break;
329 }
330 case CondRaceErr: {
331 CondRaceErrInfo* cei = (CondRaceErrInfo*)(VG_(get_error_extra)(e));
barte7086002011-10-11 19:08:39 +0000332 print_err_detail("%sProbably a race condition: condition variable 0x%lx"
333 " has been signaled but the associated mutex 0x%lx is"
334 " not locked by the signalling thread.%s\n",
335 what_prefix, cei->cond, cei->mutex, what_suffix);
bartbedfd232009-03-26 19:07:15 +0000336 VG_(pp_ExeContext)(VG_(get_error_where)(e));
337 first_observed(cei->cond);
338 first_observed(cei->mutex);
339 break;
340 }
341 case CondWaitErr: {
342 CondWaitErrInfo* cwei = (CondWaitErrInfo*)(VG_(get_error_extra)(e));
barte7086002011-10-11 19:08:39 +0000343 print_err_detail("%s%s: condition variable 0x%lx, mutexes 0x%lx and"
344 " 0x%lx%s\n", what_prefix, VG_(get_error_string)(e),
345 cwei->cond, cwei->mutex1, cwei->mutex2, what_suffix);
bartbedfd232009-03-26 19:07:15 +0000346 VG_(pp_ExeContext)(VG_(get_error_where)(e));
347 first_observed(cwei->cond);
348 first_observed(cwei->mutex1);
349 first_observed(cwei->mutex2);
350 break;
351 }
352 case SemaphoreErr: {
353 SemaphoreErrInfo* sei = (SemaphoreErrInfo*)(VG_(get_error_extra)(e));
354 tl_assert(sei);
bartb6ab69e2011-10-13 16:47:53 +0000355 print_err_detail("%s%s: semaphore 0x%lx%s\n", what_prefix,
356 VG_(get_error_string)(e), sei->semaphore, what_suffix);
bartbedfd232009-03-26 19:07:15 +0000357 VG_(pp_ExeContext)(VG_(get_error_where)(e));
358 first_observed(sei->semaphore);
359 break;
360 }
361 case BarrierErr: {
362 BarrierErrInfo* bei = (BarrierErrInfo*)(VG_(get_error_extra)(e));
363 tl_assert(bei);
barte7086002011-10-11 19:08:39 +0000364 print_err_detail("%s%s: barrier 0x%lx%s\n", what_prefix,
365 VG_(get_error_string)(e), bei->barrier, what_suffix);
bartbedfd232009-03-26 19:07:15 +0000366 VG_(pp_ExeContext)(VG_(get_error_where)(e));
barte7086002011-10-11 19:08:39 +0000367 if (bei->other_context) {
368 if (xml)
369 print_err_detail(" <confl_wait_call>\n");
370 print_err_detail("%sConflicting wait call by thread %d:%s\n",
371 what_prefix, bei->other_tid, what_suffix);
bartbedfd232009-03-26 19:07:15 +0000372 VG_(pp_ExeContext)(bei->other_context);
barte7086002011-10-11 19:08:39 +0000373 if (xml)
374 print_err_detail(" </confl_wait_call>\n");
bartbedfd232009-03-26 19:07:15 +0000375 }
376 first_observed(bei->barrier);
377 break;
378 }
379 case RwlockErr: {
380 RwlockErrInfo* p = (RwlockErrInfo*)(VG_(get_error_extra)(e));
381 tl_assert(p);
barte7086002011-10-11 19:08:39 +0000382 print_err_detail("%s%s: rwlock 0x%lx.%s\n", what_prefix,
383 VG_(get_error_string)(e), p->rwlock, what_suffix);
bartbedfd232009-03-26 19:07:15 +0000384 VG_(pp_ExeContext)(VG_(get_error_where)(e));
385 first_observed(p->rwlock);
386 break;
387 }
388 case HoldtimeErr: {
389 HoldtimeErrInfo* p =(HoldtimeErrInfo*)(VG_(get_error_extra)(e));
390 tl_assert(p);
391 tl_assert(p->acquired_at);
barte7086002011-10-11 19:08:39 +0000392 if (xml)
393 print_err_detail(" <acquired_at>\n");
394 else
395 print_err_detail("Acquired at:\n");
bartbedfd232009-03-26 19:07:15 +0000396 VG_(pp_ExeContext)(p->acquired_at);
bartb6ab69e2011-10-13 16:47:53 +0000397 if (xml)
398 print_err_detail(" </acquired_at>\n");
barte7086002011-10-11 19:08:39 +0000399 print_err_detail("%sLock on %s 0x%lx was held during %d ms"
400 " (threshold: %d ms).%s\n", what_prefix,
401 VG_(get_error_string)(e), p->synchronization_object,
402 p->hold_time_ms, p->threshold_ms, what_suffix);
bartbedfd232009-03-26 19:07:15 +0000403 VG_(pp_ExeContext)(VG_(get_error_where)(e));
404 first_observed(p->synchronization_object);
405 break;
406 }
407 case GenericErr: {
bart62cc2322010-03-07 10:54:21 +0000408 GenericErrInfo* gei = (GenericErrInfo*)(VG_(get_error_extra)(e));
barte7086002011-10-11 19:08:39 +0000409 print_err_detail("%s%s%s\n", what_prefix, VG_(get_error_string)(e),
410 what_suffix);
bartbedfd232009-03-26 19:07:15 +0000411 VG_(pp_ExeContext)(VG_(get_error_where)(e));
bart62cc2322010-03-07 10:54:21 +0000412 if (gei->addr)
413 first_observed(gei->addr);
bartbedfd232009-03-26 19:07:15 +0000414 break;
415 }
bartb48bde22009-07-31 08:26:17 +0000416 case InvalidThreadId: {
417 InvalidThreadIdInfo* iti =(InvalidThreadIdInfo*)(VG_(get_error_extra)(e));
barte7086002011-10-11 19:08:39 +0000418 print_err_detail("%s%s 0x%llx%s\n", what_prefix, VG_(get_error_string)(e),
419 iti->ptid, what_suffix);
bartb48bde22009-07-31 08:26:17 +0000420 VG_(pp_ExeContext)(VG_(get_error_where)(e));
421 break;
422 }
bart141a7ed2010-03-21 17:28:10 +0000423 case UnimpHgClReq: {
bart66f196d2009-08-15 10:50:35 +0000424 UnimpClReqInfo* uicr =(UnimpClReqInfo*)(VG_(get_error_extra)(e));
barte7086002011-10-11 19:08:39 +0000425 print_err_detail("%sThe annotation macro %s has not yet been implemented"
426 " in %ps%s\n", what_prefix, uicr->descr,
427 "<valgrind/helgrind.h>", what_suffix);
bart66f196d2009-08-15 10:50:35 +0000428 VG_(pp_ExeContext)(VG_(get_error_where)(e));
429 break;
430 }
bart141a7ed2010-03-21 17:28:10 +0000431 case UnimpDrdClReq: {
432 UnimpClReqInfo* uicr =(UnimpClReqInfo*)(VG_(get_error_extra)(e));
barte7086002011-10-11 19:08:39 +0000433 print_err_detail("%sThe annotation macro %s has not yet been implemented"
434 " in %ps%s\n", what_prefix, uicr->descr,
435 "<valgrind/drd.h>", what_suffix);
bart141a7ed2010-03-21 17:28:10 +0000436 VG_(pp_ExeContext)(VG_(get_error_where)(e));
437 break;
438 }
bartbedfd232009-03-26 19:07:15 +0000439 default:
barte7086002011-10-11 19:08:39 +0000440 print_err_detail("%s%s%s\n", what_prefix, VG_(get_error_string)(e),
441 what_suffix);
bartbedfd232009-03-26 19:07:15 +0000442 VG_(pp_ExeContext)(VG_(get_error_where)(e));
443 break;
444 }
sewardjaf44c822007-11-25 14:01:38 +0000445}
446
bartd2c5eae2009-02-21 15:27:04 +0000447static UInt drd_tool_error_update_extra(Error* e)
sewardjaf44c822007-11-25 14:01:38 +0000448{
bartbedfd232009-03-26 19:07:15 +0000449 switch (VG_(get_error_kind)(e))
450 {
451 case DataRaceErr:
452 return sizeof(DataRaceErrInfo);
453 case MutexErr:
454 return sizeof(MutexErrInfo);
455 case CondErr:
456 return sizeof(CondErrInfo);
457 case CondDestrErr:
458 return sizeof(CondDestrErrInfo);
459 case CondRaceErr:
460 return sizeof(CondRaceErrInfo);
461 case CondWaitErr:
462 return sizeof(CondWaitErrInfo);
463 case SemaphoreErr:
464 return sizeof(SemaphoreErrInfo);
465 case BarrierErr:
466 return sizeof(BarrierErrInfo);
467 case RwlockErr:
468 return sizeof(RwlockErrInfo);
469 case HoldtimeErr:
470 return sizeof(HoldtimeErrInfo);
471 case GenericErr:
472 return sizeof(GenericErrInfo);
bartb48bde22009-07-31 08:26:17 +0000473 case InvalidThreadId:
474 return sizeof(InvalidThreadIdInfo);
bart141a7ed2010-03-21 17:28:10 +0000475 case UnimpHgClReq:
476 return sizeof(UnimpClReqInfo);
477 case UnimpDrdClReq:
bart66f196d2009-08-15 10:50:35 +0000478 return sizeof(UnimpClReqInfo);
bartbedfd232009-03-26 19:07:15 +0000479 default:
480 tl_assert(False);
481 break;
482 }
sewardjaf44c822007-11-25 14:01:38 +0000483}
484
bart61d36ff2009-07-27 14:17:33 +0000485/**
486 * Parse suppression name.
487 *
488 * The suppression types recognized by DRD are the same types as the error
489 * types supported by DRD. So try to match the suppression name against the
490 * names of DRD error types.
491 */
492static Bool drd_is_recognized_suppression(Char* const name, Supp* const supp)
sewardjaf44c822007-11-25 14:01:38 +0000493{
bart61d36ff2009-07-27 14:17:33 +0000494 DrdErrorKind skind = 0;
sewardjaf44c822007-11-25 14:01:38 +0000495
bartbedfd232009-03-26 19:07:15 +0000496 if (VG_(strcmp)(name, STR_DataRaceErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000497 skind = DataRaceErr;
bartbedfd232009-03-26 19:07:15 +0000498 else if (VG_(strcmp)(name, STR_MutexErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000499 skind = MutexErr;
bartbedfd232009-03-26 19:07:15 +0000500 else if (VG_(strcmp)(name, STR_CondErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000501 skind = CondErr;
bartbedfd232009-03-26 19:07:15 +0000502 else if (VG_(strcmp)(name, STR_CondDestrErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000503 skind = CondDestrErr;
bartbedfd232009-03-26 19:07:15 +0000504 else if (VG_(strcmp)(name, STR_CondRaceErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000505 skind = CondRaceErr;
bartbedfd232009-03-26 19:07:15 +0000506 else if (VG_(strcmp)(name, STR_CondWaitErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000507 skind = CondWaitErr;
bartbedfd232009-03-26 19:07:15 +0000508 else if (VG_(strcmp)(name, STR_SemaphoreErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000509 skind = SemaphoreErr;
bartbedfd232009-03-26 19:07:15 +0000510 else if (VG_(strcmp)(name, STR_BarrierErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000511 skind = BarrierErr;
bartbedfd232009-03-26 19:07:15 +0000512 else if (VG_(strcmp)(name, STR_RwlockErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000513 skind = RwlockErr;
bartbedfd232009-03-26 19:07:15 +0000514 else if (VG_(strcmp)(name, STR_HoldtimeErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000515 skind = HoldtimeErr;
bartbedfd232009-03-26 19:07:15 +0000516 else if (VG_(strcmp)(name, STR_GenericErr) == 0)
bart61d36ff2009-07-27 14:17:33 +0000517 skind = GenericErr;
bartb48bde22009-07-31 08:26:17 +0000518 else if (VG_(strcmp)(name, STR_InvalidThreadId) == 0)
519 skind = InvalidThreadId;
bart141a7ed2010-03-21 17:28:10 +0000520 else if (VG_(strcmp)(name, STR_UnimpHgClReq) == 0)
521 skind = UnimpHgClReq;
522 else if (VG_(strcmp)(name, STR_UnimpDrdClReq) == 0)
523 skind = UnimpDrdClReq;
bartbedfd232009-03-26 19:07:15 +0000524 else
525 return False;
sewardjaf44c822007-11-25 14:01:38 +0000526
bartbedfd232009-03-26 19:07:15 +0000527 VG_(set_supp_kind)(supp, skind);
528 return True;
sewardjaf44c822007-11-25 14:01:38 +0000529}
530
bart61d36ff2009-07-27 14:17:33 +0000531/**
532 * Read additional suppression information from the suppression file.
533 *
534 * None of the suppression patterns recognized by DRD has 'extra' lines
535 * of information in the suppression file, so just return True to indicate
536 * that reading the 'extra' lines succeeded.
537 */
bart246fbf22009-02-15 14:46:17 +0000538static
bart61d36ff2009-07-27 14:17:33 +0000539Bool drd_read_extra_suppression_info(Int fd, Char** bufpp,
540 SizeT* nBufp, Supp* supp)
sewardjaf44c822007-11-25 14:01:38 +0000541{
bartbedfd232009-03-26 19:07:15 +0000542 return True;
sewardjaf44c822007-11-25 14:01:38 +0000543}
544
bart61d36ff2009-07-27 14:17:33 +0000545/**
546 * Determine whether or not the types of the given error message and the
547 * given suppression match.
548 */
549static Bool drd_error_matches_suppression(Error* const e, Supp* const supp)
sewardjaf44c822007-11-25 14:01:38 +0000550{
bart61d36ff2009-07-27 14:17:33 +0000551 return VG_(get_supp_kind)(supp) == VG_(get_error_kind)(e);
sewardjaf44c822007-11-25 14:01:38 +0000552}
553
bart61d36ff2009-07-27 14:17:33 +0000554static Char* drd_get_error_name(Error* e)
sewardjaf44c822007-11-25 14:01:38 +0000555{
bartbedfd232009-03-26 19:07:15 +0000556 switch (VG_(get_error_kind)(e))
557 {
558 case DataRaceErr: return VGAPPEND(STR_, DataRaceErr);
559 case MutexErr: return VGAPPEND(STR_, MutexErr);
560 case CondErr: return VGAPPEND(STR_, CondErr);
561 case CondDestrErr: return VGAPPEND(STR_, CondDestrErr);
562 case CondRaceErr: return VGAPPEND(STR_, CondRaceErr);
563 case CondWaitErr: return VGAPPEND(STR_, CondWaitErr);
564 case SemaphoreErr: return VGAPPEND(STR_, SemaphoreErr);
565 case BarrierErr: return VGAPPEND(STR_, BarrierErr);
566 case RwlockErr: return VGAPPEND(STR_, RwlockErr);
567 case HoldtimeErr: return VGAPPEND(STR_, HoldtimeErr);
568 case GenericErr: return VGAPPEND(STR_, GenericErr);
bartb48bde22009-07-31 08:26:17 +0000569 case InvalidThreadId: return VGAPPEND(STR_, InvalidThreadId);
bart141a7ed2010-03-21 17:28:10 +0000570 case UnimpHgClReq: return VGAPPEND(STR_, UnimpHgClReq);
571 case UnimpDrdClReq: return VGAPPEND(STR_, UnimpDrdClReq);
bartbedfd232009-03-26 19:07:15 +0000572 default:
573 tl_assert(0);
574 }
575 return 0;
sewardjaf44c822007-11-25 14:01:38 +0000576}
577
bart61d36ff2009-07-27 14:17:33 +0000578/**
sewardj588adef2009-08-15 22:41:51 +0000579 * Return extra suppression information.
bart61d36ff2009-07-27 14:17:33 +0000580 *
581 * Invoked while printing a suppression pattern because the user
582 * specified --gen-suppressions=yes or all on the command line. DRD does not
583 * define any 'extra' suppression information.
584 */
sewardj588adef2009-08-15 22:41:51 +0000585static
586Bool drd_get_extra_suppression_info(Error* e,
587 /*OUT*/Char* buf, Int nBuf)
588{
589 return False;
590}
sewardjaf44c822007-11-25 14:01:38 +0000591
bart61d36ff2009-07-27 14:17:33 +0000592/** Tell the Valgrind core about DRD's error handlers. */
bart1335ecc2009-02-14 16:10:53 +0000593void DRD_(register_error_handlers)(void)
sewardjaf44c822007-11-25 14:01:38 +0000594{
bart61d36ff2009-07-27 14:17:33 +0000595 VG_(needs_tool_errors)(drd_compare_error_contexts,
sewardj1e29ebc2009-07-15 14:49:17 +0000596 drd_tool_error_before_pp,
bartbedfd232009-03-26 19:07:15 +0000597 drd_tool_error_pp,
bartd45d9952009-05-31 18:53:54 +0000598 False,
bartbedfd232009-03-26 19:07:15 +0000599 drd_tool_error_update_extra,
bart61d36ff2009-07-27 14:17:33 +0000600 drd_is_recognized_suppression,
601 drd_read_extra_suppression_info,
602 drd_error_matches_suppression,
603 drd_get_error_name,
sewardj588adef2009-08-15 22:41:51 +0000604 drd_get_extra_suppression_info);
sewardjaf44c822007-11-25 14:01:38 +0000605}