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