sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | This file is part of drd, a data race detector. |
| 3 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2008 Bart Van Assche |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 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" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 27 | #include "pub_drd_bitmap.h" |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 28 | #include "pub_tool_libcassert.h" // tl_assert() |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 29 | #include "pub_tool_stacktrace.h" // VG_(get_and_pp_StackTrace)() |
| 30 | #include "pub_tool_threadstate.h" // VG_(get_running_tid)() |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 31 | #include "pub_tool_libcprint.h" // Vg_DebugMsg |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 32 | |
| 33 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 34 | /* Global variables. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 35 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 36 | Bool DRD_(g_any_address_traced) = False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 37 | |
| 38 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 39 | /* Local variables. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 40 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 41 | static struct bitmap* DRD_(s_suppressed); |
| 42 | static Bool DRD_(s_trace_suppression); |
| 43 | |
| 44 | |
| 45 | /* Function definitions. */ |
| 46 | |
| 47 | void DRD_(suppression_set_trace)(const Bool trace_suppression) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 48 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 49 | DRD_(s_trace_suppression) = trace_suppression; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 50 | } |
| 51 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 52 | void DRD_(suppression_init)(void) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 53 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 54 | tl_assert(DRD_(s_suppressed) == 0); |
| 55 | DRD_(s_suppressed) = bm_new(); |
| 56 | tl_assert(DRD_(s_suppressed)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 57 | } |
| 58 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 59 | void DRD_(start_suppression)(const Addr a1, const Addr a2, |
| 60 | const char* const reason) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 61 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 62 | if (DRD_(s_trace_suppression)) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 63 | { |
| 64 | VG_(message)(Vg_DebugMsg, "start suppression of 0x%lx sz %ld (%s)", |
| 65 | a1, a2 - a1, reason); |
| 66 | } |
| 67 | |
| 68 | tl_assert(a1 < a2); |
bart | d43f8d3 | 2008-03-16 17:29:20 +0000 | [diff] [blame] | 69 | // tl_assert(! drd_is_any_suppressed(a1, a2)); |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 70 | bm_access_range_store(DRD_(s_suppressed), a1, a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 71 | } |
| 72 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 73 | void DRD_(finish_suppression)(const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 74 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 75 | if (DRD_(s_trace_suppression)) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 76 | { |
| 77 | VG_(message)(Vg_DebugMsg, "finish suppression of 0x%lx sz %ld", |
| 78 | a1, a2 - a1); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 79 | VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | tl_assert(a1 < a2); |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 83 | if (! DRD_(is_suppressed)(a1, a2)) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 84 | { |
bart | b78312c | 2008-02-29 11:00:17 +0000 | [diff] [blame] | 85 | VG_(message)(Vg_DebugMsg, "?? [0x%lx,0x%lx[ not suppressed ??", a1, a2); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 86 | VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 87 | tl_assert(False); |
| 88 | } |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 89 | bm_clear_store(DRD_(s_suppressed), a1, a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Return true if data race detection suppression has been requested for all |
| 94 | * bytes in the range a1 .. a2 - 1 inclusive. Return false in case the range |
| 95 | * is only partially suppressed or not suppressed at all. |
| 96 | */ |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 97 | Bool DRD_(is_suppressed)(const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 98 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 99 | return bm_has(DRD_(s_suppressed), a1, a2, eStore); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Return true if data race detection suppression has been requested for any |
| 104 | * of the bytes in the range a1 .. a2 - 1 inclusive. Return false in case none |
| 105 | * of the bytes in the specified range is suppressed. |
| 106 | */ |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 107 | Bool DRD_(is_any_suppressed)(const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 108 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 109 | return bm_has_any_store(DRD_(s_suppressed), a1, a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 110 | } |
| 111 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 112 | void DRD_(start_tracing_address_range)(const Addr a1, const Addr a2) |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 113 | { |
| 114 | tl_assert(a1 < a2); |
| 115 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 116 | bm_access_range_load(DRD_(s_suppressed), a1, a2); |
| 117 | if (! DRD_(g_any_address_traced)) |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 118 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 119 | DRD_(g_any_address_traced) = True; |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 123 | void DRD_(stop_tracing_address_range)(const Addr a1, const Addr a2) |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 124 | { |
| 125 | tl_assert(a1 < a2); |
| 126 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 127 | bm_clear_load(DRD_(s_suppressed), a1, a2); |
| 128 | if (DRD_(g_any_address_traced)) |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 129 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 130 | DRD_(g_any_address_traced) |
| 131 | = bm_has_any_load(DRD_(s_suppressed), 0, ~(Addr)0); |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 135 | Bool DRD_(is_any_traced)(const Addr a1, const Addr a2) |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 136 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 137 | return bm_has_any_load(DRD_(s_suppressed), a1, a2); |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 138 | } |
| 139 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 140 | void DRD_(suppression_stop_using_mem)(const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 141 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 142 | if (DRD_(s_trace_suppression)) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 143 | { |
| 144 | Addr b; |
| 145 | for (b = a1; b < a2; b++) |
| 146 | { |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 147 | if (bm_has_1(DRD_(s_suppressed), b, eStore)) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 148 | { |
| 149 | VG_(message)(Vg_DebugMsg, |
| 150 | "stop_using_mem(0x%lx, %ld) finish suppression of 0x%lx", |
| 151 | a1, a2 - a1, b); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | } |
| 155 | tl_assert(a1); |
| 156 | tl_assert(a1 < a2); |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame^] | 157 | bm_clear(DRD_(s_suppressed), a1, a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 158 | } |