2 This file is part of drd, a thread error detector.
4 Copyright (C) 2006-2013 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, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 The GNU General Public License is contained in the file COPYING.
25 #include "drd_suppression.h"
26 #include "pub_drd_bitmap.h"
27 #include "pub_tool_libcassert.h" // tl_assert()
28 #include "pub_tool_stacktrace.h" // VG_(get_and_pp_StackTrace)()
29 #include "pub_tool_threadstate.h" // VG_(get_running_tid)()
30 #include "pub_tool_libcprint.h" // Vg_DebugMsg
33 /* Global variables. */
35 Bool
DRD_(g_any_address_traced
) = False
;
38 /* Local variables. */
40 static struct bitmap
* s_suppressed
;
41 static struct bitmap
* s_traced
;
42 static Bool s_trace_suppression
;
45 /* Function definitions. */
47 void DRD_(suppression_set_trace
)(const Bool trace_suppression
)
49 s_trace_suppression
= trace_suppression
;
52 void DRD_(suppression_init
)(void)
54 tl_assert(s_suppressed
== 0);
55 tl_assert(s_traced
== 0);
56 s_suppressed
= DRD_(bm_new
)();
57 s_traced
= DRD_(bm_new
)();
58 tl_assert(s_suppressed
);
62 void DRD_(start_suppression
)(const Addr a1
, const Addr a2
,
63 const HChar
* const reason
)
65 if (s_trace_suppression
)
66 VG_(message
)(Vg_DebugMsg
, "start suppression of 0x%lx sz %ld (%s)\n",
70 DRD_(bm_access_range_store
)(s_suppressed
, a1
, a2
);
73 void DRD_(finish_suppression
)(const Addr a1
, const Addr a2
)
75 if (s_trace_suppression
) {
76 VG_(message
)(Vg_DebugMsg
, "finish suppression of 0x%lx sz %ld\n",
78 VG_(get_and_pp_StackTrace
)(VG_(get_running_tid
)(), 12);
82 DRD_(bm_clear_store
)(s_suppressed
, a1
, a2
);
86 * Return true if data race detection suppression has been requested for all
87 * bytes in the range a1 .. a2 - 1 inclusive. Return false in case the range
88 * is only partially suppressed or not suppressed at all.
90 Bool
DRD_(is_suppressed
)(const Addr a1
, const Addr a2
)
92 return DRD_(bm_has
)(s_suppressed
, a1
, a2
, eStore
);
96 * Return true if data race detection suppression has been requested for any
97 * of the bytes in the range a1 .. a2 - 1 inclusive. Return false in case none
98 * of the bytes in the specified range is suppressed.
100 Bool
DRD_(is_any_suppressed
)(const Addr a1
, const Addr a2
)
102 return DRD_(bm_has_any_store
)(s_suppressed
, a1
, a2
);
105 void DRD_(mark_hbvar
)(const Addr a1
)
107 DRD_(bm_access_range_load
)(s_suppressed
, a1
, a1
+ 1);
110 Bool
DRD_(range_contains_suppression_or_hbvar
)(const Addr a1
, const Addr a2
)
112 return DRD_(bm_has_any_access
)(s_suppressed
, a1
, a2
);
116 * Start tracing memory accesses in the range [a1,a2). If persistent == True,
117 * keep tracing even after memory deallocation and reallocation.
119 void DRD_(start_tracing_address_range
)(const Addr a1
, const Addr a2
,
120 const Bool persistent
)
124 if (s_trace_suppression
)
125 VG_(message
)(Vg_DebugMsg
, "start_tracing(0x%lx, %ld) %s\n",
126 a1
, a2
- a1
, persistent
? "persistent" : "non-persistent");
128 DRD_(bm_access_range_load
)(s_traced
, a1
, a2
);
130 DRD_(bm_access_range_store
)(s_traced
, a1
, a2
);
131 if (!DRD_(g_any_address_traced
) && a1
< a2
)
132 DRD_(g_any_address_traced
) = True
;
136 * Stop tracing memory accesses in the range [a1,a2).
138 void DRD_(stop_tracing_address_range
)(const Addr a1
, const Addr a2
)
142 if (s_trace_suppression
)
143 VG_(message
)(Vg_DebugMsg
, "stop_tracing(0x%lx, %ld)\n",
146 if (DRD_(g_any_address_traced
)) {
147 DRD_(bm_clear
)(s_traced
, a1
, a2
);
148 DRD_(g_any_address_traced
) = DRD_(bm_has_any_load_g
)(s_traced
);
152 Bool
DRD_(is_any_traced
)(const Addr a1
, const Addr a2
)
154 return DRD_(bm_has_any_access
)(s_traced
, a1
, a2
);
158 * Stop using the memory range [a1,a2). Stop tracing memory accesses to
159 * non-persistent address ranges.
161 void DRD_(suppression_stop_using_mem
)(const Addr a1
, const Addr a2
)
163 if (s_trace_suppression
) {
165 for (b
= a1
; b
< a2
; b
++) {
166 if (DRD_(bm_has_1
)(s_suppressed
, b
, eStore
)) {
167 VG_(message
)(Vg_DebugMsg
,
168 "stop_using_mem(0x%lx, %ld) finish suppression of"
169 " 0x%lx\n", a1
, a2
- a1
, b
);
175 DRD_(bm_clear
)(s_suppressed
, a1
, a2
);
176 DRD_(bm_clear_load
)(s_traced
, a1
, a2
);