blob: 513851ed0ed70793330e9c082bf7fd63a5e0fa23 [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);
bart4bb53d82008-02-28 19:06:34 +000078#if 0
sewardjaf44c822007-11-25 14:01:38 +000079 if (! drd_is_suppressed(a1, a2))
80 {
81 VG_(message)(Vg_DebugMsg, "?? not suppressed ??");
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 }
bart4bb53d82008-02-28 19:06:34 +000085#endif
sewardjaf44c822007-11-25 14:01:38 +000086 bm_clear(s_suppressed, a1, a2);
87}
88
89/**
90 * Return true if data race detection suppression has been requested for all
91 * bytes in the range a1 .. a2 - 1 inclusive. Return false in case the range
92 * is only partially suppressed or not suppressed at all.
93 */
94Bool drd_is_suppressed(const Addr a1, const Addr a2)
95{
96 return bm_has(s_suppressed, a1, a2, eStore);
97}
98
99/**
100 * Return true if data race detection suppression has been requested for any
101 * of the bytes in the range a1 .. a2 - 1 inclusive. Return false in case none
102 * of the bytes in the specified range is suppressed.
103 */
104Bool drd_is_any_suppressed(const Addr a1, const Addr a2)
105{
106 return bm_has_any(s_suppressed, a1, a2, eStore);
107}
108
109void drd_suppression_stop_using_mem(const Addr a1, const Addr a2)
110{
111 if (s_trace_suppression)
112 {
113 Addr b;
114 for (b = a1; b < a2; b++)
115 {
116 if (bm_has_1(s_suppressed, b, eStore))
117 {
118 VG_(message)(Vg_DebugMsg,
119 "stop_using_mem(0x%lx, %ld) finish suppression of 0x%lx",
120 a1, a2 - a1, b);
sewardjaf44c822007-11-25 14:01:38 +0000121 }
122 }
123 }
124 tl_assert(a1);
125 tl_assert(a1 < a2);
126 bm_clear(s_suppressed, a1, a2);
127}
128
129/*
130 * Local variables:
131 * c-basic-offset: 3
132 * End:
133 */