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