-> 3.17.0.RC2
[valgrind.git] / drd / drd_suppression.c
blob8688bec9770b8b483f9a06d6c01d7e68f277de29
1 /*
2 This file is part of drd, a thread error detector.
4 Copyright (C) 2006-2020 Bart Van Assche <bvanassche@acm.org>.
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.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
19 The GNU General Public License is contained in the file COPYING.
23 #include "drd_suppression.h"
24 #include "pub_drd_bitmap.h"
25 #include "pub_tool_libcassert.h" // tl_assert()
26 #include "pub_tool_stacktrace.h" // VG_(get_and_pp_StackTrace)()
27 #include "pub_tool_threadstate.h" // VG_(get_running_tid)()
28 #include "pub_tool_libcprint.h" // Vg_DebugMsg
31 /* Global variables. */
33 Bool DRD_(g_any_address_traced) = False;
36 /* Local variables. */
38 static struct bitmap* s_suppressed;
39 static struct bitmap* s_traced;
40 static Bool s_trace_suppression;
43 /* Function definitions. */
45 void DRD_(suppression_set_trace)(const Bool trace_suppression)
47 s_trace_suppression = trace_suppression;
50 void DRD_(suppression_init)(void)
52 tl_assert(s_suppressed == 0);
53 tl_assert(s_traced == 0);
54 s_suppressed = DRD_(bm_new)();
55 s_traced = DRD_(bm_new)();
56 tl_assert(s_suppressed);
57 tl_assert(s_traced);
60 void DRD_(start_suppression)(const Addr a1, const Addr a2,
61 const HChar* const reason)
63 if (s_trace_suppression)
64 VG_(message)(Vg_DebugMsg, "start suppression of 0x%lx sz %lu (%s)\n",
65 a1, a2 - a1, reason);
67 tl_assert(a1 <= a2);
68 DRD_(bm_access_range_store)(s_suppressed, a1, a2);
71 void DRD_(finish_suppression)(const Addr a1, const Addr a2)
73 if (s_trace_suppression) {
74 VG_(message)(Vg_DebugMsg, "finish suppression of 0x%lx sz %lu\n",
75 a1, a2 - a1);
76 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12);
79 tl_assert(a1 <= a2);
80 DRD_(bm_clear_store)(s_suppressed, a1, a2);
83 /**
84 * Return true if data race detection suppression has been requested for all
85 * bytes in the range a1 .. a2 - 1 inclusive. Return false in case the range
86 * is only partially suppressed or not suppressed at all.
88 Bool DRD_(is_suppressed)(const Addr a1, const Addr a2)
90 return DRD_(bm_has)(s_suppressed, a1, a2, eStore);
93 /**
94 * Return true if data race detection suppression has been requested for any
95 * of the bytes in the range a1 .. a2 - 1 inclusive. Return false in case none
96 * of the bytes in the specified range is suppressed.
98 Bool DRD_(is_any_suppressed)(const Addr a1, const Addr a2)
100 return DRD_(bm_has_any_store)(s_suppressed, a1, a2);
103 void DRD_(mark_hbvar)(const Addr a1)
105 DRD_(bm_access_range_load)(s_suppressed, a1, a1 + 1);
108 Bool DRD_(range_contains_suppression_or_hbvar)(const Addr a1, const Addr a2)
110 return DRD_(bm_has_any_access)(s_suppressed, a1, a2);
114 * Start tracing memory accesses in the range [a1,a2). If persistent == True,
115 * keep tracing even after memory deallocation and reallocation.
117 void DRD_(start_tracing_address_range)(const Addr a1, const Addr a2,
118 const Bool persistent)
120 tl_assert(a1 <= a2);
122 if (s_trace_suppression)
123 VG_(message)(Vg_DebugMsg, "start_tracing(0x%lx, %lu) %s\n",
124 a1, a2 - a1, persistent ? "persistent" : "non-persistent");
126 DRD_(bm_access_range_load)(s_traced, a1, a2);
127 if (persistent)
128 DRD_(bm_access_range_store)(s_traced, a1, a2);
129 if (!DRD_(g_any_address_traced) && a1 < a2)
130 DRD_(g_any_address_traced) = True;
134 * Stop tracing memory accesses in the range [a1,a2).
136 void DRD_(stop_tracing_address_range)(const Addr a1, const Addr a2)
138 tl_assert(a1 <= a2);
140 if (s_trace_suppression)
141 VG_(message)(Vg_DebugMsg, "stop_tracing(0x%lx, %lu)\n",
142 a1, a2 - a1);
144 if (DRD_(g_any_address_traced)) {
145 DRD_(bm_clear)(s_traced, a1, a2);
146 DRD_(g_any_address_traced) = DRD_(bm_has_any_load_g)(s_traced);
150 Bool DRD_(is_any_traced)(const Addr a1, const Addr a2)
152 return DRD_(bm_has_any_access)(s_traced, a1, a2);
156 * Stop using the memory range [a1,a2). Stop tracing memory accesses to
157 * non-persistent address ranges.
159 void DRD_(suppression_stop_using_mem)(const Addr a1, const Addr a2)
161 if (s_trace_suppression) {
162 Addr b;
163 for (b = a1; b < a2; b++) {
164 if (DRD_(bm_has_1)(s_suppressed, b, eStore)) {
165 VG_(message)(Vg_DebugMsg,
166 "stop_using_mem(0x%lx, %lu) finish suppression of"
167 " 0x%lx\n", a1, a2 - a1, b);
171 tl_assert(a1);
172 tl_assert(a1 <= a2);
173 DRD_(bm_clear)(s_suppressed, a1, a2);
174 DRD_(bm_clear_load)(s_traced, a1, a2);