blob: cfe4b037dcc31fc89d6371fda896d50492d7d885 [file] [log] [blame]
bartbedfd232009-03-26 19:07:15 +00001/* -*- mode: C; c-basic-offset: 3; -*- */
sewardjaf44c822007-11-25 14:01:38 +00002/*
bart86562bd2009-02-16 19:43:56 +00003 This file is part of drd, a thread error detector.
sewardjaf44c822007-11-25 14:01:38 +00004
sewardj9eecbbb2010-05-03 21:37:12 +00005 Copyright (C) 2006-2010 Bart Van Assche <bart.vanassche@gmail.com>.
sewardjaf44c822007-11-25 14:01:38 +00006
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
bart1335ecc2009-02-14 16:10:53 +000034/* Global variables. */
sewardjaf44c822007-11-25 14:01:38 +000035
bart1335ecc2009-02-14 16:10:53 +000036Bool DRD_(g_any_address_traced) = False;
sewardjaf44c822007-11-25 14:01:38 +000037
38
bart1335ecc2009-02-14 16:10:53 +000039/* Local variables. */
sewardjaf44c822007-11-25 14:01:38 +000040
bart1335ecc2009-02-14 16:10:53 +000041static struct bitmap* DRD_(s_suppressed);
bartb00ac4c2010-03-07 20:05:23 +000042static struct bitmap* DRD_(s_traced);
bart1335ecc2009-02-14 16:10:53 +000043static Bool DRD_(s_trace_suppression);
44
45
46/* Function definitions. */
47
48void DRD_(suppression_set_trace)(const Bool trace_suppression)
sewardjaf44c822007-11-25 14:01:38 +000049{
bart1335ecc2009-02-14 16:10:53 +000050 DRD_(s_trace_suppression) = trace_suppression;
sewardjaf44c822007-11-25 14:01:38 +000051}
52
bart1335ecc2009-02-14 16:10:53 +000053void DRD_(suppression_init)(void)
sewardjaf44c822007-11-25 14:01:38 +000054{
bartbedfd232009-03-26 19:07:15 +000055 tl_assert(DRD_(s_suppressed) == 0);
bartb00ac4c2010-03-07 20:05:23 +000056 tl_assert(DRD_(s_traced) == 0);
bartbedfd232009-03-26 19:07:15 +000057 DRD_(s_suppressed) = DRD_(bm_new)();
bartb00ac4c2010-03-07 20:05:23 +000058 DRD_(s_traced) = DRD_(bm_new)();
bartbedfd232009-03-26 19:07:15 +000059 tl_assert(DRD_(s_suppressed));
bartb00ac4c2010-03-07 20:05:23 +000060 tl_assert(DRD_(s_traced));
sewardjaf44c822007-11-25 14:01:38 +000061}
62
bart1335ecc2009-02-14 16:10:53 +000063void DRD_(start_suppression)(const Addr a1, const Addr a2,
64 const char* const reason)
sewardjaf44c822007-11-25 14:01:38 +000065{
bartbedfd232009-03-26 19:07:15 +000066 if (DRD_(s_trace_suppression))
67 {
sewardj1e29ebc2009-07-15 14:49:17 +000068 VG_(message)(Vg_DebugMsg, "start suppression of 0x%lx sz %ld (%s)\n",
bartbedfd232009-03-26 19:07:15 +000069 a1, a2 - a1, reason);
70 }
sewardjaf44c822007-11-25 14:01:38 +000071
bartbedfd232009-03-26 19:07:15 +000072 tl_assert(a1 < a2);
bartbedfd232009-03-26 19:07:15 +000073 DRD_(bm_access_range_store)(DRD_(s_suppressed), a1, a2);
sewardjaf44c822007-11-25 14:01:38 +000074}
75
bart1335ecc2009-02-14 16:10:53 +000076void DRD_(finish_suppression)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +000077{
bartbedfd232009-03-26 19:07:15 +000078 if (DRD_(s_trace_suppression))
79 {
sewardj1e29ebc2009-07-15 14:49:17 +000080 VG_(message)(Vg_DebugMsg, "finish suppression of 0x%lx sz %ld\n",
bartbedfd232009-03-26 19:07:15 +000081 a1, a2 - a1);
bart31b983d2010-02-21 14:52:59 +000082 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12);
bartbedfd232009-03-26 19:07:15 +000083 }
sewardjaf44c822007-11-25 14:01:38 +000084
bartbedfd232009-03-26 19:07:15 +000085 tl_assert(a1 < a2);
bartbedfd232009-03-26 19:07:15 +000086 DRD_(bm_clear_store)(DRD_(s_suppressed), a1, a2);
sewardjaf44c822007-11-25 14:01:38 +000087}
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 */
bart1335ecc2009-02-14 16:10:53 +000094Bool DRD_(is_suppressed)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +000095{
bartbedfd232009-03-26 19:07:15 +000096 return DRD_(bm_has)(DRD_(s_suppressed), a1, a2, eStore);
sewardjaf44c822007-11-25 14:01:38 +000097}
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 */
bart1335ecc2009-02-14 16:10:53 +0000104Bool DRD_(is_any_suppressed)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +0000105{
bartbedfd232009-03-26 19:07:15 +0000106 return DRD_(bm_has_any_store)(DRD_(s_suppressed), a1, a2);
sewardjaf44c822007-11-25 14:01:38 +0000107}
108
bartb00ac4c2010-03-07 20:05:23 +0000109void DRD_(mark_hbvar)(const Addr a1)
110{
111 DRD_(bm_access_range_load)(DRD_(s_suppressed), a1, a1 + 1);
112}
113
114Bool DRD_(range_contains_suppression_or_hbvar)(const Addr a1, const Addr a2)
115{
116 return DRD_(bm_has_any_access)(DRD_(s_suppressed), a1, a2);
117}
118
bart1335ecc2009-02-14 16:10:53 +0000119void DRD_(start_tracing_address_range)(const Addr a1, const Addr a2)
bart005dc972008-03-29 14:42:59 +0000120{
bartbedfd232009-03-26 19:07:15 +0000121 tl_assert(a1 < a2);
bart005dc972008-03-29 14:42:59 +0000122
bartb00ac4c2010-03-07 20:05:23 +0000123 DRD_(bm_access_range_load)(DRD_(s_traced), a1, a2);
bartbedfd232009-03-26 19:07:15 +0000124 if (! DRD_(g_any_address_traced))
125 {
126 DRD_(g_any_address_traced) = True;
127 }
bart005dc972008-03-29 14:42:59 +0000128}
129
bart1335ecc2009-02-14 16:10:53 +0000130void DRD_(stop_tracing_address_range)(const Addr a1, const Addr a2)
bart005dc972008-03-29 14:42:59 +0000131{
bartbedfd232009-03-26 19:07:15 +0000132 tl_assert(a1 < a2);
bart005dc972008-03-29 14:42:59 +0000133
bartb00ac4c2010-03-07 20:05:23 +0000134 DRD_(bm_clear_load)(DRD_(s_traced), a1, a2);
bartbedfd232009-03-26 19:07:15 +0000135 if (DRD_(g_any_address_traced))
136 {
137 DRD_(g_any_address_traced)
bartb00ac4c2010-03-07 20:05:23 +0000138 = DRD_(bm_has_any_load)(DRD_(s_traced), 0, ~(Addr)0);
bartbedfd232009-03-26 19:07:15 +0000139 }
bart005dc972008-03-29 14:42:59 +0000140}
141
bart1335ecc2009-02-14 16:10:53 +0000142Bool DRD_(is_any_traced)(const Addr a1, const Addr a2)
bart005dc972008-03-29 14:42:59 +0000143{
bartb00ac4c2010-03-07 20:05:23 +0000144 return DRD_(bm_has_any_load)(DRD_(s_traced), a1, a2);
bart005dc972008-03-29 14:42:59 +0000145}
146
bart1335ecc2009-02-14 16:10:53 +0000147void DRD_(suppression_stop_using_mem)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +0000148{
bartbedfd232009-03-26 19:07:15 +0000149 if (DRD_(s_trace_suppression))
150 {
151 Addr b;
152 for (b = a1; b < a2; b++)
sewardjaf44c822007-11-25 14:01:38 +0000153 {
bartbedfd232009-03-26 19:07:15 +0000154 if (DRD_(bm_has_1)(DRD_(s_suppressed), b, eStore))
155 {
156 VG_(message)(Vg_DebugMsg,
157 "stop_using_mem(0x%lx, %ld) finish suppression of"
sewardj1e29ebc2009-07-15 14:49:17 +0000158 " 0x%lx\n", a1, a2 - a1, b);
bartbedfd232009-03-26 19:07:15 +0000159 }
sewardjaf44c822007-11-25 14:01:38 +0000160 }
bartbedfd232009-03-26 19:07:15 +0000161 }
162 tl_assert(a1);
163 tl_assert(a1 < a2);
164 DRD_(bm_clear)(DRD_(s_suppressed), a1, a2);
bartb00ac4c2010-03-07 20:05:23 +0000165 DRD_(bm_clear)(DRD_(s_traced), a1, a2);
sewardjaf44c822007-11-25 14:01:38 +0000166}