blob: 63c7251d19aec161fb8df6227402583e12dc3913 [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
2 This file is part of drd, a data race detector.
3
sewardj85642922008-01-14 11:54:56 +00004 Copyright (C) 2006-2008 Bart Van Assche
sewardjaf44c822007-11-25 14:01:38 +00005 bart.vanassche@gmail.com
6
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
26#include "drd_suppression.h"
sewardjaf44c822007-11-25 14:01:38 +000027#include "pub_drd_bitmap.h"
sewardj85642922008-01-14 11:54:56 +000028#include "pub_tool_libcassert.h" // tl_assert()
sewardjaf44c822007-11-25 14:01:38 +000029#include "pub_tool_stacktrace.h" // VG_(get_and_pp_StackTrace)()
30#include "pub_tool_threadstate.h" // VG_(get_running_tid)()
sewardj85642922008-01-14 11:54:56 +000031#include "pub_tool_libcprint.h" // Vg_DebugMsg
sewardjaf44c822007-11-25 14:01:38 +000032
33
34// Local variables.
35
36static struct bitmap* s_suppressed;
37static Bool s_trace_suppression;
bart005dc972008-03-29 14:42:59 +000038Bool g_any_address_traced = False;
sewardjaf44c822007-11-25 14:01:38 +000039
40
41// Function definitions.
42
43void suppression_set_trace(const Bool trace_suppression)
44{
45 s_trace_suppression = trace_suppression;
46}
47
48void drd_suppression_init(void)
49{
50 tl_assert(s_suppressed == 0);
51 s_suppressed = bm_new();
52 tl_assert(s_suppressed);
53}
54
55void drd_start_suppression(const Addr a1, const Addr a2,
56 const char* const reason)
57{
58 if (s_trace_suppression)
59 {
60 VG_(message)(Vg_DebugMsg, "start suppression of 0x%lx sz %ld (%s)",
61 a1, a2 - a1, reason);
62 }
63
64 tl_assert(a1 < a2);
bartd43f8d32008-03-16 17:29:20 +000065 // tl_assert(! drd_is_any_suppressed(a1, a2));
bart36556122008-03-13 19:24:30 +000066 bm_access_range_store(s_suppressed, a1, a2);
sewardjaf44c822007-11-25 14:01:38 +000067}
68
69void drd_finish_suppression(const Addr a1, const Addr a2)
70{
71 if (s_trace_suppression)
72 {
73 VG_(message)(Vg_DebugMsg, "finish suppression of 0x%lx sz %ld",
74 a1, a2 - a1);
sewardj85642922008-01-14 11:54:56 +000075 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12);
sewardjaf44c822007-11-25 14:01:38 +000076 }
77
78 tl_assert(a1 < a2);
79 if (! drd_is_suppressed(a1, a2))
80 {
bartb78312c2008-02-29 11:00:17 +000081 VG_(message)(Vg_DebugMsg, "?? [0x%lx,0x%lx[ not suppressed ??", a1, a2);
sewardj85642922008-01-14 11:54:56 +000082 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12);
sewardjaf44c822007-11-25 14:01:38 +000083 tl_assert(False);
84 }
bart005dc972008-03-29 14:42:59 +000085 bm_clear_store(s_suppressed, a1, a2);
sewardjaf44c822007-11-25 14:01:38 +000086}
87
88/**
89 * Return true if data race detection suppression has been requested for all
90 * bytes in the range a1 .. a2 - 1 inclusive. Return false in case the range
91 * is only partially suppressed or not suppressed at all.
92 */
93Bool drd_is_suppressed(const Addr a1, const Addr a2)
94{
95 return bm_has(s_suppressed, a1, a2, eStore);
96}
97
98/**
99 * Return true if data race detection suppression has been requested for any
100 * of the bytes in the range a1 .. a2 - 1 inclusive. Return false in case none
101 * of the bytes in the specified range is suppressed.
102 */
103Bool drd_is_any_suppressed(const Addr a1, const Addr a2)
104{
105 return bm_has_any(s_suppressed, a1, a2, eStore);
106}
107
bart005dc972008-03-29 14:42:59 +0000108void drd_start_tracing_address_range(const Addr a1, const Addr a2)
109{
110 tl_assert(a1 < a2);
111
112 bm_access_range_load(s_suppressed, a1, a2);
113 if (! g_any_address_traced)
114 {
115 g_any_address_traced = True;
116 }
117}
118
119void drd_stop_tracing_address_range(const Addr a1, const Addr a2)
120{
121 tl_assert(a1 < a2);
122
123 bm_clear_load(s_suppressed, a1, a2);
124 if (g_any_address_traced)
125 {
126 g_any_address_traced = bm_has_any(s_suppressed, 0, ~(Addr)0, eLoad);
127 }
128}
129
130Bool drd_is_any_traced(const Addr a1, const Addr a2)
131{
132 return bm_has_any(s_suppressed, a1, a2, eLoad);
133}
134
sewardjaf44c822007-11-25 14:01:38 +0000135void drd_suppression_stop_using_mem(const Addr a1, const Addr a2)
136{
137 if (s_trace_suppression)
138 {
139 Addr b;
140 for (b = a1; b < a2; b++)
141 {
142 if (bm_has_1(s_suppressed, b, eStore))
143 {
144 VG_(message)(Vg_DebugMsg,
145 "stop_using_mem(0x%lx, %ld) finish suppression of 0x%lx",
146 a1, a2 - a1, b);
sewardjaf44c822007-11-25 14:01:38 +0000147 }
148 }
149 }
150 tl_assert(a1);
151 tl_assert(a1 < a2);
152 bm_clear(s_suppressed, a1, a2);
153}