blob: 5fe25f7e9908246eb675074cc255a652adc8429c [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
2 This file is part of drd, a data race detector.
3
4 Copyright (C) 2006-2007 Bart Van Assche
5 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"
27#include "pub_core_libcassert.h"
28#include "pub_core_libcprint.h"
29#include "pub_core_options.h" // VG_(clo_backtrace_size)
30#include "pub_drd_bitmap.h"
31#include "pub_tool_stacktrace.h" // VG_(get_and_pp_StackTrace)()
32#include "pub_tool_threadstate.h" // VG_(get_running_tid)()
33
34
35// Local variables.
36
37static struct bitmap* s_suppressed;
38static Bool s_trace_suppression;
39
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);
65 tl_assert(! drd_is_any_suppressed(a1, a2));
66 bm_access_range(s_suppressed, a1, a2 - a1, eStore);
67}
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);
75 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(),
76 VG_(clo_backtrace_size));
77 }
78
79 tl_assert(a1 < a2);
80 if (! drd_is_suppressed(a1, a2))
81 {
82 VG_(message)(Vg_DebugMsg, "?? not suppressed ??");
83 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(),
84 VG_(clo_backtrace_size));
85 tl_assert(False);
86 }
87 bm_clear(s_suppressed, a1, a2);
88}
89
90/**
91 * Return true if data race detection suppression has been requested for all
92 * bytes in the range a1 .. a2 - 1 inclusive. Return false in case the range
93 * is only partially suppressed or not suppressed at all.
94 */
95Bool drd_is_suppressed(const Addr a1, const Addr a2)
96{
97 return bm_has(s_suppressed, a1, a2, eStore);
98}
99
100/**
101 * Return true if data race detection suppression has been requested for any
102 * of the bytes in the range a1 .. a2 - 1 inclusive. Return false in case none
103 * of the bytes in the specified range is suppressed.
104 */
105Bool drd_is_any_suppressed(const Addr a1, const Addr a2)
106{
107 return bm_has_any(s_suppressed, a1, a2, eStore);
108}
109
110void drd_suppression_stop_using_mem(const Addr a1, const Addr a2)
111{
112 if (s_trace_suppression)
113 {
114 Addr b;
115 for (b = a1; b < a2; b++)
116 {
117 if (bm_has_1(s_suppressed, b, eStore))
118 {
119 VG_(message)(Vg_DebugMsg,
120 "stop_using_mem(0x%lx, %ld) finish suppression of 0x%lx",
121 a1, a2 - a1, b);
122 //VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), VG_(clo_backtrace_size));
123 }
124 }
125 }
126 tl_assert(a1);
127 tl_assert(a1 < a2);
128 bm_clear(s_suppressed, a1, a2);
129}
130
131/*
132 * Local variables:
133 * c-basic-offset: 3
134 * End:
135 */