bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 1 | /* -*- mode: C; c-basic-offset: 3; -*- */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 2 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 3 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 4 | |
bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 5 | Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 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 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 26 | #include "drd_barrier.h" |
bart | 4bb53d8 | 2008-02-28 19:06:34 +0000 | [diff] [blame] | 27 | #include "drd_clientobj.h" |
bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 28 | #include "drd_clientreq.h" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 29 | #include "drd_cond.h" |
| 30 | #include "drd_error.h" |
bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 31 | #include "drd_load_store.h" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 32 | #include "drd_malloc_wrappers.h" |
| 33 | #include "drd_mutex.h" |
bart | 5bd9f2d | 2008-03-03 20:31:58 +0000 | [diff] [blame] | 34 | #include "drd_rwlock.h" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 35 | #include "drd_segment.h" |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 36 | #include "drd_semaphore.h" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 37 | #include "drd_suppression.h" |
| 38 | #include "drd_thread.h" |
bart | eacd916 | 2008-06-16 20:22:18 +0000 | [diff] [blame] | 39 | #include "libvex_guest_offsets.h" |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 40 | #include "pub_drd_bitmap.h" |
bart | 024a95a | 2008-04-01 18:27:41 +0000 | [diff] [blame] | 41 | #include "pub_tool_vki.h" // Must be included before pub_tool_libcproc |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 42 | #include "pub_tool_basics.h" |
| 43 | #include "pub_tool_debuginfo.h" // VG_(describe_IP)() |
| 44 | #include "pub_tool_libcassert.h" // tl_assert() |
| 45 | #include "pub_tool_libcbase.h" // VG_(strcmp) |
| 46 | #include "pub_tool_libcprint.h" // VG_(printf) |
| 47 | #include "pub_tool_libcproc.h" |
| 48 | #include "pub_tool_machine.h" |
bart | 024a95a | 2008-04-01 18:27:41 +0000 | [diff] [blame] | 49 | #include "pub_tool_mallocfree.h" // VG_(malloc)(), VG_(free)() |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 50 | #include "pub_tool_options.h" // command line options |
bart | ceded21 | 2008-03-26 17:39:52 +0000 | [diff] [blame] | 51 | #include "pub_tool_replacemalloc.h" |
bart | 72b751c | 2008-03-01 13:44:24 +0000 | [diff] [blame] | 52 | #include "pub_tool_threadstate.h" // VG_(get_running_tid)() |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 53 | #include "pub_tool_tooliface.h" |
| 54 | |
| 55 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 56 | /* Local variables. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 57 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 58 | static Bool DRD_(s_print_stats) = False; |
| 59 | static Bool DRD_(s_var_info) = False; |
| 60 | static Bool DRD_(s_show_stack_usage) = False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 61 | |
| 62 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 63 | /** |
| 64 | * Implement the needs_command_line_options for drd. |
| 65 | */ |
| 66 | static Bool DRD_(process_cmd_line_option)(Char* arg) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 67 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 68 | int check_stack_accesses = -1; |
| 69 | int exclusive_threshold_ms = -1; |
| 70 | int report_signal_unlocked = -1; |
| 71 | int segment_merging = -1; |
| 72 | int shared_threshold_ms = -1; |
| 73 | int show_confl_seg = -1; |
| 74 | int trace_barrier = -1; |
| 75 | int trace_clientobj = -1; |
| 76 | int trace_cond = -1; |
| 77 | int trace_csw = -1; |
| 78 | int trace_fork_join = -1; |
| 79 | int trace_conflict_set = -1; |
| 80 | int trace_mutex = -1; |
| 81 | int trace_rwlock = -1; |
| 82 | int trace_segment = -1; |
| 83 | int trace_semaphore = -1; |
| 84 | int trace_suppression = -1; |
| 85 | Char* trace_address = 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 86 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 87 | if VG_BOOL_CLO(arg, "--check-stack-var", check_stack_accesses) {} |
| 88 | else if VG_BOOL_CLO(arg, "--drd-stats", DRD_(s_print_stats)) {} |
| 89 | else if VG_BOOL_CLO(arg,"--report-signal-unlocked",report_signal_unlocked) {} |
| 90 | else if VG_BOOL_CLO(arg, "--segment-merging", segment_merging) {} |
| 91 | else if VG_BOOL_CLO(arg, "--show-confl-seg", show_confl_seg) {} |
| 92 | else if VG_BOOL_CLO(arg, "--show-stack-usage", |
| 93 | DRD_(s_show_stack_usage)) {} |
| 94 | else if VG_BOOL_CLO(arg, "--trace-barrier", trace_barrier) {} |
| 95 | else if VG_BOOL_CLO(arg, "--trace-clientobj", trace_clientobj) {} |
| 96 | else if VG_BOOL_CLO(arg, "--trace-cond", trace_cond) {} |
| 97 | else if VG_BOOL_CLO(arg, "--trace-conflict-set", trace_conflict_set) {} |
| 98 | else if VG_BOOL_CLO(arg, "--trace-csw", trace_csw) {} |
| 99 | else if VG_BOOL_CLO(arg, "--trace-fork-join", trace_fork_join) {} |
| 100 | else if VG_BOOL_CLO(arg, "--trace-mutex", trace_mutex) {} |
| 101 | else if VG_BOOL_CLO(arg, "--trace-rwlock", trace_rwlock) {} |
| 102 | else if VG_BOOL_CLO(arg, "--trace-segment", trace_segment) {} |
| 103 | else if VG_BOOL_CLO(arg, "--trace-semaphore", trace_semaphore) {} |
| 104 | else if VG_BOOL_CLO(arg, "--trace-suppr", trace_suppression) {} |
| 105 | else if VG_BOOL_CLO(arg, "--var-info", DRD_(s_var_info)) {} |
| 106 | else if VG_INT_CLO (arg, "--exclusive-threshold", exclusive_threshold_ms) {} |
| 107 | else if VG_INT_CLO (arg, "--shared-threshold", shared_threshold_ms) {} |
| 108 | else if VG_STR_CLO (arg, "--trace-addr", trace_address) {} |
| 109 | else |
| 110 | return VG_(replacement_malloc_process_cmd_line_option)(arg); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 111 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 112 | if (check_stack_accesses != -1) |
| 113 | DRD_(set_check_stack_accesses)(check_stack_accesses); |
| 114 | if (exclusive_threshold_ms != -1) |
| 115 | { |
| 116 | DRD_(mutex_set_lock_threshold)(exclusive_threshold_ms); |
| 117 | DRD_(rwlock_set_exclusive_threshold)(exclusive_threshold_ms); |
| 118 | } |
| 119 | if (report_signal_unlocked != -1) |
| 120 | { |
| 121 | DRD_(cond_set_report_signal_unlocked)(report_signal_unlocked); |
| 122 | } |
| 123 | if (shared_threshold_ms != -1) |
| 124 | { |
| 125 | DRD_(rwlock_set_shared_threshold)(shared_threshold_ms); |
| 126 | } |
| 127 | if (segment_merging != -1) |
| 128 | DRD_(thread_set_segment_merging)(segment_merging); |
| 129 | if (show_confl_seg != -1) |
| 130 | DRD_(set_show_conflicting_segments)(show_confl_seg); |
| 131 | if (trace_address) |
| 132 | { |
| 133 | const Addr addr = VG_(strtoll16)(trace_address, 0); |
| 134 | DRD_(start_tracing_address_range)(addr, addr + 1); |
| 135 | } |
| 136 | if (trace_barrier != -1) |
| 137 | DRD_(barrier_set_trace)(trace_barrier); |
| 138 | if (trace_clientobj != -1) |
| 139 | DRD_(clientobj_set_trace)(trace_clientobj); |
| 140 | if (trace_cond != -1) |
| 141 | DRD_(cond_set_trace)(trace_cond); |
| 142 | if (trace_csw != -1) |
| 143 | DRD_(thread_trace_context_switches)(trace_csw); |
| 144 | if (trace_fork_join != -1) |
| 145 | DRD_(thread_set_trace_fork_join)(trace_fork_join); |
| 146 | if (trace_conflict_set != -1) |
| 147 | DRD_(thread_trace_conflict_set)(trace_conflict_set); |
| 148 | if (trace_mutex != -1) |
| 149 | DRD_(mutex_set_trace)(trace_mutex); |
| 150 | if (trace_rwlock != -1) |
| 151 | DRD_(rwlock_set_trace)(trace_rwlock); |
| 152 | if (trace_segment != -1) |
| 153 | DRD_(sg_set_trace)(trace_segment); |
| 154 | if (trace_semaphore != -1) |
| 155 | DRD_(semaphore_set_trace)(trace_semaphore); |
| 156 | if (trace_suppression != -1) |
| 157 | DRD_(suppression_set_trace)(trace_suppression); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 158 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 159 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 160 | } |
| 161 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 162 | static void DRD_(print_usage)(void) |
bart | bd7e56e | 2008-03-31 18:14:12 +0000 | [diff] [blame] | 163 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 164 | VG_(printf)( |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 165 | " --check-stack-var=yes|no Whether or not to report data races on\n" |
| 166 | " stack variables [no].\n" |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 167 | " --exclusive-threshold=<n> Print an error message if any mutex or\n" |
| 168 | " writer lock is held longer than the specified time (in milliseconds).\n" |
bart | 46b5fce | 2008-06-28 13:01:30 +0000 | [diff] [blame] | 169 | " --report-signal-unlocked=yes|no Whether to report calls to\n" |
| 170 | " pthread_cond_signal() where the mutex associated\n" |
| 171 | " with the signal via pthread_cond_wait() is not\n" |
| 172 | " locked at the time the signal is sent [yes].\n" |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 173 | " --segment-merging=yes|no Controls segment merging [yes].\n" |
bart | bd7e56e | 2008-03-31 18:14:12 +0000 | [diff] [blame] | 174 | " Segment merging is an algorithm to limit memory usage of the\n" |
| 175 | " data race detection algorithm. Disabling segment merging may\n" |
| 176 | " improve the accuracy of the so-called 'other segments' displayed\n" |
| 177 | " in race reports but can also trigger an out of memory error.\n" |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 178 | " --shared-threshold=<n> Print an error message if a reader lock\n" |
| 179 | " is held longer than the specified time (in milliseconds).\n" |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 180 | " --show-confl-seg=yes|no Show conflicting segments in race reports [yes].\n" |
| 181 | " --show-stack-usage=yes|no Print stack usage at thread exit time [no].\n" |
| 182 | " --var-info=yes|no Display the names of global, static and\n" |
bart | bd7e56e | 2008-03-31 18:14:12 +0000 | [diff] [blame] | 183 | " stack variables when a race is reported on such a variable. This\n" |
| 184 | " information is by default not displayed since for big programs\n" |
bart | 85d2253 | 2008-06-26 07:30:32 +0000 | [diff] [blame] | 185 | " reading in all debug information at once may cause an out of\n" |
| 186 | " memory error [no].\n" |
bart | bd7e56e | 2008-03-31 18:14:12 +0000 | [diff] [blame] | 187 | "\n" |
bart | ef1b972 | 2008-07-04 15:34:23 +0000 | [diff] [blame] | 188 | " drd options for monitoring process behavior:\n" |
bart | 952e1a0 | 2008-04-06 13:06:36 +0000 | [diff] [blame] | 189 | " --trace-addr=<address> Trace all load and store activity for the.\n" |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 190 | " specified address [off].\n" |
| 191 | " --trace-barrier=yes|no Trace all barrier activity [no].\n" |
| 192 | " --trace-cond=yes|no Trace all condition variable activity [no].\n" |
| 193 | " --trace-fork-join=yes|no Trace all thread fork/join activity [no].\n" |
| 194 | " --trace-mutex=yes|no Trace all mutex activity [no].\n" |
| 195 | " --trace-rwlock=yes|no Trace all reader-writer lock activity[no].\n" |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 196 | " --trace-semaphore=yes|no Trace all semaphore activity [no].\n" |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 197 | ); |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 198 | VG_(replacement_malloc_print_usage)(); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 199 | } |
| 200 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 201 | static void DRD_(print_debug_usage)(void) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 202 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 203 | VG_(printf)( |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 204 | " --drd-stats=yes|no Print statistics about DRD activity [no].\n" |
| 205 | " --trace-clientobj=yes|no Trace all client object activity [no].\n" |
| 206 | " --trace-csw=yes|no Trace all scheduler context switches [no].\n" |
bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 207 | " --trace-conflict-set=yes|no Trace all conflict set updates [no].\n" |
bart | 987781d | 2008-06-27 15:00:07 +0000 | [diff] [blame] | 208 | " --trace-segment=yes|no Trace segment actions [no].\n" |
| 209 | " --trace-suppr=yes|no Trace all address suppression actions [no].\n" |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 210 | ); |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 211 | VG_(replacement_malloc_print_debug_usage)(); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | |
| 215 | // |
| 216 | // Implements the thread-related core callbacks. |
| 217 | // |
| 218 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 219 | static void drd_pre_mem_read(const CorePart part, |
| 220 | const ThreadId tid, |
| 221 | Char* const s, |
| 222 | const Addr a, |
| 223 | const SizeT size) |
| 224 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 225 | if (size > 0) |
| 226 | { |
| 227 | DRD_(trace_load)(a, size); |
| 228 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 229 | } |
| 230 | |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 231 | static void drd_pre_mem_read_asciiz(const CorePart part, |
| 232 | const ThreadId tid, |
| 233 | Char* const s, |
| 234 | const Addr a) |
| 235 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 236 | const char* p = (void*)a; |
| 237 | SizeT size = 0; |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 238 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 239 | /* Note: the expression '*p' reads client memory and may crash if the */ |
| 240 | /* client provided an invalid pointer ! */ |
| 241 | while (*p) |
| 242 | { |
| 243 | p++; |
| 244 | size++; |
| 245 | } |
| 246 | // To do: find out what a reasonable upper limit on 'size' is. |
| 247 | tl_assert(size < 4096); |
| 248 | if (size > 0) |
| 249 | { |
| 250 | DRD_(trace_load)(a, size); |
| 251 | } |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 252 | } |
| 253 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 254 | static void drd_post_mem_write(const CorePart part, |
| 255 | const ThreadId tid, |
| 256 | const Addr a, |
| 257 | const SizeT size) |
| 258 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 259 | DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)()); |
| 260 | if (size > 0) |
| 261 | { |
| 262 | DRD_(trace_store)(a, size); |
| 263 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 264 | } |
| 265 | |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 266 | static __inline__ |
| 267 | void drd_start_using_mem(const Addr a1, const SizeT len) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 268 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 269 | tl_assert(a1 < a1 + len); |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 270 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 271 | if (UNLIKELY(DRD_(any_address_is_traced)())) |
| 272 | { |
| 273 | DRD_(trace_mem_access)(a1, len, eStart); |
| 274 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 275 | } |
| 276 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 277 | static void drd_start_using_mem_w_ecu(const Addr a1, |
| 278 | const SizeT len, |
| 279 | UInt ec_uniq) |
| 280 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 281 | drd_start_using_mem(a1, len); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static void drd_start_using_mem_w_tid(const Addr a1, |
| 285 | const SizeT len, |
| 286 | ThreadId tid) |
| 287 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 288 | drd_start_using_mem(a1, len); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 289 | } |
| 290 | |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 291 | static __inline__ |
| 292 | void drd_stop_using_mem(const Addr a1, const SizeT len, |
| 293 | const Bool is_stack_mem) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 294 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 295 | const Addr a2 = a1 + len; |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 296 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 297 | tl_assert(a1 < a2); |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 298 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 299 | if (UNLIKELY(DRD_(any_address_is_traced)())) |
| 300 | { |
| 301 | DRD_(trace_mem_access)(a1, len, eEnd); |
| 302 | } |
| 303 | if (! is_stack_mem || DRD_(get_check_stack_accesses)()) |
| 304 | { |
| 305 | DRD_(thread_stop_using_mem)(a1, a2); |
| 306 | DRD_(clientobj_stop_using_mem)(a1, a2); |
| 307 | DRD_(suppression_stop_using_mem)(a1, a2); |
| 308 | } |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | static __inline__ |
| 312 | void drd_stop_using_nonstack_mem(const Addr a1, const SizeT len) |
| 313 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 314 | drd_stop_using_mem(a1, len, False); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 315 | } |
| 316 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 317 | /** |
bart | fdaa018 | 2009-03-10 09:25:32 +0000 | [diff] [blame] | 318 | * Discard all information DRD has about memory accesses and client objects |
| 319 | * in the specified address range. |
| 320 | */ |
| 321 | void DRD_(clean_memory)(const Addr a1, const SizeT len) |
| 322 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 323 | const Bool is_stack_memory = DRD_(thread_address_on_any_stack)(a1); |
| 324 | drd_stop_using_mem(a1, len, is_stack_memory); |
| 325 | drd_start_using_mem(a1, len); |
bart | fdaa018 | 2009-03-10 09:25:32 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /** |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 329 | * Suppress data race reports on all addresses contained in .plt and |
| 330 | * .got.plt sections inside the address range [ a, a + len [. The data in |
| 331 | * these sections is modified by _dl_relocate_object() every time a function |
| 332 | * in a shared library is called for the first time. Since the first call |
| 333 | * to a function in a shared library can happen from a multithreaded context, |
| 334 | * such calls can cause conflicting accesses. See also Ulrich Drepper's |
| 335 | * paper "How to Write Shared Libraries" for more information about relocation |
| 336 | * (http://people.redhat.com/drepper/dsohowto.pdf). |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 337 | */ |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 338 | static void DRD_(suppress_relocation_conflicts)(const Addr a, const SizeT len) |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 339 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 340 | const DebugInfo* di; |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 341 | |
| 342 | #if 0 |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 343 | VG_(printf)("Evaluating range @ 0x%lx size %ld\n", a, len); |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 344 | #endif |
| 345 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 346 | for (di = VG_(next_seginfo)(0); di; di = VG_(next_seginfo)(di)) |
| 347 | { |
| 348 | Addr avma; |
| 349 | SizeT size; |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 350 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 351 | avma = VG_(seginfo_get_plt_avma)(di); |
| 352 | size = VG_(seginfo_get_plt_size)(di); |
| 353 | tl_assert((avma && size) || (avma == 0 && size == 0)); |
| 354 | if (size > 0) |
| 355 | { |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 356 | #if 0 |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 357 | VG_(printf)("Suppressing .plt @ 0x%lx size %ld\n", avma, size); |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 358 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 359 | tl_assert(VG_(seginfo_sect_kind)(NULL, 0, avma) == Vg_SectPLT); |
| 360 | DRD_(start_suppression)(avma, avma + size, ".plt"); |
| 361 | } |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 362 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 363 | avma = VG_(seginfo_get_gotplt_avma)(di); |
| 364 | size = VG_(seginfo_get_gotplt_size)(di); |
| 365 | tl_assert((avma && size) || (avma == 0 && size == 0)); |
| 366 | if (size > 0) |
| 367 | { |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 368 | #if 0 |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 369 | VG_(printf)("Suppressing .got.plt @ 0x%lx size %ld\n", avma, size); |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 370 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 371 | tl_assert(VG_(seginfo_sect_kind)(NULL, 0, avma) == Vg_SectGOTPLT); |
| 372 | DRD_(start_suppression)(avma, avma + size, ".gotplt"); |
| 373 | } |
| 374 | } |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 375 | } |
| 376 | |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 377 | static |
| 378 | void drd_start_using_mem_w_perms(const Addr a, const SizeT len, |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 379 | const Bool rr, const Bool ww, const Bool xx, |
| 380 | ULong di_handle) |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 381 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 382 | DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)()); |
bart | d576591 | 2008-03-16 08:40:55 +0000 | [diff] [blame] | 383 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 384 | drd_start_using_mem(a, len); |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 385 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 386 | DRD_(suppress_relocation_conflicts)(a, len); |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 387 | } |
| 388 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 389 | /* Called by the core when the stack of a thread grows, to indicate that */ |
| 390 | /* the addresses in range [ a, a + len [ may now be used by the client. */ |
| 391 | /* Assumption: stacks grow downward. */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 392 | static __inline__ |
| 393 | void drd_start_using_mem_stack(const Addr a, const SizeT len) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 394 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 395 | DRD_(thread_set_stack_min)(DRD_(thread_get_running_tid)(), |
| 396 | a - VG_STACK_REDZONE_SZB); |
| 397 | drd_start_using_mem(a - VG_STACK_REDZONE_SZB, |
| 398 | len + VG_STACK_REDZONE_SZB); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /* Called by the core when the stack of a thread shrinks, to indicate that */ |
| 402 | /* the addresses [ a, a + len [ are no longer accessible for the client. */ |
| 403 | /* Assumption: stacks grow downward. */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 404 | static __inline__ |
| 405 | void drd_stop_using_mem_stack(const Addr a, const SizeT len) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 406 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 407 | DRD_(thread_set_stack_min)(DRD_(thread_get_running_tid)(), |
| 408 | a + len - VG_STACK_REDZONE_SZB); |
| 409 | drd_stop_using_mem(a - VG_STACK_REDZONE_SZB, len + VG_STACK_REDZONE_SZB, |
| 410 | True); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 411 | } |
| 412 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 413 | /** |
| 414 | * Callback function called by the Valgrind core before a stack area is |
| 415 | * being used by a signal handler. |
| 416 | * |
| 417 | * @param[in] a Start of address range. |
| 418 | * @param[in] len Address range length. |
| 419 | * @param[in] tid Valgrind thread ID for whom the signal frame is being |
| 420 | * constructed. |
| 421 | */ |
| 422 | static void drd_start_using_mem_stack_signal(const Addr a, const SizeT len, |
| 423 | ThreadId tid) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 424 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 425 | DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)()); |
| 426 | drd_start_using_mem(a, len); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 427 | } |
| 428 | |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 429 | static void drd_stop_using_mem_stack_signal(Addr a, SizeT len) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 430 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 431 | drd_stop_using_mem(a, len, True); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | static |
| 435 | void drd_pre_thread_create(const ThreadId creator, const ThreadId created) |
| 436 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 437 | const DrdThreadId drd_creator = DRD_(VgThreadIdToDrdThreadId)(creator); |
| 438 | tl_assert(created != VG_INVALID_THREADID); |
| 439 | DRD_(thread_pre_create)(drd_creator, created); |
| 440 | if (DRD_(IsValidDrdThreadId)(drd_creator)) |
| 441 | { |
| 442 | DRD_(thread_new_segment)(drd_creator); |
| 443 | } |
| 444 | if (DRD_(thread_get_trace_fork_join)()) |
| 445 | { |
| 446 | VG_(message)(Vg_DebugMsg, |
| 447 | "drd_pre_thread_create creator = %d/%d, created = %d", |
| 448 | creator, drd_creator, created); |
| 449 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | /* Called by Valgrind's core before any loads or stores are performed on */ |
| 453 | /* the context of thread "created". At startup, this function is called */ |
| 454 | /* with arguments (0,1). */ |
| 455 | static |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 456 | void drd_post_thread_create(const ThreadId vg_created) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 457 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 458 | DrdThreadId drd_created; |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 459 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 460 | tl_assert(vg_created != VG_INVALID_THREADID); |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 461 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 462 | drd_created = DRD_(thread_post_create)(vg_created); |
| 463 | if (DRD_(thread_get_trace_fork_join)()) |
| 464 | { |
| 465 | VG_(message)(Vg_DebugMsg, |
| 466 | "drd_post_thread_create created = %d/%d", |
| 467 | vg_created, drd_created); |
| 468 | } |
| 469 | if (! DRD_(get_check_stack_accesses)()) |
| 470 | { |
| 471 | DRD_(start_suppression)(DRD_(thread_get_stack_max)(drd_created) |
| 472 | - DRD_(thread_get_stack_size)(drd_created), |
| 473 | DRD_(thread_get_stack_max)(drd_created), |
| 474 | "stack"); |
| 475 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 476 | } |
| 477 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 478 | /* Called after a thread has performed its last memory access. */ |
bart | d43f8d3 | 2008-03-16 17:29:20 +0000 | [diff] [blame] | 479 | static void drd_thread_finished(ThreadId vg_tid) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 480 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 481 | DrdThreadId drd_tid; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 482 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 483 | tl_assert(VG_(get_running_tid)() == vg_tid); |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 484 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 485 | drd_tid = DRD_(VgThreadIdToDrdThreadId)(vg_tid); |
| 486 | if (DRD_(thread_get_trace_fork_join)()) |
| 487 | { |
| 488 | VG_(message)(Vg_DebugMsg, |
| 489 | "drd_thread_finished tid = %d/%d%s", |
| 490 | vg_tid, |
| 491 | drd_tid, |
| 492 | DRD_(thread_get_joinable)(drd_tid) |
| 493 | ? "" |
| 494 | : " (which is a detached thread)"); |
| 495 | } |
| 496 | if (DRD_(s_show_stack_usage)) |
| 497 | { |
| 498 | const SizeT stack_size = DRD_(thread_get_stack_size)(drd_tid); |
| 499 | const SizeT used_stack |
| 500 | = (DRD_(thread_get_stack_max)(drd_tid) |
| 501 | - DRD_(thread_get_stack_min_min)(drd_tid)); |
| 502 | VG_(message)(Vg_UserMsg, |
| 503 | "thread %d/%d%s finished and used %ld bytes out of %ld" |
| 504 | " on its stack. Margin: %ld bytes.", |
| 505 | vg_tid, |
| 506 | drd_tid, |
| 507 | DRD_(thread_get_joinable)(drd_tid) |
| 508 | ? "" |
| 509 | : " (which is a detached thread)", |
| 510 | used_stack, |
| 511 | stack_size, |
| 512 | stack_size - used_stack); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 513 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 514 | } |
| 515 | drd_stop_using_mem(DRD_(thread_get_stack_min)(drd_tid), |
| 516 | DRD_(thread_get_stack_max)(drd_tid) |
| 517 | - DRD_(thread_get_stack_min)(drd_tid), |
| 518 | True); |
| 519 | DRD_(thread_stop_recording)(drd_tid); |
| 520 | DRD_(thread_finished)(drd_tid); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 521 | } |
| 522 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 523 | // |
| 524 | // Implementation of the tool interface. |
| 525 | // |
| 526 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 527 | static void DRD_(post_clo_init)(void) |
sewardj | dcbb8d3 | 2007-11-26 21:34:30 +0000 | [diff] [blame] | 528 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 529 | # if defined(VGP_x86_linux) || defined(VGP_amd64_linux) \ |
| 530 | || defined(VGP_ppc32_linux) || defined(VGP_ppc64_linux) |
| 531 | /* fine */ |
sewardj | dcbb8d3 | 2007-11-26 21:34:30 +0000 | [diff] [blame] | 532 | # else |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 533 | VG_(printf)("\nWARNING: DRD has only been tested on Linux.\n\n"); |
sewardj | dcbb8d3 | 2007-11-26 21:34:30 +0000 | [diff] [blame] | 534 | # endif |
bart | 95761b5 | 2008-03-29 08:34:03 +0000 | [diff] [blame] | 535 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 536 | if (DRD_(s_var_info)) |
| 537 | { |
| 538 | VG_(needs_var_info)(); |
| 539 | } |
sewardj | dcbb8d3 | 2007-11-26 21:34:30 +0000 | [diff] [blame] | 540 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 541 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 542 | static void drd_start_client_code(const ThreadId tid, const ULong bbs_done) |
| 543 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 544 | tl_assert(tid == VG_(get_running_tid)()); |
| 545 | DRD_(thread_set_vg_running_tid)(tid); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 546 | } |
| 547 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 548 | static void DRD_(fini)(Int exitcode) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 549 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 550 | // thread_print_all(); |
| 551 | if (VG_(clo_verbosity) > 1 || DRD_(s_print_stats)) |
| 552 | { |
| 553 | ULong update_conflict_set_count; |
| 554 | ULong dsnsc; |
| 555 | ULong dscvc; |
bart | e4504dd | 2008-04-06 15:02:58 +0000 | [diff] [blame] | 556 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 557 | update_conflict_set_count |
| 558 | = DRD_(thread_get_update_conflict_set_count)(&dsnsc, &dscvc); |
bart | e4504dd | 2008-04-06 15:02:58 +0000 | [diff] [blame] | 559 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 560 | VG_(message)(Vg_UserMsg, |
| 561 | " thread: %lld context switches" |
| 562 | " / %lld updates of the conflict set", |
| 563 | DRD_(thread_get_context_switch_count)(), |
| 564 | update_conflict_set_count); |
| 565 | VG_(message)(Vg_UserMsg, |
| 566 | " (%lld new sg + %lld combine vc + %lld csw).", |
| 567 | dsnsc, |
| 568 | dscvc, |
| 569 | update_conflict_set_count - dsnsc - dscvc); |
| 570 | VG_(message)(Vg_UserMsg, |
| 571 | " segments: created %lld segments, max %lld alive," |
| 572 | " %lld discard points.", |
| 573 | DRD_(sg_get_segments_created_count)(), |
| 574 | DRD_(sg_get_max_segments_alive_count)(), |
| 575 | DRD_(thread_get_discard_ordered_segments_count)()); |
| 576 | VG_(message)(Vg_UserMsg, |
| 577 | " (%lld m, %lld rw, %lld s, %lld b)", |
| 578 | DRD_(get_mutex_segment_creation_count)(), |
| 579 | DRD_(get_rwlock_segment_creation_count)(), |
| 580 | DRD_(get_semaphore_segment_creation_count)(), |
| 581 | DRD_(get_barrier_segment_creation_count)()); |
| 582 | VG_(message)(Vg_UserMsg, |
| 583 | " bitmaps: %lld level 1 / %lld level 2 bitmap refs", |
| 584 | DRD_(bm_get_bitmap_creation_count)(), |
| 585 | DRD_(bm_get_bitmap2_node_creation_count)()); |
| 586 | VG_(message)(Vg_UserMsg, |
| 587 | " and %lld level 2 bitmaps were allocated.", |
| 588 | DRD_(bm_get_bitmap2_creation_count)()); |
| 589 | VG_(message)(Vg_UserMsg, |
| 590 | " mutex: %lld non-recursive lock/unlock events.", |
| 591 | DRD_(get_mutex_lock_count)()); |
| 592 | DRD_(print_malloc_stats)(); |
| 593 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 594 | } |
| 595 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 596 | static |
| 597 | void drd_pre_clo_init(void) |
| 598 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 599 | // Basic tool stuff. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 600 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 601 | VG_(details_name) ("drd"); |
| 602 | VG_(details_version) (NULL); |
| 603 | VG_(details_description) ("a thread error detector"); |
| 604 | VG_(details_copyright_author)("Copyright (C) 2006-2009, and GNU GPL'd," |
| 605 | " by Bart Van Assche."); |
| 606 | VG_(details_bug_reports_to) (VG_BUGS_TO); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 607 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 608 | VG_(basic_tool_funcs) (DRD_(post_clo_init), |
| 609 | DRD_(instrument), |
| 610 | DRD_(fini)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 611 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 612 | // Command line stuff. |
| 613 | VG_(needs_command_line_options)(DRD_(process_cmd_line_option), |
| 614 | DRD_(print_usage), |
| 615 | DRD_(print_debug_usage)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 616 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 617 | // Error handling. |
| 618 | DRD_(register_error_handlers)(); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 619 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 620 | // Core event tracking. |
| 621 | VG_(track_pre_mem_read) (drd_pre_mem_read); |
| 622 | VG_(track_pre_mem_read_asciiz) (drd_pre_mem_read_asciiz); |
| 623 | VG_(track_post_mem_write) (drd_post_mem_write); |
| 624 | VG_(track_new_mem_brk) (drd_start_using_mem_w_tid); |
| 625 | VG_(track_new_mem_mmap) (drd_start_using_mem_w_perms); |
| 626 | VG_(track_new_mem_stack) (drd_start_using_mem_stack); |
| 627 | VG_(track_new_mem_stack_signal) (drd_start_using_mem_stack_signal); |
| 628 | VG_(track_new_mem_startup) (drd_start_using_mem_w_perms); |
| 629 | VG_(track_die_mem_brk) (drd_stop_using_nonstack_mem); |
| 630 | VG_(track_die_mem_munmap) (drd_stop_using_nonstack_mem); |
| 631 | VG_(track_die_mem_stack) (drd_stop_using_mem_stack); |
| 632 | VG_(track_die_mem_stack_signal) (drd_stop_using_mem_stack_signal); |
| 633 | VG_(track_start_client_code) (drd_start_client_code); |
| 634 | VG_(track_pre_thread_ll_create) (drd_pre_thread_create); |
| 635 | VG_(track_pre_thread_first_insn)(drd_post_thread_create); |
| 636 | VG_(track_pre_thread_ll_exit) (drd_thread_finished); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 637 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 638 | // Other stuff. |
| 639 | DRD_(register_malloc_wrappers)(drd_start_using_mem_w_ecu, |
| 640 | drd_stop_using_nonstack_mem); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 641 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 642 | DRD_(clientreq_init)(); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 643 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 644 | DRD_(suppression_init)(); |
bart | 4bb53d8 | 2008-02-28 19:06:34 +0000 | [diff] [blame] | 645 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 646 | DRD_(clientobj_init)(); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
| 650 | VG_DETERMINE_INTERFACE_VERSION(drd_pre_clo_init) |