blob: 0ed2e55a8b4b5518ce047434f5b7dd1e928a0846 [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
bart86562bd2009-02-16 19:43:56 +00002 This file is part of drd, a thread error detector.
sewardjaf44c822007-11-25 14:01:38 +00003
bart86562bd2009-02-16 19:43:56 +00004 Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>.
sewardjaf44c822007-11-25 14:01:38 +00005
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_suppression.h"
sewardjaf44c822007-11-25 14:01:38 +000026#include "pub_drd_bitmap.h"
sewardj85642922008-01-14 11:54:56 +000027#include "pub_tool_libcassert.h" // tl_assert()
sewardjaf44c822007-11-25 14:01:38 +000028#include "pub_tool_stacktrace.h" // VG_(get_and_pp_StackTrace)()
29#include "pub_tool_threadstate.h" // VG_(get_running_tid)()
sewardj85642922008-01-14 11:54:56 +000030#include "pub_tool_libcprint.h" // Vg_DebugMsg
sewardjaf44c822007-11-25 14:01:38 +000031
32
bart1335ecc2009-02-14 16:10:53 +000033/* Global variables. */
sewardjaf44c822007-11-25 14:01:38 +000034
bart1335ecc2009-02-14 16:10:53 +000035Bool DRD_(g_any_address_traced) = False;
sewardjaf44c822007-11-25 14:01:38 +000036
37
bart1335ecc2009-02-14 16:10:53 +000038/* Local variables. */
sewardjaf44c822007-11-25 14:01:38 +000039
bart1335ecc2009-02-14 16:10:53 +000040static struct bitmap* DRD_(s_suppressed);
41static Bool DRD_(s_trace_suppression);
42
43
44/* Function definitions. */
45
46void DRD_(suppression_set_trace)(const Bool trace_suppression)
sewardjaf44c822007-11-25 14:01:38 +000047{
bart1335ecc2009-02-14 16:10:53 +000048 DRD_(s_trace_suppression) = trace_suppression;
sewardjaf44c822007-11-25 14:01:38 +000049}
50
bart1335ecc2009-02-14 16:10:53 +000051void DRD_(suppression_init)(void)
sewardjaf44c822007-11-25 14:01:38 +000052{
bart1335ecc2009-02-14 16:10:53 +000053 tl_assert(DRD_(s_suppressed) == 0);
bart99edb292009-02-15 15:59:20 +000054 DRD_(s_suppressed) = DRD_(bm_new)();
bart1335ecc2009-02-14 16:10:53 +000055 tl_assert(DRD_(s_suppressed));
sewardjaf44c822007-11-25 14:01:38 +000056}
57
bart1335ecc2009-02-14 16:10:53 +000058void DRD_(start_suppression)(const Addr a1, const Addr a2,
59 const char* const reason)
sewardjaf44c822007-11-25 14:01:38 +000060{
bart1335ecc2009-02-14 16:10:53 +000061 if (DRD_(s_trace_suppression))
sewardjaf44c822007-11-25 14:01:38 +000062 {
63 VG_(message)(Vg_DebugMsg, "start suppression of 0x%lx sz %ld (%s)",
64 a1, a2 - a1, reason);
65 }
66
67 tl_assert(a1 < a2);
bartd43f8d32008-03-16 17:29:20 +000068 // tl_assert(! drd_is_any_suppressed(a1, a2));
bart99edb292009-02-15 15:59:20 +000069 DRD_(bm_access_range_store)(DRD_(s_suppressed), a1, a2);
sewardjaf44c822007-11-25 14:01:38 +000070}
71
bart1335ecc2009-02-14 16:10:53 +000072void DRD_(finish_suppression)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +000073{
bart1335ecc2009-02-14 16:10:53 +000074 if (DRD_(s_trace_suppression))
sewardjaf44c822007-11-25 14:01:38 +000075 {
76 VG_(message)(Vg_DebugMsg, "finish suppression of 0x%lx sz %ld",
77 a1, a2 - a1);
sewardj85642922008-01-14 11:54:56 +000078 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12);
sewardjaf44c822007-11-25 14:01:38 +000079 }
80
81 tl_assert(a1 < a2);
bart1335ecc2009-02-14 16:10:53 +000082 if (! DRD_(is_suppressed)(a1, a2))
sewardjaf44c822007-11-25 14:01:38 +000083 {
bartb78312c2008-02-29 11:00:17 +000084 VG_(message)(Vg_DebugMsg, "?? [0x%lx,0x%lx[ not suppressed ??", a1, a2);
sewardj85642922008-01-14 11:54:56 +000085 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12);
sewardjaf44c822007-11-25 14:01:38 +000086 tl_assert(False);
87 }
bart99edb292009-02-15 15:59:20 +000088 DRD_(bm_clear_store)(DRD_(s_suppressed), a1, a2);
sewardjaf44c822007-11-25 14:01:38 +000089}
90
91/**
92 * Return true if data race detection suppression has been requested for all
93 * bytes in the range a1 .. a2 - 1 inclusive. Return false in case the range
94 * is only partially suppressed or not suppressed at all.
95 */
bart1335ecc2009-02-14 16:10:53 +000096Bool DRD_(is_suppressed)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +000097{
bart99edb292009-02-15 15:59:20 +000098 return DRD_(bm_has)(DRD_(s_suppressed), a1, a2, eStore);
sewardjaf44c822007-11-25 14:01:38 +000099}
100
101/**
102 * Return true if data race detection suppression has been requested for any
103 * of the bytes in the range a1 .. a2 - 1 inclusive. Return false in case none
104 * of the bytes in the specified range is suppressed.
105 */
bart1335ecc2009-02-14 16:10:53 +0000106Bool DRD_(is_any_suppressed)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +0000107{
bart99edb292009-02-15 15:59:20 +0000108 return DRD_(bm_has_any_store)(DRD_(s_suppressed), a1, a2);
sewardjaf44c822007-11-25 14:01:38 +0000109}
110
bart1335ecc2009-02-14 16:10:53 +0000111void DRD_(start_tracing_address_range)(const Addr a1, const Addr a2)
bart005dc972008-03-29 14:42:59 +0000112{
113 tl_assert(a1 < a2);
114
bart99edb292009-02-15 15:59:20 +0000115 DRD_(bm_access_range_load)(DRD_(s_suppressed), a1, a2);
bart1335ecc2009-02-14 16:10:53 +0000116 if (! DRD_(g_any_address_traced))
bart005dc972008-03-29 14:42:59 +0000117 {
bart1335ecc2009-02-14 16:10:53 +0000118 DRD_(g_any_address_traced) = True;
bart005dc972008-03-29 14:42:59 +0000119 }
120}
121
bart1335ecc2009-02-14 16:10:53 +0000122void DRD_(stop_tracing_address_range)(const Addr a1, const Addr a2)
bart005dc972008-03-29 14:42:59 +0000123{
124 tl_assert(a1 < a2);
125
bart99edb292009-02-15 15:59:20 +0000126 DRD_(bm_clear_load)(DRD_(s_suppressed), a1, a2);
bart1335ecc2009-02-14 16:10:53 +0000127 if (DRD_(g_any_address_traced))
bart005dc972008-03-29 14:42:59 +0000128 {
bart1335ecc2009-02-14 16:10:53 +0000129 DRD_(g_any_address_traced)
bart99edb292009-02-15 15:59:20 +0000130 = DRD_(bm_has_any_load)(DRD_(s_suppressed), 0, ~(Addr)0);
bart005dc972008-03-29 14:42:59 +0000131 }
132}
133
bart1335ecc2009-02-14 16:10:53 +0000134Bool DRD_(is_any_traced)(const Addr a1, const Addr a2)
bart005dc972008-03-29 14:42:59 +0000135{
bart99edb292009-02-15 15:59:20 +0000136 return DRD_(bm_has_any_load)(DRD_(s_suppressed), a1, a2);
bart005dc972008-03-29 14:42:59 +0000137}
138
bart1335ecc2009-02-14 16:10:53 +0000139void DRD_(suppression_stop_using_mem)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +0000140{
bart1335ecc2009-02-14 16:10:53 +0000141 if (DRD_(s_trace_suppression))
sewardjaf44c822007-11-25 14:01:38 +0000142 {
143 Addr b;
144 for (b = a1; b < a2; b++)
145 {
bart99edb292009-02-15 15:59:20 +0000146 if (DRD_(bm_has_1)(DRD_(s_suppressed), b, eStore))
sewardjaf44c822007-11-25 14:01:38 +0000147 {
148 VG_(message)(Vg_DebugMsg,
149 "stop_using_mem(0x%lx, %ld) finish suppression of 0x%lx",
150 a1, a2 - a1, b);
sewardjaf44c822007-11-25 14:01:38 +0000151 }
152 }
153 }
154 tl_assert(a1);
155 tl_assert(a1 < a2);
bart99edb292009-02-15 15:59:20 +0000156 DRD_(bm_clear)(DRD_(s_suppressed), a1, a2);
sewardjaf44c822007-11-25 14:01:38 +0000157}