blob: 71a4c608e7887443a107af32b3797991ec9ceab1 [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;
38
39
40// Function definitions.
41
42void suppression_set_trace(const Bool trace_suppression)
43{
44 s_trace_suppression = trace_suppression;
45}
46
47void drd_suppression_init(void)
48{
49 tl_assert(s_suppressed == 0);
50 s_suppressed = bm_new();
51 tl_assert(s_suppressed);
52}
53
54void drd_start_suppression(const Addr a1, const Addr a2,
55 const char* const reason)
56{
57 if (s_trace_suppression)
58 {
59 VG_(message)(Vg_DebugMsg, "start suppression of 0x%lx sz %ld (%s)",
60 a1, a2 - a1, reason);
61 }
62
63 tl_assert(a1 < a2);
64 tl_assert(! drd_is_any_suppressed(a1, a2));
65 bm_access_range(s_suppressed, a1, a2 - a1, eStore);
66}
67
68void drd_finish_suppression(const Addr a1, const Addr a2)
69{
70 if (s_trace_suppression)
71 {
72 VG_(message)(Vg_DebugMsg, "finish suppression of 0x%lx sz %ld",
73 a1, a2 - a1);
sewardj85642922008-01-14 11:54:56 +000074 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12);
sewardjaf44c822007-11-25 14:01:38 +000075 }
76
77 tl_assert(a1 < a2);
78 if (! drd_is_suppressed(a1, a2))
79 {
bartb78312c2008-02-29 11:00:17 +000080 VG_(message)(Vg_DebugMsg, "?? [0x%lx,0x%lx[ not suppressed ??", a1, a2);
sewardj85642922008-01-14 11:54:56 +000081 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12);
sewardjaf44c822007-11-25 14:01:38 +000082 tl_assert(False);
83 }
84 bm_clear(s_suppressed, a1, a2);
85}
86
87/**
88 * Return true if data race detection suppression has been requested for all
89 * bytes in the range a1 .. a2 - 1 inclusive. Return false in case the range
90 * is only partially suppressed or not suppressed at all.
91 */
92Bool drd_is_suppressed(const Addr a1, const Addr a2)
93{
94 return bm_has(s_suppressed, a1, a2, eStore);
95}
96
97/**
98 * Return true if data race detection suppression has been requested for any
99 * of the bytes in the range a1 .. a2 - 1 inclusive. Return false in case none
100 * of the bytes in the specified range is suppressed.
101 */
102Bool drd_is_any_suppressed(const Addr a1, const Addr a2)
103{
104 return bm_has_any(s_suppressed, a1, a2, eStore);
105}
106
107void drd_suppression_stop_using_mem(const Addr a1, const Addr a2)
108{
109 if (s_trace_suppression)
110 {
111 Addr b;
112 for (b = a1; b < a2; b++)
113 {
114 if (bm_has_1(s_suppressed, b, eStore))
115 {
116 VG_(message)(Vg_DebugMsg,
117 "stop_using_mem(0x%lx, %ld) finish suppression of 0x%lx",
118 a1, a2 - a1, b);
sewardjaf44c822007-11-25 14:01:38 +0000119 }
120 }
121 }
122 tl_assert(a1);
123 tl_assert(a1 < a2);
124 bm_clear(s_suppressed, a1, a2);
125}
126
127/*
128 * Local variables:
129 * c-basic-offset: 3
130 * End:
131 */