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