blob: 69c48c482a54df687f55e3b7cd7729299f4bc379 [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
bart86562bd2009-02-16 19:43:56 +00002 This file is part of drd, a thread error detector.
sewardjaf44c822007-11-25 14:01:38 +00003
bart922304f2011-03-13 12:02:44 +00004 Copyright (C) 2006-2011 Bart Van Assche <bvanassche@acm.org>.
sewardjaf44c822007-11-25 14:01:38 +00005
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307, USA.
20
21 The GNU General Public License is contained in the file COPYING.
22*/
23
24
25#include "drd_suppression.h"
sewardjaf44c822007-11-25 14:01:38 +000026#include "pub_drd_bitmap.h"
sewardj85642922008-01-14 11:54:56 +000027#include "pub_tool_libcassert.h" // tl_assert()
sewardjaf44c822007-11-25 14:01:38 +000028#include "pub_tool_stacktrace.h" // VG_(get_and_pp_StackTrace)()
29#include "pub_tool_threadstate.h" // VG_(get_running_tid)()
sewardj85642922008-01-14 11:54:56 +000030#include "pub_tool_libcprint.h" // Vg_DebugMsg
sewardjaf44c822007-11-25 14:01:38 +000031
32
bart1335ecc2009-02-14 16:10:53 +000033/* Global variables. */
sewardjaf44c822007-11-25 14:01:38 +000034
bart1335ecc2009-02-14 16:10:53 +000035Bool DRD_(g_any_address_traced) = False;
sewardjaf44c822007-11-25 14:01:38 +000036
37
bart1335ecc2009-02-14 16:10:53 +000038/* Local variables. */
sewardjaf44c822007-11-25 14:01:38 +000039
bart2e2f2132012-01-16 13:08:05 +000040static struct bitmap* s_suppressed;
41static struct bitmap* s_traced;
42static Bool s_trace_suppression;
bart1335ecc2009-02-14 16:10:53 +000043
44
45/* Function definitions. */
46
47void DRD_(suppression_set_trace)(const Bool trace_suppression)
sewardjaf44c822007-11-25 14:01:38 +000048{
bart2e2f2132012-01-16 13:08:05 +000049 s_trace_suppression = trace_suppression;
sewardjaf44c822007-11-25 14:01:38 +000050}
51
bart1335ecc2009-02-14 16:10:53 +000052void DRD_(suppression_init)(void)
sewardjaf44c822007-11-25 14:01:38 +000053{
bart2e2f2132012-01-16 13:08:05 +000054 tl_assert(s_suppressed == 0);
55 tl_assert(s_traced == 0);
56 s_suppressed = DRD_(bm_new)();
57 s_traced = DRD_(bm_new)();
58 tl_assert(s_suppressed);
59 tl_assert(s_traced);
sewardjaf44c822007-11-25 14:01:38 +000060}
61
bart1335ecc2009-02-14 16:10:53 +000062void DRD_(start_suppression)(const Addr a1, const Addr a2,
63 const char* const reason)
sewardjaf44c822007-11-25 14:01:38 +000064{
bart2e2f2132012-01-16 13:08:05 +000065 if (s_trace_suppression)
sewardj1e29ebc2009-07-15 14:49:17 +000066 VG_(message)(Vg_DebugMsg, "start suppression of 0x%lx sz %ld (%s)\n",
bartbedfd232009-03-26 19:07:15 +000067 a1, a2 - a1, reason);
sewardjaf44c822007-11-25 14:01:38 +000068
barta3003982010-09-08 16:29:17 +000069 tl_assert(a1 <= a2);
bart2e2f2132012-01-16 13:08:05 +000070 DRD_(bm_access_range_store)(s_suppressed, a1, a2);
sewardjaf44c822007-11-25 14:01:38 +000071}
72
bart1335ecc2009-02-14 16:10:53 +000073void DRD_(finish_suppression)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +000074{
bart2e2f2132012-01-16 13:08:05 +000075 if (s_trace_suppression) {
sewardj1e29ebc2009-07-15 14:49:17 +000076 VG_(message)(Vg_DebugMsg, "finish suppression of 0x%lx sz %ld\n",
bartbedfd232009-03-26 19:07:15 +000077 a1, a2 - a1);
bart31b983d2010-02-21 14:52:59 +000078 VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12);
bartbedfd232009-03-26 19:07:15 +000079 }
sewardjaf44c822007-11-25 14:01:38 +000080
barta3003982010-09-08 16:29:17 +000081 tl_assert(a1 <= a2);
bart2e2f2132012-01-16 13:08:05 +000082 DRD_(bm_clear_store)(s_suppressed, a1, a2);
sewardjaf44c822007-11-25 14:01:38 +000083}
84
85/**
86 * Return true if data race detection suppression has been requested for all
87 * bytes in the range a1 .. a2 - 1 inclusive. Return false in case the range
88 * is only partially suppressed or not suppressed at all.
89 */
bart1335ecc2009-02-14 16:10:53 +000090Bool DRD_(is_suppressed)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +000091{
bart2e2f2132012-01-16 13:08:05 +000092 return DRD_(bm_has)(s_suppressed, a1, a2, eStore);
sewardjaf44c822007-11-25 14:01:38 +000093}
94
95/**
96 * Return true if data race detection suppression has been requested for any
97 * of the bytes in the range a1 .. a2 - 1 inclusive. Return false in case none
98 * of the bytes in the specified range is suppressed.
99 */
bart1335ecc2009-02-14 16:10:53 +0000100Bool DRD_(is_any_suppressed)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +0000101{
bart2e2f2132012-01-16 13:08:05 +0000102 return DRD_(bm_has_any_store)(s_suppressed, a1, a2);
sewardjaf44c822007-11-25 14:01:38 +0000103}
104
bartb00ac4c2010-03-07 20:05:23 +0000105void DRD_(mark_hbvar)(const Addr a1)
106{
bart2e2f2132012-01-16 13:08:05 +0000107 DRD_(bm_access_range_load)(s_suppressed, a1, a1 + 1);
bartb00ac4c2010-03-07 20:05:23 +0000108}
109
110Bool DRD_(range_contains_suppression_or_hbvar)(const Addr a1, const Addr a2)
111{
bart2e2f2132012-01-16 13:08:05 +0000112 return DRD_(bm_has_any_access)(s_suppressed, a1, a2);
bartb00ac4c2010-03-07 20:05:23 +0000113}
114
bart1335ecc2009-02-14 16:10:53 +0000115void DRD_(start_tracing_address_range)(const Addr a1, const Addr a2)
bart005dc972008-03-29 14:42:59 +0000116{
barta3003982010-09-08 16:29:17 +0000117 tl_assert(a1 <= a2);
bart005dc972008-03-29 14:42:59 +0000118
bart2e2f2132012-01-16 13:08:05 +0000119 DRD_(bm_access_range_load)(s_traced, a1, a2);
120 if (!DRD_(g_any_address_traced))
bartbedfd232009-03-26 19:07:15 +0000121 DRD_(g_any_address_traced) = True;
bart005dc972008-03-29 14:42:59 +0000122}
123
bart1335ecc2009-02-14 16:10:53 +0000124void DRD_(stop_tracing_address_range)(const Addr a1, const Addr a2)
bart005dc972008-03-29 14:42:59 +0000125{
barta3003982010-09-08 16:29:17 +0000126 tl_assert(a1 <= a2);
bart005dc972008-03-29 14:42:59 +0000127
bart2e2f2132012-01-16 13:08:05 +0000128 DRD_(bm_clear_load)(s_traced, a1, a2);
bartbedfd232009-03-26 19:07:15 +0000129 if (DRD_(g_any_address_traced))
bartbedfd232009-03-26 19:07:15 +0000130 DRD_(g_any_address_traced)
bart2e2f2132012-01-16 13:08:05 +0000131 = DRD_(bm_has_any_load_g)(s_traced);
bart005dc972008-03-29 14:42:59 +0000132}
133
bart1335ecc2009-02-14 16:10:53 +0000134Bool DRD_(is_any_traced)(const Addr a1, const Addr a2)
bart005dc972008-03-29 14:42:59 +0000135{
bart2e2f2132012-01-16 13:08:05 +0000136 return DRD_(bm_has_any_load)(s_traced, a1, a2);
bart005dc972008-03-29 14:42:59 +0000137}
138
bart1335ecc2009-02-14 16:10:53 +0000139void DRD_(suppression_stop_using_mem)(const Addr a1, const Addr a2)
sewardjaf44c822007-11-25 14:01:38 +0000140{
bart2e2f2132012-01-16 13:08:05 +0000141 if (s_trace_suppression) {
bartbedfd232009-03-26 19:07:15 +0000142 Addr b;
bart2e2f2132012-01-16 13:08:05 +0000143 for (b = a1; b < a2; b++) {
144 if (DRD_(bm_has_1)(s_suppressed, b, eStore)) {
bartbedfd232009-03-26 19:07:15 +0000145 VG_(message)(Vg_DebugMsg,
146 "stop_using_mem(0x%lx, %ld) finish suppression of"
sewardj1e29ebc2009-07-15 14:49:17 +0000147 " 0x%lx\n", a1, a2 - a1, b);
bartbedfd232009-03-26 19:07:15 +0000148 }
sewardjaf44c822007-11-25 14:01:38 +0000149 }
bartbedfd232009-03-26 19:07:15 +0000150 }
151 tl_assert(a1);
barta3003982010-09-08 16:29:17 +0000152 tl_assert(a1 <= a2);
bart2e2f2132012-01-16 13:08:05 +0000153 DRD_(bm_clear)(s_suppressed, a1, a2);
154 DRD_(bm_clear)(s_traced, a1, a2);
sewardjaf44c822007-11-25 14:01:38 +0000155}