• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2   This file is part of drd, a thread error detector.
3 
4   Copyright (C) 2006-2013 Bart Van Assche <bvanassche@acm.org>.
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 
25 #include "drd_clientobj.h"        /* struct mutex_info        */
26 #include "drd_error.h"
27 #include "drd_malloc_wrappers.h"
28 #include "drd_mutex.h"
29 #include "drd_suppression.h"      /* drd_start_suppression()  */
30 #include "pub_drd_bitmap.h"       /* LHS_W, ...               */
31 #include "pub_tool_vki.h"
32 #include "pub_tool_basics.h"
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)()            */
37 #include "pub_tool_machine.h"
38 #include "pub_tool_mallocfree.h"  /* VG_(malloc), VG_(free)   */
39 #include "pub_tool_options.h"     /* VG_(clo_xml)             */
40 #include "pub_tool_threadstate.h" /* VG_(get_pthread_id)()    */
41 #include "pub_tool_tooliface.h"   /* VG_(needs_tool_errors)() */
42 
43 
44 /* Local function declarations. */
45 
46 static const HChar* drd_get_error_name(const Error* e);
47 
48 
49 /* Local variables. */
50 
51 static Bool s_show_conflicting_segments = True;
52 
53 
DRD_(set_show_conflicting_segments)54 void DRD_(set_show_conflicting_segments)(const Bool scs)
55 {
56    s_show_conflicting_segments = scs;
57 }
58 
DRD_(trace_msg)59 void DRD_(trace_msg)(const HChar* format, ...)
60 {
61    va_list vargs;
62    va_start(vargs, format);
63    if (VG_(clo_xml)) {
64       VG_(printf_xml)("  <trace><text>");
65       VG_(vprintf_xml)(format, vargs);
66       VG_(printf_xml)("</text></trace>\n");
67    } else {
68       VG_(vmessage)(Vg_UserMsg, format, vargs);
69       VG_(message)(Vg_UserMsg, "\n");
70    }
71    va_end(vargs);
72 }
73 
DRD_(trace_msg_w_bt)74 void DRD_(trace_msg_w_bt)(const HChar* format, ...)
75 {
76    va_list vargs;
77    va_start(vargs, format);
78    if (VG_(clo_xml)) {
79       VG_(printf_xml)("  <trace><text>");
80       VG_(vprintf_xml)(format, vargs);
81       VG_(printf_xml)("</text>\n");
82    } else {
83       VG_(vmessage)(Vg_UserMsg, format, vargs);
84       VG_(message)(Vg_UserMsg, "\n");
85    }
86    VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), VG_(clo_backtrace_size));
87    va_end(vargs);
88    if (VG_(clo_xml))
89       VG_(printf_xml)("  </trace>\n");
90 }
91 
92 /**
93  * Emit error message detail in the format requested by the user.
94  */
95 static void print_err_detail(const HChar* format, ...) PRINTF_CHECK(1, 2);
print_err_detail(const HChar * format,...)96 static void print_err_detail(const HChar* format, ...)
97 {
98    va_list vargs;
99    va_start(vargs, format);
100    if (VG_(clo_xml))
101       VG_(vprintf_xml)(format, vargs);
102    else
103       VG_(vmessage)(Vg_UserMsg, format, vargs);
104    va_end(vargs);
105 }
106 
107 /**
108  * Describe the client address a as good as possible, putting the result in ai.
109  */
110 static
describe_malloced_addr(Addr const a,AddrInfo * const ai)111 void describe_malloced_addr(Addr const a, AddrInfo* const ai)
112 {
113    Addr heap_block_start;
114 
115    if (DRD_(heap_addrinfo)(a, &heap_block_start, &ai->size, &ai->lastchange))
116    {
117       ai->akind = eMallocd;
118       ai->rwoffset = a - heap_block_start;
119    }
120    else
121    {
122       ai->akind = eUnknown;
123    }
124 }
125 
126 /**
127  * Report where a client synchronization object has been observed for the first
128  * time. The printed call stack will either refer to a pthread_*_init() or a
129  * pthread_*lock() call.
130  */
first_observed(const Addr obj)131 static void first_observed(const Addr obj)
132 {
133    DrdClientobj* cl;
134 
135    cl = DRD_(clientobj_get_any)(obj);
136    if (cl) {
137       tl_assert(cl->any.first_observed_at);
138       if (VG_(clo_xml)) {
139          print_err_detail("  <first_observed_at>\n"
140                           "    <what>%pS</what>\n"
141                           "    <address>0x%lx</address>\n",
142                           DRD_(clientobj_type_name)(cl->any.type), obj);
143          VG_(pp_ExeContext)(cl->any.first_observed_at);
144          print_err_detail("  </first_observed_at>\n");
145       } else {
146          print_err_detail("%s 0x%lx was first observed at:\n",
147                           DRD_(clientobj_type_name)(cl->any.type), obj);
148          VG_(pp_ExeContext)(cl->any.first_observed_at);
149       }
150    }
151 }
152 
153 static
drd_report_data_race(const Error * const err,const DataRaceErrInfo * const dri)154 void drd_report_data_race(const Error* const err,
155                           const DataRaceErrInfo* const dri)
156 {
157    const Bool xml = VG_(clo_xml);
158    const HChar* const what_prefix = xml ? "  <what>" : "";
159    const HChar* const what_suffix = xml ? "</what>" : "";
160    const HChar* const auxwhat_prefix = xml ? "  <auxwhat>" : "";
161    const HChar* const auxwhat_suffix = xml ? "</auxwhat>" : "";
162    const HChar* const indent = xml ? "  " : "";
163    AddrInfo ai;
164 
165    XArray* /* of HChar */ descr1
166       = VG_(newXA)( VG_(malloc), "drd.error.drdr2.1",
167                     VG_(free), sizeof(HChar) );
168    XArray* /* of HChar */ descr2
169       = VG_(newXA)( VG_(malloc), "drd.error.drdr2.2",
170                     VG_(free), sizeof(HChar) );
171 
172    tl_assert(dri);
173    tl_assert(dri->addr);
174    tl_assert(dri->size > 0);
175 
176    (void) VG_(get_data_description)(descr1, descr2, dri->addr);
177    /* If there's nothing in descr1/2, free them.  Why is it safe to to
178       VG_(indexXA) at zero here?  Because VG_(get_data_description)
179       guarantees to zero terminate descr1/2 regardless of the outcome
180       of the call.  So there's always at least one element in each XA
181       after the call.
182    */
183    if (0 == VG_(strlen)( VG_(indexXA)( descr1, 0 ))) {
184       VG_(deleteXA)( descr1 );
185       descr1 = NULL;
186    }
187    if (0 == VG_(strlen)( VG_(indexXA)( descr2, 0 ))) {
188       VG_(deleteXA)( descr2 );
189       descr2 = NULL;
190    }
191    /* Assume (assert) that VG_(get_data_description) fills in descr1
192       before it fills in descr2 */
193    if (descr1 == NULL)
194       tl_assert(descr2 == NULL);
195    /* So anyway.  Do we have something useful? */
196    if (descr1 == NULL)
197    {
198       /* No.  Do Plan B. */
199       describe_malloced_addr(dri->addr, &ai);
200    }
201 
202    print_err_detail("%sConflicting %s by thread %d at 0x%08lx size %ld%s\n",
203                     what_prefix, dri->access_type == eStore ? "store" : "load",
204                     dri->tid, dri->addr, dri->size, what_suffix);
205 
206    VG_(pp_ExeContext)(VG_(get_error_where)(err));
207    if (descr1 != NULL) {
208       print_err_detail("%s%s\n", indent, (HChar*)VG_(indexXA)(descr1, 0));
209       if (descr2 != NULL)
210          print_err_detail("%s%s\n", indent, (HChar*)VG_(indexXA)(descr2, 0));
211    } else if (ai.akind == eMallocd && ai.lastchange) {
212       print_err_detail("%sAddress 0x%lx is at offset %ld from 0x%lx.%s%s",
213                        auxwhat_prefix, dri->addr, ai.rwoffset,
214                        dri->addr - ai.rwoffset, auxwhat_suffix,
215                        xml ? "\n" : "");
216       if (xml)
217          print_err_detail("  <allocation_context>\n");
218       else
219          print_err_detail(" Allocation context:\n");
220       VG_(pp_ExeContext)(ai.lastchange);
221       if (xml)
222          print_err_detail("  </allocation_context>\n");
223    } else {
224       const HChar *sect_name;
225       VgSectKind sect_kind;
226 
227       sect_kind = VG_(DebugInfo_sect_kind)(&sect_name, dri->addr);
228       if (sect_kind != Vg_SectUnknown) {
229          print_err_detail("%sAllocation context: %ps section of %ps%s\n",
230                           auxwhat_prefix, VG_(pp_SectKind)(sect_kind),
231                           sect_name, auxwhat_suffix);
232       } else {
233          print_err_detail("%sAllocation context: unknown.%s\n",
234                           auxwhat_prefix, auxwhat_suffix);
235       }
236    }
237    if (s_show_conflicting_segments)
238    {
239       DRD_(thread_report_conflicting_segments)(dri->tid,
240                                                dri->addr, dri->size,
241                                                dri->access_type);
242    }
243 
244    if (descr2)
245       VG_(deleteXA)(descr2);
246    if (descr1)
247       VG_(deleteXA)(descr1);
248 }
249 
250 /**
251  * Compare two error contexts. The core function VG_(maybe_record_error)()
252  * calls this function to compare error contexts such that errors that occur
253  * repeatedly are only printed once. This function is only called by the core
254  * if the error kind of e1 and e2 matches and if the ExeContext's of e1 and
255  * e2 also match.
256  */
drd_compare_error_contexts(VgRes res,const Error * e1,const Error * e2)257 static Bool drd_compare_error_contexts(VgRes res, const Error* e1,
258                                        const Error* e2)
259 {
260    tl_assert(VG_(get_error_kind)(e1) == VG_(get_error_kind)(e2));
261 
262    switch (VG_(get_error_kind)(e1))
263    {
264    case DataRaceErr:
265    {
266       const DataRaceErrInfo* const dri1 = VG_(get_error_extra)(e1);
267       const DataRaceErrInfo* const dri2 = VG_(get_error_extra)(e2);
268       return dri1->access_type == dri2->access_type
269 	     && dri1->size == dri2->size;
270    }
271    case MutexErr:
272    {
273       const MutexErrInfo* const mei1 = VG_(get_error_extra)(e1);
274       const MutexErrInfo* const mei2 = VG_(get_error_extra)(e2);
275       return mei1->mutex == mei2->mutex;
276    }
277    default:
278       return True;
279    }
280 }
281 
282 /**
283  * Called by the core just before an error message will be printed. Used by
284  * DRD to print the thread number as a preamble.
285  */
drd_tool_error_before_pp(const Error * const e)286 static void drd_tool_error_before_pp(const Error* const e)
287 {
288    static DrdThreadId s_last_tid_printed = 1;
289    DrdThreadId* err_extra;
290 
291    err_extra = VG_(get_error_extra)(e);
292 
293    if (err_extra && *err_extra != s_last_tid_printed && !VG_(clo_xml)) {
294       VG_(umsg)("%s:\n", DRD_(thread_get_name)(*err_extra));
295       s_last_tid_printed = *err_extra;
296    }
297 }
298 
299 /** Report an error to the user. */
drd_tool_error_pp(const Error * const e)300 static void drd_tool_error_pp(const Error* const e)
301 {
302    const Bool xml = VG_(clo_xml);
303    const HChar* const what_prefix = xml ? "  <what>" : "";
304    const HChar* const what_suffix = xml ? "</what>" : "";
305 
306    if (xml)
307       VG_(printf_xml)( "  <kind>%pS</kind>\n", drd_get_error_name(e));
308 
309    switch (VG_(get_error_kind)(e))
310    {
311    case DataRaceErr: {
312       drd_report_data_race(e, VG_(get_error_extra)(e));
313       break;
314    }
315    case MutexErr: {
316       MutexErrInfo* p = (MutexErrInfo*)(VG_(get_error_extra)(e));
317       tl_assert(p);
318       if (p->recursion_count >= 0) {
319          print_err_detail("%s%s: mutex 0x%lx, recursion count %d, owner %d."
320                           "%s\n", what_prefix, VG_(get_error_string)(e),
321                           p->mutex, p->recursion_count, p->owner, what_suffix);
322       } else {
323          print_err_detail("%sThe object at address 0x%lx is not a mutex.%s\n",
324                           what_prefix, p->mutex, what_suffix);
325       }
326       VG_(pp_ExeContext)(VG_(get_error_where)(e));
327       first_observed(p->mutex);
328       break;
329    }
330    case CondErr: {
331       CondErrInfo* cdei =(CondErrInfo*)(VG_(get_error_extra)(e));
332       print_err_detail("%s%s: cond 0x%lx%s\n", what_prefix,
333                        VG_(get_error_string)(e), cdei->cond, what_suffix);
334       VG_(pp_ExeContext)(VG_(get_error_where)(e));
335       first_observed(cdei->cond);
336       break;
337    }
338    case CondDestrErr: {
339       CondDestrErrInfo* cdi = (CondDestrErrInfo*)(VG_(get_error_extra)(e));
340       print_err_detail("%s%s: cond 0x%lx, mutex 0x%lx locked by thread %d%s\n",
341                        what_prefix, VG_(get_error_string)(e), cdi->cond,
342                        cdi->mutex, cdi->owner, what_suffix);
343       VG_(pp_ExeContext)(VG_(get_error_where)(e));
344       first_observed(cdi->mutex);
345       break;
346    }
347    case CondRaceErr: {
348       CondRaceErrInfo* cei = (CondRaceErrInfo*)(VG_(get_error_extra)(e));
349       print_err_detail("%sProbably a race condition: condition variable 0x%lx"
350                        " has been signaled but the associated mutex 0x%lx is"
351                        " not locked by the signalling thread.%s\n",
352                        what_prefix, cei->cond, cei->mutex, what_suffix);
353       VG_(pp_ExeContext)(VG_(get_error_where)(e));
354       first_observed(cei->cond);
355       first_observed(cei->mutex);
356       break;
357    }
358    case CondWaitErr: {
359       CondWaitErrInfo* cwei = (CondWaitErrInfo*)(VG_(get_error_extra)(e));
360       print_err_detail("%s%s: condition variable 0x%lx, mutexes 0x%lx and"
361                        " 0x%lx%s\n", what_prefix, VG_(get_error_string)(e),
362                        cwei->cond, cwei->mutex1, cwei->mutex2, what_suffix);
363       VG_(pp_ExeContext)(VG_(get_error_where)(e));
364       first_observed(cwei->cond);
365       first_observed(cwei->mutex1);
366       first_observed(cwei->mutex2);
367       break;
368    }
369    case SemaphoreErr: {
370       SemaphoreErrInfo* sei = (SemaphoreErrInfo*)(VG_(get_error_extra)(e));
371       tl_assert(sei);
372       print_err_detail("%s%s: semaphore 0x%lx%s\n", what_prefix,
373                        VG_(get_error_string)(e), sei->semaphore, what_suffix);
374       VG_(pp_ExeContext)(VG_(get_error_where)(e));
375       first_observed(sei->semaphore);
376       break;
377    }
378    case BarrierErr: {
379       BarrierErrInfo* bei = (BarrierErrInfo*)(VG_(get_error_extra)(e));
380       tl_assert(bei);
381       print_err_detail("%s%s: barrier 0x%lx%s\n", what_prefix,
382                        VG_(get_error_string)(e), bei->barrier, what_suffix);
383       VG_(pp_ExeContext)(VG_(get_error_where)(e));
384       if (bei->other_context) {
385          if (xml)
386             print_err_detail("  <confl_wait_call>\n");
387          print_err_detail("%sConflicting wait call by thread %d:%s\n",
388                           what_prefix, bei->other_tid, what_suffix);
389          VG_(pp_ExeContext)(bei->other_context);
390          if (xml)
391             print_err_detail("  </confl_wait_call>\n");
392       }
393       first_observed(bei->barrier);
394       break;
395    }
396    case RwlockErr: {
397       RwlockErrInfo* p = (RwlockErrInfo*)(VG_(get_error_extra)(e));
398       tl_assert(p);
399       print_err_detail("%s%s: rwlock 0x%lx.%s\n", what_prefix,
400                        VG_(get_error_string)(e), p->rwlock, what_suffix);
401       VG_(pp_ExeContext)(VG_(get_error_where)(e));
402       first_observed(p->rwlock);
403       break;
404    }
405    case HoldtimeErr: {
406       HoldtimeErrInfo* p =(HoldtimeErrInfo*)(VG_(get_error_extra)(e));
407       tl_assert(p);
408       tl_assert(p->acquired_at);
409       if (xml)
410          print_err_detail("  <acquired_at>\n");
411       else
412          print_err_detail("Acquired at:\n");
413       VG_(pp_ExeContext)(p->acquired_at);
414       if (xml)
415          print_err_detail("  </acquired_at>\n");
416       print_err_detail("%sLock on %s 0x%lx was held during %d ms"
417                        " (threshold: %d ms).%s\n", what_prefix,
418                        VG_(get_error_string)(e), p->synchronization_object,
419                        p->hold_time_ms, p->threshold_ms, what_suffix);
420       VG_(pp_ExeContext)(VG_(get_error_where)(e));
421       first_observed(p->synchronization_object);
422       break;
423    }
424    case GenericErr: {
425       GenericErrInfo* gei = (GenericErrInfo*)(VG_(get_error_extra)(e));
426       print_err_detail("%s%s%s\n", what_prefix, VG_(get_error_string)(e),
427                        what_suffix);
428       VG_(pp_ExeContext)(VG_(get_error_where)(e));
429       if (gei->addr)
430 	 first_observed(gei->addr);
431       break;
432    }
433    case InvalidThreadId: {
434       InvalidThreadIdInfo* iti =(InvalidThreadIdInfo*)(VG_(get_error_extra)(e));
435       print_err_detail("%s%s 0x%llx%s\n", what_prefix, VG_(get_error_string)(e),
436                        iti->ptid, what_suffix);
437       VG_(pp_ExeContext)(VG_(get_error_where)(e));
438       break;
439    }
440    case UnimpHgClReq: {
441       UnimpClReqInfo* uicr =(UnimpClReqInfo*)(VG_(get_error_extra)(e));
442       print_err_detail("%sThe annotation macro %s has not yet been implemented"
443                        " in %ps%s\n", what_prefix, uicr->descr,
444                        "<valgrind/helgrind.h>", what_suffix);
445       VG_(pp_ExeContext)(VG_(get_error_where)(e));
446       break;
447    }
448    case UnimpDrdClReq: {
449       UnimpClReqInfo* uicr =(UnimpClReqInfo*)(VG_(get_error_extra)(e));
450       print_err_detail("%sThe annotation macro %s has not yet been implemented"
451                        " in %ps%s\n", what_prefix, uicr->descr,
452                        "<valgrind/drd.h>", what_suffix);
453       VG_(pp_ExeContext)(VG_(get_error_where)(e));
454       break;
455    }
456    default:
457       print_err_detail("%s%s%s\n", what_prefix, VG_(get_error_string)(e),
458                        what_suffix);
459       VG_(pp_ExeContext)(VG_(get_error_where)(e));
460       break;
461    }
462 }
463 
drd_tool_error_update_extra(const Error * e)464 static UInt drd_tool_error_update_extra(const Error* e)
465 {
466    switch (VG_(get_error_kind)(e))
467    {
468    case DataRaceErr:
469       return sizeof(DataRaceErrInfo);
470    case MutexErr:
471       return sizeof(MutexErrInfo);
472    case CondErr:
473       return sizeof(CondErrInfo);
474    case CondDestrErr:
475       return sizeof(CondDestrErrInfo);
476    case CondRaceErr:
477       return sizeof(CondRaceErrInfo);
478    case CondWaitErr:
479       return sizeof(CondWaitErrInfo);
480    case SemaphoreErr:
481       return sizeof(SemaphoreErrInfo);
482    case BarrierErr:
483       return sizeof(BarrierErrInfo);
484    case RwlockErr:
485       return sizeof(RwlockErrInfo);
486    case HoldtimeErr:
487       return sizeof(HoldtimeErrInfo);
488    case GenericErr:
489       return sizeof(GenericErrInfo);
490    case InvalidThreadId:
491       return sizeof(InvalidThreadIdInfo);
492    case UnimpHgClReq:
493       return sizeof(UnimpClReqInfo);
494    case UnimpDrdClReq:
495       return sizeof(UnimpClReqInfo);
496    default:
497       tl_assert(False);
498       break;
499    }
500 }
501 
502 /**
503  * Parse suppression name.
504  *
505  * The suppression types recognized by DRD are the same types as the error
506  * types supported by DRD. So try to match the suppression name against the
507  * names of DRD error types.
508  */
drd_is_recognized_suppression(const HChar * const name,Supp * const supp)509 static Bool drd_is_recognized_suppression(const HChar* const name,
510                                           Supp* const supp)
511 {
512    DrdErrorKind skind = 0;
513 
514    if (VG_(strcmp)(name, STR_DataRaceErr) == 0)
515       skind = DataRaceErr;
516    else if (VG_(strcmp)(name, STR_MutexErr) == 0)
517       skind = MutexErr;
518    else if (VG_(strcmp)(name, STR_CondErr) == 0)
519       skind = CondErr;
520    else if (VG_(strcmp)(name, STR_CondDestrErr) == 0)
521       skind = CondDestrErr;
522    else if (VG_(strcmp)(name, STR_CondRaceErr) == 0)
523       skind = CondRaceErr;
524    else if (VG_(strcmp)(name, STR_CondWaitErr) == 0)
525       skind = CondWaitErr;
526    else if (VG_(strcmp)(name, STR_SemaphoreErr) == 0)
527       skind = SemaphoreErr;
528    else if (VG_(strcmp)(name, STR_BarrierErr) == 0)
529       skind = BarrierErr;
530    else if (VG_(strcmp)(name, STR_RwlockErr) == 0)
531       skind = RwlockErr;
532    else if (VG_(strcmp)(name, STR_HoldtimeErr) == 0)
533       skind = HoldtimeErr;
534    else if (VG_(strcmp)(name, STR_GenericErr) == 0)
535       skind = GenericErr;
536    else if (VG_(strcmp)(name, STR_InvalidThreadId) == 0)
537       skind = InvalidThreadId;
538    else if (VG_(strcmp)(name, STR_UnimpHgClReq) == 0)
539       skind = UnimpHgClReq;
540    else if (VG_(strcmp)(name, STR_UnimpDrdClReq) == 0)
541       skind = UnimpDrdClReq;
542    else
543       return False;
544 
545    VG_(set_supp_kind)(supp, skind);
546    return True;
547 }
548 
549 /**
550  * Read additional suppression information from the suppression file.
551  *
552  * None of the suppression patterns recognized by DRD has 'extra' lines
553  * of information in the suppression file, so just return True to indicate
554  * that reading the 'extra' lines succeeded.
555  */
556 static
drd_read_extra_suppression_info(Int fd,HChar ** bufpp,SizeT * nBufp,Int * lineno,Supp * supp)557 Bool drd_read_extra_suppression_info(Int fd, HChar** bufpp,
558                                      SizeT* nBufp, Int* lineno, Supp* supp)
559 {
560    return True;
561 }
562 
563 /**
564  * Determine whether or not the types of the given error message and the
565  * given suppression match.
566  */
drd_error_matches_suppression(const Error * const e,const Supp * const supp)567 static Bool drd_error_matches_suppression(const Error* const e,
568                                           const Supp* const supp)
569 {
570    return VG_(get_supp_kind)(supp) == VG_(get_error_kind)(e);
571 }
572 
drd_get_error_name(const Error * e)573 static const HChar* drd_get_error_name(const Error* e)
574 {
575    switch (VG_(get_error_kind)(e))
576    {
577    case DataRaceErr:  return VGAPPEND(STR_, DataRaceErr);
578    case MutexErr:     return VGAPPEND(STR_, MutexErr);
579    case CondErr:      return VGAPPEND(STR_, CondErr);
580    case CondDestrErr: return VGAPPEND(STR_, CondDestrErr);
581    case CondRaceErr:  return VGAPPEND(STR_, CondRaceErr);
582    case CondWaitErr:  return VGAPPEND(STR_, CondWaitErr);
583    case SemaphoreErr: return VGAPPEND(STR_, SemaphoreErr);
584    case BarrierErr:   return VGAPPEND(STR_, BarrierErr);
585    case RwlockErr:    return VGAPPEND(STR_, RwlockErr);
586    case HoldtimeErr:  return VGAPPEND(STR_, HoldtimeErr);
587    case GenericErr:   return VGAPPEND(STR_, GenericErr);
588    case InvalidThreadId: return VGAPPEND(STR_, InvalidThreadId);
589    case UnimpHgClReq:  return VGAPPEND(STR_, UnimpHgClReq);
590    case UnimpDrdClReq: return VGAPPEND(STR_, UnimpDrdClReq);
591    default:
592       tl_assert(0);
593    }
594    return 0;
595 }
596 
597 /**
598  * Return extra suppression information.
599  *
600  * Invoked while printing a suppression pattern because the user
601  * specified --gen-suppressions=yes or all on the command line. DRD does not
602  * define any 'extra' suppression information.
603  */
604 static
drd_get_extra_suppression_info(const Error * e,HChar * buf,Int nBuf)605 SizeT drd_get_extra_suppression_info(const Error* e,
606                                      /*OUT*/HChar* buf, Int nBuf)
607 {
608    tl_assert(nBuf >= 1);
609    buf[0] = '\0';
610    return 0;
611 }
612 
613 static
drd_print_extra_suppression_use(const Supp * su,HChar * buf,Int nBuf)614 SizeT drd_print_extra_suppression_use(const Supp* su,
615                                       /*OUT*/HChar* buf, Int nBuf)
616 {
617    tl_assert(nBuf >= 1);
618    buf[0] = '\0';
619    return 0;
620 }
621 
622 static
drd_update_extra_suppresion_use(const Error * e,const Supp * supp)623 void  drd_update_extra_suppresion_use(const Error* e, const Supp* supp)
624 {
625    return;
626 }
627 
628 /** Tell the Valgrind core about DRD's error handlers. */
DRD_(register_error_handlers)629 void DRD_(register_error_handlers)(void)
630 {
631    VG_(needs_tool_errors)(drd_compare_error_contexts,
632                           drd_tool_error_before_pp,
633                           drd_tool_error_pp,
634                           False,
635                           drd_tool_error_update_extra,
636                           drd_is_recognized_suppression,
637                           drd_read_extra_suppression_info,
638                           drd_error_matches_suppression,
639                           drd_get_error_name,
640                           drd_get_extra_suppression_info,
641                           drd_print_extra_suppression_use,
642                           drd_update_extra_suppresion_use);
643 }
644