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; |
| 38 | |
| 39 | |
| 40 | // Function definitions. |
| 41 | |
| 42 | void suppression_set_trace(const Bool trace_suppression) |
| 43 | { |
| 44 | s_trace_suppression = trace_suppression; |
| 45 | } |
| 46 | |
| 47 | void drd_suppression_init(void) |
| 48 | { |
| 49 | tl_assert(s_suppressed == 0); |
| 50 | s_suppressed = bm_new(); |
| 51 | tl_assert(s_suppressed); |
| 52 | } |
| 53 | |
| 54 | void drd_start_suppression(const Addr a1, const Addr a2, |
| 55 | const char* const reason) |
| 56 | { |
| 57 | if (s_trace_suppression) |
| 58 | { |
| 59 | VG_(message)(Vg_DebugMsg, "start suppression of 0x%lx sz %ld (%s)", |
| 60 | a1, a2 - a1, reason); |
| 61 | } |
| 62 | |
| 63 | tl_assert(a1 < a2); |
| 64 | tl_assert(! drd_is_any_suppressed(a1, a2)); |
| 65 | bm_access_range(s_suppressed, a1, a2 - a1, eStore); |
| 66 | } |
| 67 | |
| 68 | void drd_finish_suppression(const Addr a1, const Addr a2) |
| 69 | { |
| 70 | if (s_trace_suppression) |
| 71 | { |
| 72 | VG_(message)(Vg_DebugMsg, "finish suppression of 0x%lx sz %ld", |
| 73 | a1, a2 - a1); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 74 | VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | tl_assert(a1 < a2); |
| 78 | if (! drd_is_suppressed(a1, a2)) |
| 79 | { |
bart | b78312c | 2008-02-29 11:00:17 +0000 | [diff] [blame^] | 80 | VG_(message)(Vg_DebugMsg, "?? [0x%lx,0x%lx[ not suppressed ??", a1, a2); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 81 | VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(), 12); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 82 | tl_assert(False); |
| 83 | } |
| 84 | bm_clear(s_suppressed, a1, a2); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Return true if data race detection suppression has been requested for all |
| 89 | * bytes in the range a1 .. a2 - 1 inclusive. Return false in case the range |
| 90 | * is only partially suppressed or not suppressed at all. |
| 91 | */ |
| 92 | Bool drd_is_suppressed(const Addr a1, const Addr a2) |
| 93 | { |
| 94 | return bm_has(s_suppressed, a1, a2, eStore); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Return true if data race detection suppression has been requested for any |
| 99 | * of the bytes in the range a1 .. a2 - 1 inclusive. Return false in case none |
| 100 | * of the bytes in the specified range is suppressed. |
| 101 | */ |
| 102 | Bool drd_is_any_suppressed(const Addr a1, const Addr a2) |
| 103 | { |
| 104 | return bm_has_any(s_suppressed, a1, a2, eStore); |
| 105 | } |
| 106 | |
| 107 | void drd_suppression_stop_using_mem(const Addr a1, const Addr a2) |
| 108 | { |
| 109 | if (s_trace_suppression) |
| 110 | { |
| 111 | Addr b; |
| 112 | for (b = a1; b < a2; b++) |
| 113 | { |
| 114 | if (bm_has_1(s_suppressed, b, eStore)) |
| 115 | { |
| 116 | VG_(message)(Vg_DebugMsg, |
| 117 | "stop_using_mem(0x%lx, %ld) finish suppression of 0x%lx", |
| 118 | a1, a2 - a1, b); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | } |
| 122 | tl_assert(a1); |
| 123 | tl_assert(a1 < a2); |
| 124 | bm_clear(s_suppressed, a1, a2); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Local variables: |
| 129 | * c-basic-offset: 3 |
| 130 | * End: |
| 131 | */ |