sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 2 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 3 | |
bart | d4bab99 | 2013-10-04 05:55:30 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2013 Bart Van Assche <bvanassche@acm.org>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | |
| 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" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 26 | #include "pub_drd_bitmap.h" |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 27 | #include "pub_tool_libcassert.h" // tl_assert() |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 28 | #include "pub_tool_stacktrace.h" // VG_(get_and_pp_StackTrace)() |
| 29 | #include "pub_tool_threadstate.h" // VG_(get_running_tid)() |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 30 | #include "pub_tool_libcprint.h" // Vg_DebugMsg |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 31 | |
| 32 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 33 | /* Global variables. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 34 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 35 | Bool DRD_(g_any_address_traced) = False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 36 | |
| 37 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 38 | /* Local variables. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 39 | |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 40 | static struct bitmap* s_suppressed; |
| 41 | static struct bitmap* s_traced; |
| 42 | static Bool s_trace_suppression; |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 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 | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 49 | 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 | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 54 | 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); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 60 | } |
| 61 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 62 | void DRD_(start_suppression)(const Addr a1, const Addr a2, |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 63 | const HChar* const reason) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 64 | { |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 65 | if (s_trace_suppression) |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 66 | VG_(message)(Vg_DebugMsg, "start suppression of 0x%lx sz %ld (%s)\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 67 | a1, a2 - a1, reason); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 68 | |
bart | a300398 | 2010-09-08 16:29:17 +0000 | [diff] [blame] | 69 | tl_assert(a1 <= a2); |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 70 | DRD_(bm_access_range_store)(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 | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 75 | if (s_trace_suppression) { |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 76 | VG_(message)(Vg_DebugMsg, "finish suppression of 0x%lx sz %ld\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 77 | a1, a2 - a1); |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 78 | VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 79 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 80 | |
bart | a300398 | 2010-09-08 16:29:17 +0000 | [diff] [blame] | 81 | tl_assert(a1 <= a2); |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 82 | DRD_(bm_clear_store)(s_suppressed, a1, a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 83 | } |
| 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 | */ |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 90 | Bool DRD_(is_suppressed)(const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 91 | { |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 92 | return DRD_(bm_has)(s_suppressed, a1, a2, eStore); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 93 | } |
| 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 | */ |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 100 | Bool DRD_(is_any_suppressed)(const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 101 | { |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 102 | return DRD_(bm_has_any_store)(s_suppressed, a1, a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 103 | } |
| 104 | |
bart | b00ac4c | 2010-03-07 20:05:23 +0000 | [diff] [blame] | 105 | void DRD_(mark_hbvar)(const Addr a1) |
| 106 | { |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 107 | DRD_(bm_access_range_load)(s_suppressed, a1, a1 + 1); |
bart | b00ac4c | 2010-03-07 20:05:23 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | Bool DRD_(range_contains_suppression_or_hbvar)(const Addr a1, const Addr a2) |
| 111 | { |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 112 | return DRD_(bm_has_any_access)(s_suppressed, a1, a2); |
bart | b00ac4c | 2010-03-07 20:05:23 +0000 | [diff] [blame] | 113 | } |
| 114 | |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 115 | /** |
| 116 | * Start tracing memory accesses in the range [a1,a2). If persistent == True, |
| 117 | * keep tracing even after memory deallocation and reallocation. |
| 118 | */ |
| 119 | void DRD_(start_tracing_address_range)(const Addr a1, const Addr a2, |
| 120 | const Bool persistent) |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 121 | { |
bart | a300398 | 2010-09-08 16:29:17 +0000 | [diff] [blame] | 122 | tl_assert(a1 <= a2); |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 123 | |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 124 | if (s_trace_suppression) |
| 125 | VG_(message)(Vg_DebugMsg, "start_tracing(0x%lx, %ld) %s\n", |
| 126 | a1, a2 - a1, persistent ? "persistent" : "non-persistent"); |
| 127 | |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 128 | DRD_(bm_access_range_load)(s_traced, a1, a2); |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 129 | if (persistent) |
| 130 | DRD_(bm_access_range_store)(s_traced, a1, a2); |
| 131 | if (!DRD_(g_any_address_traced) && a1 < a2) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 132 | DRD_(g_any_address_traced) = True; |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 133 | } |
| 134 | |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 135 | /** |
| 136 | * Stop tracing memory accesses in the range [a1,a2). |
| 137 | */ |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 138 | void DRD_(stop_tracing_address_range)(const Addr a1, const Addr a2) |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 139 | { |
bart | a300398 | 2010-09-08 16:29:17 +0000 | [diff] [blame] | 140 | tl_assert(a1 <= a2); |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 141 | |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 142 | if (s_trace_suppression) |
| 143 | VG_(message)(Vg_DebugMsg, "stop_tracing(0x%lx, %ld)\n", |
| 144 | a1, a2 - a1); |
| 145 | |
| 146 | if (DRD_(g_any_address_traced)) { |
| 147 | DRD_(bm_clear)(s_traced, a1, a2); |
| 148 | DRD_(g_any_address_traced) = DRD_(bm_has_any_load_g)(s_traced); |
| 149 | } |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 150 | } |
| 151 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 152 | Bool DRD_(is_any_traced)(const Addr a1, const Addr a2) |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 153 | { |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 154 | return DRD_(bm_has_any_access)(s_traced, a1, a2); |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 155 | } |
| 156 | |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 157 | /** |
| 158 | * Stop using the memory range [a1,a2). Stop tracing memory accesses to |
| 159 | * non-persistent address ranges. |
| 160 | */ |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 161 | void DRD_(suppression_stop_using_mem)(const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 162 | { |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 163 | if (s_trace_suppression) { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 164 | Addr b; |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 165 | for (b = a1; b < a2; b++) { |
| 166 | if (DRD_(bm_has_1)(s_suppressed, b, eStore)) { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 167 | VG_(message)(Vg_DebugMsg, |
| 168 | "stop_using_mem(0x%lx, %ld) finish suppression of" |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 169 | " 0x%lx\n", a1, a2 - a1, b); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 170 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 171 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 172 | } |
| 173 | tl_assert(a1); |
bart | a300398 | 2010-09-08 16:29:17 +0000 | [diff] [blame] | 174 | tl_assert(a1 <= a2); |
bart | 2e2f213 | 2012-01-16 13:08:05 +0000 | [diff] [blame] | 175 | DRD_(bm_clear)(s_suppressed, a1, a2); |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 176 | DRD_(bm_clear_load)(s_traced, a1, a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 177 | } |