sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 2 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 3 | |
bart | d4bab99 | 2013-10-04 05:55:30 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2013 Bart Van Assche <bvanassche@acm.org>. |
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 | c182467 | 2011-03-12 14:07:09 +0000 | [diff] [blame] | 30 | #include "drd_hb.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" |
sewardj | 234e558 | 2011-02-09 12:47:23 +0000 | [diff] [blame] | 54 | #include "pub_tool_aspacemgr.h" // VG_(am_is_valid_for_client) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 55 | |
| 56 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 57 | /* Local variables. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 58 | |
bart | 7d5f523 | 2011-03-13 09:08:10 +0000 | [diff] [blame] | 59 | static Bool s_print_stats; |
| 60 | static Bool s_var_info; |
| 61 | static Bool s_show_stack_usage; |
| 62 | static Bool s_trace_alloc; |
bart | c0cd28f | 2013-08-24 17:51:18 +0000 | [diff] [blame] | 63 | static Bool trace_sectsuppr; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 64 | |
| 65 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 66 | /** |
| 67 | * Implement the needs_command_line_options for drd. |
| 68 | */ |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 69 | static Bool DRD_(process_cmd_line_option)(const HChar* arg) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 70 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 71 | int check_stack_accesses = -1; |
bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 72 | int join_list_vol = -1; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 73 | int exclusive_threshold_ms = -1; |
bart | f98a569 | 2009-05-03 17:17:37 +0000 | [diff] [blame] | 74 | int first_race_only = -1; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 75 | int report_signal_unlocked = -1; |
| 76 | int segment_merging = -1; |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 77 | int segment_merge_interval = -1; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 78 | int shared_threshold_ms = -1; |
| 79 | int show_confl_seg = -1; |
| 80 | int trace_barrier = -1; |
| 81 | int trace_clientobj = -1; |
| 82 | int trace_cond = -1; |
| 83 | int trace_csw = -1; |
| 84 | int trace_fork_join = -1; |
bart | c182467 | 2011-03-12 14:07:09 +0000 | [diff] [blame] | 85 | int trace_hb = -1; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 86 | int trace_conflict_set = -1; |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 87 | int trace_conflict_set_bm = -1; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 88 | int trace_mutex = -1; |
| 89 | int trace_rwlock = -1; |
| 90 | int trace_segment = -1; |
| 91 | int trace_semaphore = -1; |
| 92 | int trace_suppression = -1; |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 93 | const HChar* trace_address = 0; |
| 94 | const HChar* ptrace_address= 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 95 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 96 | if VG_BOOL_CLO(arg, "--check-stack-var", check_stack_accesses) {} |
bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 97 | else if VG_INT_CLO (arg, "--join-list-vol", join_list_vol) {} |
bart | 75c1cba | 2010-08-29 07:20:30 +0000 | [diff] [blame] | 98 | else if VG_BOOL_CLO(arg, "--drd-stats", s_print_stats) {} |
bart | f98a569 | 2009-05-03 17:17:37 +0000 | [diff] [blame] | 99 | else if VG_BOOL_CLO(arg, "--first-race-only", first_race_only) {} |
bart | 7d5f523 | 2011-03-13 09:08:10 +0000 | [diff] [blame] | 100 | else if VG_BOOL_CLO(arg, "--free-is-write", DRD_(g_free_is_write)) {} |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 101 | else if VG_BOOL_CLO(arg,"--report-signal-unlocked",report_signal_unlocked) |
| 102 | {} |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 103 | else if VG_BOOL_CLO(arg, "--segment-merging", segment_merging) {} |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 104 | else if VG_INT_CLO (arg, "--segment-merging-interval", segment_merge_interval) |
| 105 | {} |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 106 | else if VG_BOOL_CLO(arg, "--show-confl-seg", show_confl_seg) {} |
bart | 75c1cba | 2010-08-29 07:20:30 +0000 | [diff] [blame] | 107 | else if VG_BOOL_CLO(arg, "--show-stack-usage", s_show_stack_usage) {} |
bart | f9427fd | 2010-08-29 09:19:07 +0000 | [diff] [blame] | 108 | else if VG_BOOL_CLO(arg, "--trace-alloc", s_trace_alloc) {} |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 109 | else if VG_BOOL_CLO(arg, "--trace-barrier", trace_barrier) {} |
| 110 | else if VG_BOOL_CLO(arg, "--trace-clientobj", trace_clientobj) {} |
| 111 | else if VG_BOOL_CLO(arg, "--trace-cond", trace_cond) {} |
| 112 | else if VG_BOOL_CLO(arg, "--trace-conflict-set", trace_conflict_set) {} |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 113 | else if VG_BOOL_CLO(arg, "--trace-conflict-set-bm", trace_conflict_set_bm){} |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 114 | else if VG_BOOL_CLO(arg, "--trace-csw", trace_csw) {} |
| 115 | else if VG_BOOL_CLO(arg, "--trace-fork-join", trace_fork_join) {} |
bart | c182467 | 2011-03-12 14:07:09 +0000 | [diff] [blame] | 116 | else if VG_BOOL_CLO(arg, "--trace-hb", trace_hb) {} |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 117 | else if VG_BOOL_CLO(arg, "--trace-mutex", trace_mutex) {} |
| 118 | else if VG_BOOL_CLO(arg, "--trace-rwlock", trace_rwlock) {} |
bart | c0cd28f | 2013-08-24 17:51:18 +0000 | [diff] [blame] | 119 | else if VG_BOOL_CLO(arg, "--trace-sectsuppr", trace_sectsuppr) {} |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 120 | else if VG_BOOL_CLO(arg, "--trace-segment", trace_segment) {} |
| 121 | else if VG_BOOL_CLO(arg, "--trace-semaphore", trace_semaphore) {} |
| 122 | else if VG_BOOL_CLO(arg, "--trace-suppr", trace_suppression) {} |
bart | 75c1cba | 2010-08-29 07:20:30 +0000 | [diff] [blame] | 123 | else if VG_BOOL_CLO(arg, "--var-info", s_var_info) {} |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 124 | else if VG_INT_CLO (arg, "--exclusive-threshold", exclusive_threshold_ms) {} |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 125 | else if VG_STR_CLO (arg, "--ptrace-addr", ptrace_address) {} |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 126 | else if VG_INT_CLO (arg, "--shared-threshold", shared_threshold_ms) {} |
| 127 | else if VG_STR_CLO (arg, "--trace-addr", trace_address) {} |
| 128 | else |
| 129 | return VG_(replacement_malloc_process_cmd_line_option)(arg); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 130 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 131 | if (check_stack_accesses != -1) |
| 132 | DRD_(set_check_stack_accesses)(check_stack_accesses); |
| 133 | if (exclusive_threshold_ms != -1) |
| 134 | { |
| 135 | DRD_(mutex_set_lock_threshold)(exclusive_threshold_ms); |
| 136 | DRD_(rwlock_set_exclusive_threshold)(exclusive_threshold_ms); |
| 137 | } |
bart | f98a569 | 2009-05-03 17:17:37 +0000 | [diff] [blame] | 138 | if (first_race_only != -1) |
| 139 | { |
| 140 | DRD_(set_first_race_only)(first_race_only); |
| 141 | } |
bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 142 | if (join_list_vol != -1) |
| 143 | DRD_(thread_set_join_list_vol)(join_list_vol); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 144 | if (report_signal_unlocked != -1) |
| 145 | { |
| 146 | DRD_(cond_set_report_signal_unlocked)(report_signal_unlocked); |
| 147 | } |
| 148 | if (shared_threshold_ms != -1) |
| 149 | { |
| 150 | DRD_(rwlock_set_shared_threshold)(shared_threshold_ms); |
| 151 | } |
| 152 | if (segment_merging != -1) |
| 153 | DRD_(thread_set_segment_merging)(segment_merging); |
bart | 109d5da | 2009-06-22 18:06:29 +0000 | [diff] [blame] | 154 | if (segment_merge_interval != -1) |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 155 | DRD_(thread_set_segment_merge_interval)(segment_merge_interval); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 156 | if (show_confl_seg != -1) |
| 157 | DRD_(set_show_conflicting_segments)(show_confl_seg); |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 158 | if (trace_address) { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 159 | const Addr addr = VG_(strtoll16)(trace_address, 0); |
bart | 41a378a | 2012-01-24 18:39:29 +0000 | [diff] [blame] | 160 | DRD_(start_tracing_address_range)(addr, addr + 1, False); |
| 161 | } |
| 162 | if (ptrace_address) { |
bart | 8670edc | 2013-10-25 14:26:14 +0000 | [diff] [blame] | 163 | char *plus = VG_(strchr)(ptrace_address, '+'); |
| 164 | Addr addr, length; |
| 165 | if (plus) |
| 166 | *plus = '\0'; |
| 167 | addr = VG_(strtoll16)(ptrace_address, 0); |
| 168 | length = plus ? VG_(strtoll16)(plus + 1, 0) : 1; |
| 169 | DRD_(start_tracing_address_range)(addr, addr + length, True); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 170 | } |
| 171 | if (trace_barrier != -1) |
| 172 | DRD_(barrier_set_trace)(trace_barrier); |
| 173 | if (trace_clientobj != -1) |
| 174 | DRD_(clientobj_set_trace)(trace_clientobj); |
| 175 | if (trace_cond != -1) |
| 176 | DRD_(cond_set_trace)(trace_cond); |
| 177 | if (trace_csw != -1) |
| 178 | DRD_(thread_trace_context_switches)(trace_csw); |
| 179 | if (trace_fork_join != -1) |
| 180 | DRD_(thread_set_trace_fork_join)(trace_fork_join); |
bart | c182467 | 2011-03-12 14:07:09 +0000 | [diff] [blame] | 181 | if (trace_hb != -1) |
| 182 | DRD_(hb_set_trace)(trace_hb); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 183 | if (trace_conflict_set != -1) |
| 184 | DRD_(thread_trace_conflict_set)(trace_conflict_set); |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 185 | if (trace_conflict_set_bm != -1) |
| 186 | DRD_(thread_trace_conflict_set_bm)(trace_conflict_set_bm); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 187 | if (trace_mutex != -1) |
| 188 | DRD_(mutex_set_trace)(trace_mutex); |
| 189 | if (trace_rwlock != -1) |
| 190 | DRD_(rwlock_set_trace)(trace_rwlock); |
| 191 | if (trace_segment != -1) |
| 192 | DRD_(sg_set_trace)(trace_segment); |
| 193 | if (trace_semaphore != -1) |
| 194 | DRD_(semaphore_set_trace)(trace_semaphore); |
| 195 | if (trace_suppression != -1) |
| 196 | DRD_(suppression_set_trace)(trace_suppression); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 197 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 198 | return True; |
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_usage)(void) |
bart | bd7e56e | 2008-03-31 18:14:12 +0000 | [diff] [blame] | 202 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 203 | VG_(printf)( |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 204 | " --check-stack-var=yes|no Whether or not to report data races on\n" |
| 205 | " stack variables [no].\n" |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 206 | " --exclusive-threshold=<n> Print an error message if any mutex or\n" |
bart | 8600c42 | 2010-10-25 18:18:54 +0000 | [diff] [blame] | 207 | " writer lock is held longer than the specified\n" |
| 208 | " time (in milliseconds) [off].\n" |
bart | 1a3b0b3 | 2009-05-03 17:07:34 +0000 | [diff] [blame] | 209 | " --first-race-only=yes|no Only report the first data race that occurs on\n" |
| 210 | " a memory location instead of all races [no].\n" |
bart | 639d0ad | 2011-03-12 14:26:01 +0000 | [diff] [blame] | 211 | " --free-is-write=yes|no Whether to report races between freeing memory\n" |
| 212 | " and subsequent accesses of that memory[no].\n" |
bart | 505b35c | 2011-10-13 18:51:47 +0000 | [diff] [blame] | 213 | " --join-list-vol=<n> Number of threads to delay cleanup for [10].\n" |
bart | 46b5fce | 2008-06-28 13:01:30 +0000 | [diff] [blame] | 214 | " --report-signal-unlocked=yes|no Whether to report calls to\n" |
| 215 | " pthread_cond_signal() where the mutex associated\n" |
| 216 | " with the signal via pthread_cond_wait() is not\n" |
| 217 | " locked at the time the signal is sent [yes].\n" |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 218 | " --segment-merging=yes|no Controls segment merging [yes].\n" |
bart | bd7e56e | 2008-03-31 18:14:12 +0000 | [diff] [blame] | 219 | " Segment merging is an algorithm to limit memory usage of the\n" |
| 220 | " data race detection algorithm. Disabling segment merging may\n" |
| 221 | " improve the accuracy of the so-called 'other segments' displayed\n" |
| 222 | " in race reports but can also trigger an out of memory error.\n" |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 223 | " --segment-merging-interval=<n> Perform segment merging every time n new\n" |
| 224 | " segments have been created. Default: %d.\n" |
bart | 9d5b796 | 2008-05-14 12:25:00 +0000 | [diff] [blame] | 225 | " --shared-threshold=<n> Print an error message if a reader lock\n" |
bart | 8600c42 | 2010-10-25 18:18:54 +0000 | [diff] [blame] | 226 | " is held longer than the specified time (in\n" |
| 227 | " milliseconds) [off]\n" |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 228 | " --show-confl-seg=yes|no Show conflicting segments in race reports [yes].\n" |
| 229 | " --show-stack-usage=yes|no Print stack usage at thread exit time [no].\n" |
bart | bd7e56e | 2008-03-31 18:14:12 +0000 | [diff] [blame] | 230 | "\n" |
bart | ef1b972 | 2008-07-04 15:34:23 +0000 | [diff] [blame] | 231 | " drd options for monitoring process behavior:\n" |
bart | 8670edc | 2013-10-25 14:26:14 +0000 | [diff] [blame] | 232 | " --ptrace-addr=<address>[+<length>] Trace all load and store activity for\n" |
| 233 | " the specified address range and keep doing that\n" |
| 234 | " even after the memory at that address has been\n" |
| 235 | " freed and reallocated [off].\n" |
bart | 8c3de75 | 2011-12-12 15:49:00 +0000 | [diff] [blame] | 236 | " --trace-addr=<address> Trace all load and store activity for the\n" |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 237 | " specified address [off].\n" |
bart | 8670edc | 2013-10-25 14:26:14 +0000 | [diff] [blame] | 238 | " --trace-alloc=yes|no Trace all memory allocations and deallocations\n" |
| 239 | " [no].\n" |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 240 | " --trace-barrier=yes|no Trace all barrier activity [no].\n" |
| 241 | " --trace-cond=yes|no Trace all condition variable activity [no].\n" |
| 242 | " --trace-fork-join=yes|no Trace all thread fork/join activity [no].\n" |
bart | 505b35c | 2011-10-13 18:51:47 +0000 | [diff] [blame] | 243 | " --trace-hb=yes|no Trace ANNOTATE_HAPPENS_BEFORE() etc. [no].\n" |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 244 | " --trace-mutex=yes|no Trace all mutex activity [no].\n" |
| 245 | " --trace-rwlock=yes|no Trace all reader-writer lock activity[no].\n" |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 246 | " --trace-semaphore=yes|no Trace all semaphore activity [no].\n", |
| 247 | DRD_(thread_get_segment_merge_interval)() |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 248 | ); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 249 | } |
| 250 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 251 | static void DRD_(print_debug_usage)(void) |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 252 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 253 | VG_(printf)( |
bart | 130463a | 2008-04-01 17:03:33 +0000 | [diff] [blame] | 254 | " --drd-stats=yes|no Print statistics about DRD activity [no].\n" |
| 255 | " --trace-clientobj=yes|no Trace all client object activity [no].\n" |
| 256 | " --trace-csw=yes|no Trace all scheduler context switches [no].\n" |
bart | e73b0aa | 2008-06-28 07:19:56 +0000 | [diff] [blame] | 257 | " --trace-conflict-set=yes|no Trace all conflict set updates [no].\n" |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 258 | " --trace-conflict-set-bm=yes|no Trace all conflict set bitmap\n" |
| 259 | " updates [no]. Note: enabling this option\n" |
| 260 | " will generate a lot of output !\n" |
bart | c0cd28f | 2013-08-24 17:51:18 +0000 | [diff] [blame] | 261 | " --trace-sectsuppr=yes|no Trace which the dynamic library sections on\n" |
| 262 | " which data race detection is suppressed.\n" |
bart | 987781d | 2008-06-27 15:00:07 +0000 | [diff] [blame] | 263 | " --trace-segment=yes|no Trace segment actions [no].\n" |
| 264 | " --trace-suppr=yes|no Trace all address suppression actions [no].\n" |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 265 | ); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | |
| 269 | // |
| 270 | // Implements the thread-related core callbacks. |
| 271 | // |
| 272 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 273 | static void drd_pre_mem_read(const CorePart part, |
| 274 | const ThreadId tid, |
florian | e543f30 | 2012-10-21 19:43:43 +0000 | [diff] [blame] | 275 | const HChar* const s, |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 276 | const Addr a, |
| 277 | const SizeT size) |
| 278 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 279 | if (size > 0) |
| 280 | { |
| 281 | DRD_(trace_load)(a, size); |
| 282 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 283 | } |
| 284 | |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 285 | static void drd_pre_mem_read_asciiz(const CorePart part, |
| 286 | const ThreadId tid, |
florian | e543f30 | 2012-10-21 19:43:43 +0000 | [diff] [blame] | 287 | const HChar* const s, |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 288 | const Addr a) |
| 289 | { |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 290 | const HChar* p = (void*)a; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 291 | SizeT size = 0; |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 292 | |
sewardj | 234e558 | 2011-02-09 12:47:23 +0000 | [diff] [blame] | 293 | // Don't segfault if the string starts in an obviously stupid |
| 294 | // place. Actually we should check the whole string, not just |
| 295 | // the start address, but that's too much trouble. At least |
| 296 | // checking the first byte is better than nothing. See #255009. |
| 297 | if (!VG_(am_is_valid_for_client) (a, 1, VKI_PROT_READ)) |
| 298 | return; |
| 299 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 300 | /* Note: the expression '*p' reads client memory and may crash if the */ |
| 301 | /* client provided an invalid pointer ! */ |
| 302 | while (*p) |
| 303 | { |
| 304 | p++; |
| 305 | size++; |
| 306 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 307 | if (size > 0) |
| 308 | { |
| 309 | DRD_(trace_load)(a, size); |
| 310 | } |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 311 | } |
| 312 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 313 | static void drd_post_mem_write(const CorePart part, |
| 314 | const ThreadId tid, |
| 315 | const Addr a, |
| 316 | const SizeT size) |
| 317 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 318 | DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)()); |
| 319 | if (size > 0) |
| 320 | { |
| 321 | DRD_(trace_store)(a, size); |
| 322 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 323 | } |
| 324 | |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 325 | static __inline__ |
bart | f9427fd | 2010-08-29 09:19:07 +0000 | [diff] [blame] | 326 | void drd_start_using_mem(const Addr a1, const SizeT len, |
| 327 | const Bool is_stack_mem) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 328 | { |
bart | 639d0ad | 2011-03-12 14:26:01 +0000 | [diff] [blame] | 329 | const Addr a2 = a1 + len; |
| 330 | |
| 331 | tl_assert(a1 <= a2); |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 332 | |
bart | f9427fd | 2010-08-29 09:19:07 +0000 | [diff] [blame] | 333 | if (!is_stack_mem && s_trace_alloc) |
bart | ad994e8 | 2011-10-13 18:04:30 +0000 | [diff] [blame] | 334 | DRD_(trace_msg)("Started using memory range 0x%lx + %ld%s", |
bart | b92ff0f | 2011-10-08 08:29:29 +0000 | [diff] [blame] | 335 | a1, len, DRD_(running_thread_inside_pthread_create)() |
| 336 | ? " (inside pthread_create())" : ""); |
bart | f9427fd | 2010-08-29 09:19:07 +0000 | [diff] [blame] | 337 | |
bart | 7d5f523 | 2011-03-13 09:08:10 +0000 | [diff] [blame] | 338 | if (!is_stack_mem && DRD_(g_free_is_write)) |
bart | 639d0ad | 2011-03-12 14:26:01 +0000 | [diff] [blame] | 339 | DRD_(thread_stop_using_mem)(a1, a2); |
| 340 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 341 | if (UNLIKELY(DRD_(any_address_is_traced)())) |
| 342 | { |
bart | 42f3263 | 2011-12-13 11:12:05 +0000 | [diff] [blame] | 343 | DRD_(trace_mem_access)(a1, len, eStart, 0, 0); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 344 | } |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 345 | |
bart | 27656f8 | 2011-12-17 15:18:20 +0000 | [diff] [blame] | 346 | if (UNLIKELY(DRD_(running_thread_inside_pthread_create)())) |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 347 | { |
bart | 639d0ad | 2011-03-12 14:26:01 +0000 | [diff] [blame] | 348 | DRD_(start_suppression)(a1, a2, "pthread_create()"); |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 349 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 350 | } |
| 351 | |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 352 | static void drd_start_using_mem_w_ecu(const Addr a1, |
| 353 | const SizeT len, |
| 354 | UInt ec_uniq) |
| 355 | { |
bart | f9427fd | 2010-08-29 09:19:07 +0000 | [diff] [blame] | 356 | drd_start_using_mem(a1, len, False); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static void drd_start_using_mem_w_tid(const Addr a1, |
| 360 | const SizeT len, |
| 361 | ThreadId tid) |
| 362 | { |
bart | f9427fd | 2010-08-29 09:19:07 +0000 | [diff] [blame] | 363 | drd_start_using_mem(a1, len, False); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 364 | } |
| 365 | |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 366 | static __inline__ |
| 367 | void drd_stop_using_mem(const Addr a1, const SizeT len, |
| 368 | const Bool is_stack_mem) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 369 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 370 | const Addr a2 = a1 + len; |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 371 | |
bart | a300398 | 2010-09-08 16:29:17 +0000 | [diff] [blame] | 372 | tl_assert(a1 <= a2); |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 373 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 374 | if (UNLIKELY(DRD_(any_address_is_traced)())) |
bart | 42f3263 | 2011-12-13 11:12:05 +0000 | [diff] [blame] | 375 | DRD_(trace_mem_access)(a1, len, eEnd, 0, 0); |
bart | f9427fd | 2010-08-29 09:19:07 +0000 | [diff] [blame] | 376 | |
| 377 | if (!is_stack_mem && s_trace_alloc) |
bart | ad994e8 | 2011-10-13 18:04:30 +0000 | [diff] [blame] | 378 | DRD_(trace_msg)("Stopped using memory range 0x%lx + %ld", |
bart | b92ff0f | 2011-10-08 08:29:29 +0000 | [diff] [blame] | 379 | a1, len); |
bart | f9427fd | 2010-08-29 09:19:07 +0000 | [diff] [blame] | 380 | |
bart | 0759503 | 2010-08-29 09:51:06 +0000 | [diff] [blame] | 381 | if (!is_stack_mem || DRD_(get_check_stack_accesses)()) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 382 | { |
bart | 7d5f523 | 2011-03-13 09:08:10 +0000 | [diff] [blame] | 383 | if (is_stack_mem || !DRD_(g_free_is_write)) |
bart | 639d0ad | 2011-03-12 14:26:01 +0000 | [diff] [blame] | 384 | DRD_(thread_stop_using_mem)(a1, a2); |
bart | 7d5f523 | 2011-03-13 09:08:10 +0000 | [diff] [blame] | 385 | else if (DRD_(g_free_is_write)) |
bart | 639d0ad | 2011-03-12 14:26:01 +0000 | [diff] [blame] | 386 | DRD_(trace_store)(a1, len); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 387 | DRD_(clientobj_stop_using_mem)(a1, a2); |
| 388 | DRD_(suppression_stop_using_mem)(a1, a2); |
| 389 | } |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static __inline__ |
| 393 | void drd_stop_using_nonstack_mem(const Addr a1, const SizeT len) |
| 394 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 395 | drd_stop_using_mem(a1, len, False); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 396 | } |
| 397 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 398 | /** |
bart | fdaa018 | 2009-03-10 09:25:32 +0000 | [diff] [blame] | 399 | * Discard all information DRD has about memory accesses and client objects |
| 400 | * in the specified address range. |
| 401 | */ |
| 402 | void DRD_(clean_memory)(const Addr a1, const SizeT len) |
| 403 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 404 | const Bool is_stack_memory = DRD_(thread_address_on_any_stack)(a1); |
| 405 | drd_stop_using_mem(a1, len, is_stack_memory); |
bart | f9427fd | 2010-08-29 09:19:07 +0000 | [diff] [blame] | 406 | drd_start_using_mem(a1, len, is_stack_memory); |
bart | fdaa018 | 2009-03-10 09:25:32 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /** |
bart | 6834783 | 2012-09-06 14:08:26 +0000 | [diff] [blame] | 410 | * Suppress data race reports on all addresses contained in .plt, .got and |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 411 | * .got.plt sections inside the address range [ a, a + len [. The data in |
| 412 | * these sections is modified by _dl_relocate_object() every time a function |
| 413 | * in a shared library is called for the first time. Since the first call |
| 414 | * to a function in a shared library can happen from a multithreaded context, |
| 415 | * such calls can cause conflicting accesses. See also Ulrich Drepper's |
| 416 | * paper "How to Write Shared Libraries" for more information about relocation |
| 417 | * (http://people.redhat.com/drepper/dsohowto.pdf). |
bart | 6834783 | 2012-09-06 14:08:26 +0000 | [diff] [blame] | 418 | * Note: the contents of the .got section is only modified by the MIPS resolver. |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 419 | */ |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 420 | static void DRD_(suppress_relocation_conflicts)(const Addr a, const SizeT len) |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 421 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 422 | const DebugInfo* di; |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 423 | |
bart | a9cc2dd | 2012-01-15 19:17:37 +0000 | [diff] [blame] | 424 | if (trace_sectsuppr) |
| 425 | VG_(dmsg)("Evaluating range @ 0x%lx size %ld\n", a, len); |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 426 | |
bart | a9cc2dd | 2012-01-15 19:17:37 +0000 | [diff] [blame] | 427 | for (di = VG_(next_DebugInfo)(0); di; di = VG_(next_DebugInfo)(di)) { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 428 | Addr avma; |
| 429 | SizeT size; |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 430 | |
bart | a9cc2dd | 2012-01-15 19:17:37 +0000 | [diff] [blame] | 431 | if (trace_sectsuppr) |
| 432 | VG_(dmsg)("Examining %s / %s\n", VG_(DebugInfo_get_filename)(di), |
| 433 | VG_(DebugInfo_get_soname)(di)); |
| 434 | |
bart | 90c8d7e | 2013-08-24 17:53:00 +0000 | [diff] [blame] | 435 | /* |
| 436 | * Suppress the race report on the libpthread global variable |
| 437 | * __pthread_multiple_threads. See also |
| 438 | * http://bugs.kde.org/show_bug.cgi?id=323905. |
| 439 | */ |
| 440 | avma = VG_(DebugInfo_get_bss_avma)(di); |
| 441 | size = VG_(DebugInfo_get_bss_size)(di); |
| 442 | tl_assert((avma && size) || (avma == 0 && size == 0)); |
| 443 | if (size > 0 && |
| 444 | VG_(strcmp)(VG_(DebugInfo_get_soname)(di), "libpthread.so.0") == 0) { |
| 445 | if (trace_sectsuppr) |
| 446 | VG_(dmsg)("Suppressing .bss @ 0x%lx size %ld\n", avma, size); |
| 447 | tl_assert(VG_(DebugInfo_sect_kind)(NULL, 0, avma) == Vg_SectBSS); |
| 448 | DRD_(start_suppression)(avma, avma + size, ".bss"); |
| 449 | } |
| 450 | |
sewardj | e3f1e59 | 2009-07-31 09:41:29 +0000 | [diff] [blame] | 451 | avma = VG_(DebugInfo_get_plt_avma)(di); |
| 452 | size = VG_(DebugInfo_get_plt_size)(di); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 453 | tl_assert((avma && size) || (avma == 0 && size == 0)); |
bart | a9cc2dd | 2012-01-15 19:17:37 +0000 | [diff] [blame] | 454 | if (size > 0) { |
| 455 | if (trace_sectsuppr) |
| 456 | VG_(dmsg)("Suppressing .plt @ 0x%lx size %ld\n", avma, size); |
sewardj | e3f1e59 | 2009-07-31 09:41:29 +0000 | [diff] [blame] | 457 | tl_assert(VG_(DebugInfo_sect_kind)(NULL, 0, avma) == Vg_SectPLT); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 458 | DRD_(start_suppression)(avma, avma + size, ".plt"); |
| 459 | } |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 460 | |
sewardj | e3f1e59 | 2009-07-31 09:41:29 +0000 | [diff] [blame] | 461 | avma = VG_(DebugInfo_get_gotplt_avma)(di); |
| 462 | size = VG_(DebugInfo_get_gotplt_size)(di); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 463 | tl_assert((avma && size) || (avma == 0 && size == 0)); |
bart | a9cc2dd | 2012-01-15 19:17:37 +0000 | [diff] [blame] | 464 | if (size > 0) { |
| 465 | if (trace_sectsuppr) |
| 466 | VG_(dmsg)("Suppressing .got.plt @ 0x%lx size %ld\n", avma, size); |
sewardj | e3f1e59 | 2009-07-31 09:41:29 +0000 | [diff] [blame] | 467 | tl_assert(VG_(DebugInfo_sect_kind)(NULL, 0, avma) == Vg_SectGOTPLT); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 468 | DRD_(start_suppression)(avma, avma + size, ".gotplt"); |
| 469 | } |
bart | 6834783 | 2012-09-06 14:08:26 +0000 | [diff] [blame] | 470 | |
| 471 | avma = VG_(DebugInfo_get_got_avma)(di); |
| 472 | size = VG_(DebugInfo_get_got_size)(di); |
| 473 | tl_assert((avma && size) || (avma == 0 && size == 0)); |
| 474 | if (size > 0) { |
| 475 | if (trace_sectsuppr) |
| 476 | VG_(dmsg)("Suppressing .got @ 0x%lx size %ld\n", avma, size); |
| 477 | tl_assert(VG_(DebugInfo_sect_kind)(NULL, 0, avma) == Vg_SectGOT); |
| 478 | DRD_(start_suppression)(avma, avma + size, ".got"); |
| 479 | } |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 480 | } |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 481 | } |
| 482 | |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 483 | static |
| 484 | void drd_start_using_mem_w_perms(const Addr a, const SizeT len, |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 485 | const Bool rr, const Bool ww, const Bool xx, |
| 486 | ULong di_handle) |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 487 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 488 | DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)()); |
bart | d576591 | 2008-03-16 08:40:55 +0000 | [diff] [blame] | 489 | |
bart | f9427fd | 2010-08-29 09:19:07 +0000 | [diff] [blame] | 490 | drd_start_using_mem(a, len, False); |
bart | cb2d007 | 2008-05-31 07:55:51 +0000 | [diff] [blame] | 491 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 492 | DRD_(suppress_relocation_conflicts)(a, len); |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 493 | } |
| 494 | |
bart | ad193e7 | 2012-01-15 19:02:20 +0000 | [diff] [blame] | 495 | /** |
| 496 | * Called by the core when the stack of a thread grows, to indicate that |
| 497 | * the addresses in range [ a, a + len [ may now be used by the client. |
| 498 | * Assumption: stacks grow downward. |
| 499 | */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 500 | static __inline__ |
bart | 993d32f | 2012-01-15 19:08:13 +0000 | [diff] [blame] | 501 | void drd_start_using_mem_stack2(const DrdThreadId tid, const Addr a, |
| 502 | const SizeT len) |
| 503 | { |
| 504 | DRD_(thread_set_stack_min)(tid, a - VG_STACK_REDZONE_SZB); |
| 505 | drd_start_using_mem(a - VG_STACK_REDZONE_SZB, len + VG_STACK_REDZONE_SZB, |
| 506 | True); |
| 507 | } |
| 508 | |
| 509 | static __inline__ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 510 | void drd_start_using_mem_stack(const Addr a, const SizeT len) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 511 | { |
bart | 993d32f | 2012-01-15 19:08:13 +0000 | [diff] [blame] | 512 | drd_start_using_mem_stack2(DRD_(thread_get_running_tid)(), a, len); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 513 | } |
| 514 | |
bart | ad193e7 | 2012-01-15 19:02:20 +0000 | [diff] [blame] | 515 | /** |
| 516 | * Called by the core when the stack of a thread shrinks, to indicate that |
| 517 | * the addresses [ a, a + len [ are no longer accessible for the client. |
| 518 | * Assumption: stacks grow downward. |
| 519 | */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 520 | static __inline__ |
bart | 993d32f | 2012-01-15 19:08:13 +0000 | [diff] [blame] | 521 | void drd_stop_using_mem_stack2(const DrdThreadId tid, const Addr a, |
| 522 | const SizeT len) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 523 | { |
bart | 993d32f | 2012-01-15 19:08:13 +0000 | [diff] [blame] | 524 | DRD_(thread_set_stack_min)(tid, a + len - VG_STACK_REDZONE_SZB); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 525 | drd_stop_using_mem(a - VG_STACK_REDZONE_SZB, len + VG_STACK_REDZONE_SZB, |
| 526 | True); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 527 | } |
| 528 | |
bart | 993d32f | 2012-01-15 19:08:13 +0000 | [diff] [blame] | 529 | static __inline__ |
| 530 | void drd_stop_using_mem_stack(const Addr a, const SizeT len) |
| 531 | { |
| 532 | drd_stop_using_mem_stack2(DRD_(thread_get_running_tid)(), a, len); |
| 533 | } |
| 534 | |
bart | 68a8afa | 2010-09-02 14:50:41 +0000 | [diff] [blame] | 535 | static |
| 536 | Bool on_alt_stack(const Addr a) |
| 537 | { |
| 538 | ThreadId vg_tid; |
| 539 | Addr alt_min; |
| 540 | SizeT alt_size; |
| 541 | |
| 542 | vg_tid = VG_(get_running_tid)(); |
| 543 | alt_min = VG_(thread_get_altstack_min)(vg_tid); |
| 544 | alt_size = VG_(thread_get_altstack_size)(vg_tid); |
| 545 | return (SizeT)(a - alt_min) < alt_size; |
| 546 | } |
| 547 | |
| 548 | static |
| 549 | void drd_start_using_mem_alt_stack(const Addr a, const SizeT len) |
| 550 | { |
| 551 | if (!on_alt_stack(a)) |
| 552 | drd_start_using_mem_stack(a, len); |
| 553 | } |
| 554 | |
| 555 | static |
| 556 | void drd_stop_using_mem_alt_stack(const Addr a, const SizeT len) |
| 557 | { |
| 558 | if (!on_alt_stack(a)) |
| 559 | drd_stop_using_mem_stack(a, len); |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * Callback function invoked by the Valgrind core before a signal is delivered. |
| 564 | */ |
| 565 | static |
| 566 | void drd_pre_deliver_signal(const ThreadId vg_tid, const Int sigNo, |
| 567 | const Bool alt_stack) |
| 568 | { |
| 569 | DrdThreadId drd_tid; |
| 570 | |
| 571 | drd_tid = DRD_(VgThreadIdToDrdThreadId)(vg_tid); |
| 572 | DRD_(thread_set_on_alt_stack)(drd_tid, alt_stack); |
| 573 | if (alt_stack) |
| 574 | { |
| 575 | /* |
| 576 | * As soon a signal handler has been invoked on the alternate stack, |
| 577 | * switch to stack memory handling functions that can handle the |
| 578 | * alternate stack. |
| 579 | */ |
| 580 | VG_(track_new_mem_stack)(drd_start_using_mem_alt_stack); |
| 581 | VG_(track_die_mem_stack)(drd_stop_using_mem_alt_stack); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * Callback function invoked by the Valgrind core after a signal is delivered, |
| 587 | * at least if the signal handler did not longjmp(). |
| 588 | */ |
| 589 | static |
| 590 | void drd_post_deliver_signal(const ThreadId vg_tid, const Int sigNo) |
| 591 | { |
| 592 | DrdThreadId drd_tid; |
| 593 | |
| 594 | drd_tid = DRD_(VgThreadIdToDrdThreadId)(vg_tid); |
| 595 | DRD_(thread_set_on_alt_stack)(drd_tid, False); |
| 596 | if (DRD_(thread_get_threads_on_alt_stack)() == 0) |
| 597 | { |
| 598 | VG_(track_new_mem_stack)(drd_start_using_mem_stack); |
| 599 | VG_(track_die_mem_stack)(drd_stop_using_mem_stack); |
| 600 | } |
| 601 | } |
| 602 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 603 | /** |
| 604 | * Callback function called by the Valgrind core before a stack area is |
| 605 | * being used by a signal handler. |
| 606 | * |
bart | 573d074 | 2013-03-10 11:02:32 +0000 | [diff] [blame] | 607 | * @param[in] a Start of address range - VG_STACK_REDZONE_SZB. |
| 608 | * @param[in] len Address range length + VG_STACK_REDZONE_SZB. |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 609 | * @param[in] tid Valgrind thread ID for whom the signal frame is being |
| 610 | * constructed. |
| 611 | */ |
| 612 | static void drd_start_using_mem_stack_signal(const Addr a, const SizeT len, |
| 613 | ThreadId tid) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 614 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 615 | DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)()); |
bart | 573d074 | 2013-03-10 11:02:32 +0000 | [diff] [blame] | 616 | drd_start_using_mem(a + VG_STACK_REDZONE_SZB, len - VG_STACK_REDZONE_SZB, |
| 617 | True); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 618 | } |
| 619 | |
bart | 5e85d26 | 2008-03-01 10:49:37 +0000 | [diff] [blame] | 620 | static void drd_stop_using_mem_stack_signal(Addr a, SizeT len) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 621 | { |
bart | 573d074 | 2013-03-10 11:02:32 +0000 | [diff] [blame] | 622 | drd_stop_using_mem(a + VG_STACK_REDZONE_SZB, len - VG_STACK_REDZONE_SZB, |
| 623 | True); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static |
| 627 | void drd_pre_thread_create(const ThreadId creator, const ThreadId created) |
| 628 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 629 | const DrdThreadId drd_creator = DRD_(VgThreadIdToDrdThreadId)(creator); |
| 630 | tl_assert(created != VG_INVALID_THREADID); |
| 631 | DRD_(thread_pre_create)(drd_creator, created); |
| 632 | if (DRD_(IsValidDrdThreadId)(drd_creator)) |
| 633 | { |
| 634 | DRD_(thread_new_segment)(drd_creator); |
| 635 | } |
| 636 | if (DRD_(thread_get_trace_fork_join)()) |
| 637 | { |
bart | ad994e8 | 2011-10-13 18:04:30 +0000 | [diff] [blame] | 638 | DRD_(trace_msg)("drd_pre_thread_create creator = %d, created = %d", |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 639 | drd_creator, created); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 640 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 641 | } |
| 642 | |
bart | ad193e7 | 2012-01-15 19:02:20 +0000 | [diff] [blame] | 643 | /** |
| 644 | * Called by Valgrind's core before any loads or stores are performed on |
| 645 | * the context of thread "created". |
| 646 | */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 647 | static |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 648 | void drd_post_thread_create(const ThreadId vg_created) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 649 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 650 | DrdThreadId drd_created; |
bart | 864920d | 2012-01-15 19:13:35 +0000 | [diff] [blame] | 651 | Addr stack_max; |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 652 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 653 | tl_assert(vg_created != VG_INVALID_THREADID); |
bart | 0ffa483 | 2008-04-05 12:57:01 +0000 | [diff] [blame] | 654 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 655 | drd_created = DRD_(thread_post_create)(vg_created); |
bart | 864920d | 2012-01-15 19:13:35 +0000 | [diff] [blame] | 656 | |
| 657 | /* Set up red zone before the code in glibc's clone.S is run. */ |
| 658 | stack_max = DRD_(thread_get_stack_max)(drd_created); |
| 659 | drd_start_using_mem_stack2(drd_created, stack_max, 0); |
| 660 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 661 | if (DRD_(thread_get_trace_fork_join)()) |
| 662 | { |
bart | ad994e8 | 2011-10-13 18:04:30 +0000 | [diff] [blame] | 663 | DRD_(trace_msg)("drd_post_thread_create created = %d", drd_created); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 664 | } |
| 665 | if (! DRD_(get_check_stack_accesses)()) |
| 666 | { |
| 667 | DRD_(start_suppression)(DRD_(thread_get_stack_max)(drd_created) |
| 668 | - DRD_(thread_get_stack_size)(drd_created), |
| 669 | DRD_(thread_get_stack_max)(drd_created), |
| 670 | "stack"); |
| 671 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 672 | } |
| 673 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 674 | /* Called after a thread has performed its last memory access. */ |
bart | d43f8d3 | 2008-03-16 17:29:20 +0000 | [diff] [blame] | 675 | static void drd_thread_finished(ThreadId vg_tid) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 676 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 677 | DrdThreadId drd_tid; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 678 | |
bart | 9bb46c4 | 2012-02-02 10:14:30 +0000 | [diff] [blame] | 679 | /* |
bart | 37e1dd0 | 2012-02-02 10:58:01 +0000 | [diff] [blame] | 680 | * Ignore if invoked because thread creation failed. See e.g. |
bart | 9bb46c4 | 2012-02-02 10:14:30 +0000 | [diff] [blame] | 681 | * coregrind/m_syswrap/syswrap-amd64-linux.c |
| 682 | */ |
bart | 37e1dd0 | 2012-02-02 10:58:01 +0000 | [diff] [blame] | 683 | if (VG_(get_running_tid)() != vg_tid) |
| 684 | return; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 685 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 686 | drd_tid = DRD_(VgThreadIdToDrdThreadId)(vg_tid); |
bart | 37e1dd0 | 2012-02-02 10:58:01 +0000 | [diff] [blame] | 687 | tl_assert(drd_tid != DRD_INVALID_THREADID); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 688 | if (DRD_(thread_get_trace_fork_join)()) |
| 689 | { |
bart | ad994e8 | 2011-10-13 18:04:30 +0000 | [diff] [blame] | 690 | DRD_(trace_msg)("drd_thread_finished tid = %d%s", drd_tid, |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 691 | DRD_(thread_get_joinable)(drd_tid) |
| 692 | ? "" : " (which is a detached thread)"); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 693 | } |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 694 | if (s_show_stack_usage && !VG_(clo_xml)) { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 695 | const SizeT stack_size = DRD_(thread_get_stack_size)(drd_tid); |
| 696 | const SizeT used_stack |
| 697 | = (DRD_(thread_get_stack_max)(drd_tid) |
| 698 | - DRD_(thread_get_stack_min_min)(drd_tid)); |
| 699 | VG_(message)(Vg_UserMsg, |
bart | 63c92ea | 2009-07-19 17:53:56 +0000 | [diff] [blame] | 700 | "thread %d%s finished and used %ld bytes out of %ld" |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 701 | " on its stack. Margin: %ld bytes.\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 702 | drd_tid, |
| 703 | DRD_(thread_get_joinable)(drd_tid) |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 704 | ? "" : " (which is a detached thread)", |
| 705 | used_stack, stack_size, stack_size - used_stack); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 706 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 707 | } |
| 708 | drd_stop_using_mem(DRD_(thread_get_stack_min)(drd_tid), |
| 709 | DRD_(thread_get_stack_max)(drd_tid) |
| 710 | - DRD_(thread_get_stack_min)(drd_tid), |
| 711 | True); |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 712 | DRD_(thread_set_record_loads)(drd_tid, False); |
| 713 | DRD_(thread_set_record_stores)(drd_tid, False); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 714 | DRD_(thread_finished)(drd_tid); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 715 | } |
| 716 | |
bart | 5c7e6b6 | 2011-02-03 17:47:50 +0000 | [diff] [blame] | 717 | /* |
| 718 | * Called immediately after fork for the child process only. 'tid' is the |
| 719 | * only surviving thread in the child process. Cleans up thread state. |
| 720 | * See also http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_atfork.html for a detailed discussion of using fork() in combination with mutexes. |
| 721 | */ |
| 722 | static |
| 723 | void drd__atfork_child(ThreadId tid) |
| 724 | { |
| 725 | DRD_(drd_thread_atfork_child)(tid); |
| 726 | } |
| 727 | |
| 728 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 729 | // |
| 730 | // Implementation of the tool interface. |
| 731 | // |
| 732 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 733 | static void DRD_(post_clo_init)(void) |
sewardj | dcbb8d3 | 2007-11-26 21:34:30 +0000 | [diff] [blame] | 734 | { |
bart | 0c6bf35 | 2009-07-25 14:03:53 +0000 | [diff] [blame] | 735 | #if defined(VGO_linux) || defined(VGO_darwin) |
bart | c6ef4af | 2009-07-23 10:10:30 +0000 | [diff] [blame] | 736 | /* fine */ |
bart | c6ef4af | 2009-07-23 10:10:30 +0000 | [diff] [blame] | 737 | #else |
| 738 | VG_(printf)("\nWARNING: DRD has not yet been tested on this operating system.\n\n"); |
sewardj | dcbb8d3 | 2007-11-26 21:34:30 +0000 | [diff] [blame] | 739 | # endif |
bart | 95761b5 | 2008-03-29 08:34:03 +0000 | [diff] [blame] | 740 | |
bart | 75c1cba | 2010-08-29 07:20:30 +0000 | [diff] [blame] | 741 | if (s_var_info) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 742 | { |
| 743 | VG_(needs_var_info)(); |
| 744 | } |
sewardj | dcbb8d3 | 2007-11-26 21:34:30 +0000 | [diff] [blame] | 745 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 746 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 747 | static void drd_start_client_code(const ThreadId tid, const ULong bbs_done) |
| 748 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 749 | tl_assert(tid == VG_(get_running_tid)()); |
| 750 | DRD_(thread_set_vg_running_tid)(tid); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 751 | } |
| 752 | |
bart | 1335ecc | 2009-02-14 16:10:53 +0000 | [diff] [blame] | 753 | static void DRD_(fini)(Int exitcode) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 754 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 755 | // thread_print_all(); |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 756 | if (VG_(clo_verbosity) == 1 && !VG_(clo_xml)) { |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 757 | VG_(message)(Vg_UserMsg, "For counts of detected and suppressed errors, " |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 758 | "rerun with: -v\n"); |
| 759 | } |
| 760 | |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 761 | if ((VG_(clo_stats) || s_print_stats) && !VG_(clo_xml)) |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 762 | { |
bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 763 | ULong pu = DRD_(thread_get_update_conflict_set_count)(); |
| 764 | ULong pu_seg_cr = DRD_(thread_get_update_conflict_set_new_sg_count)(); |
| 765 | ULong pu_mtx_cv = DRD_(thread_get_update_conflict_set_sync_count)(); |
| 766 | ULong pu_join = DRD_(thread_get_update_conflict_set_join_count)(); |
| 767 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 768 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 769 | " thread: %lld context switches.\n", |
bart | 54803fe | 2009-06-21 09:26:27 +0000 | [diff] [blame] | 770 | DRD_(thread_get_context_switch_count)()); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 771 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 772 | "confl set: %lld full updates and %lld partial updates;\n", |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 773 | DRD_(thread_get_compute_conflict_set_count)(), |
| 774 | pu); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 775 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 776 | " %lld partial updates during segment creation,\n", |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 777 | pu_seg_cr); |
bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 778 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 779 | " %lld because of mutex/sema/cond.var. operations,\n", |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 780 | pu_mtx_cv); |
bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 781 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 782 | " %lld because of barrier/rwlock operations and\n", |
bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 783 | pu - pu_seg_cr - pu_mtx_cv - pu_join); |
| 784 | VG_(message)(Vg_UserMsg, |
| 785 | " %lld partial updates because of thread join" |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 786 | " operations.\n", |
| 787 | pu_join); |
bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 788 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 789 | " segments: created %lld segments, max %lld alive,\n", |
bart | 9dedafe | 2009-06-21 18:09:02 +0000 | [diff] [blame] | 790 | DRD_(sg_get_segments_created_count)(), |
| 791 | DRD_(sg_get_max_segments_alive_count)()); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 792 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 793 | " %lld discard points and %lld merges.\n", |
bart | 9dedafe | 2009-06-21 18:09:02 +0000 | [diff] [blame] | 794 | DRD_(thread_get_discard_ordered_segments_count)(), |
bart | 1a3b0b3 | 2009-05-03 17:07:34 +0000 | [diff] [blame] | 795 | DRD_(sg_get_segment_merge_count)()); |
| 796 | VG_(message)(Vg_UserMsg, |
bart | 54803fe | 2009-06-21 09:26:27 +0000 | [diff] [blame] | 797 | "segmnt cr: %lld mutex, %lld rwlock, %lld semaphore and" |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 798 | " %lld barrier.\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 799 | DRD_(get_mutex_segment_creation_count)(), |
| 800 | DRD_(get_rwlock_segment_creation_count)(), |
| 801 | DRD_(get_semaphore_segment_creation_count)(), |
| 802 | DRD_(get_barrier_segment_creation_count)()); |
| 803 | VG_(message)(Vg_UserMsg, |
bart | 9dedafe | 2009-06-21 18:09:02 +0000 | [diff] [blame] | 804 | " bitmaps: %lld level one" |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 805 | " and %lld level two bitmaps were allocated.\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 806 | DRD_(bm_get_bitmap_creation_count)(), |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 807 | DRD_(bm_get_bitmap2_creation_count)()); |
| 808 | VG_(message)(Vg_UserMsg, |
sewardj | 1e29ebc | 2009-07-15 14:49:17 +0000 | [diff] [blame] | 809 | " mutex: %lld non-recursive lock/unlock events.\n", |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 810 | DRD_(get_mutex_lock_count)()); |
| 811 | DRD_(print_malloc_stats)(); |
| 812 | } |
bart | e44bccc | 2012-01-18 09:46:57 +0000 | [diff] [blame] | 813 | |
| 814 | DRD_(bm_module_cleanup)(); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 815 | } |
| 816 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 817 | static |
| 818 | void drd_pre_clo_init(void) |
| 819 | { |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 820 | // Basic tool stuff. |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 821 | VG_(details_name) ("drd"); |
| 822 | VG_(details_version) (NULL); |
| 823 | VG_(details_description) ("a thread error detector"); |
bart | d4bab99 | 2013-10-04 05:55:30 +0000 | [diff] [blame] | 824 | VG_(details_copyright_author)("Copyright (C) 2006-2013, and GNU GPL'd," |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 825 | " by Bart Van Assche."); |
| 826 | VG_(details_bug_reports_to) (VG_BUGS_TO); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 827 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 828 | VG_(basic_tool_funcs) (DRD_(post_clo_init), |
| 829 | DRD_(instrument), |
| 830 | DRD_(fini)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 831 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 832 | // Command line stuff. |
| 833 | VG_(needs_command_line_options)(DRD_(process_cmd_line_option), |
| 834 | DRD_(print_usage), |
| 835 | DRD_(print_debug_usage)); |
bart | e708600 | 2011-10-11 19:08:39 +0000 | [diff] [blame] | 836 | VG_(needs_xml_output) (); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 837 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 838 | // Error handling. |
| 839 | DRD_(register_error_handlers)(); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 840 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 841 | // Core event tracking. |
| 842 | VG_(track_pre_mem_read) (drd_pre_mem_read); |
| 843 | VG_(track_pre_mem_read_asciiz) (drd_pre_mem_read_asciiz); |
| 844 | VG_(track_post_mem_write) (drd_post_mem_write); |
| 845 | VG_(track_new_mem_brk) (drd_start_using_mem_w_tid); |
| 846 | VG_(track_new_mem_mmap) (drd_start_using_mem_w_perms); |
| 847 | VG_(track_new_mem_stack) (drd_start_using_mem_stack); |
| 848 | VG_(track_new_mem_stack_signal) (drd_start_using_mem_stack_signal); |
| 849 | VG_(track_new_mem_startup) (drd_start_using_mem_w_perms); |
| 850 | VG_(track_die_mem_brk) (drd_stop_using_nonstack_mem); |
| 851 | VG_(track_die_mem_munmap) (drd_stop_using_nonstack_mem); |
| 852 | VG_(track_die_mem_stack) (drd_stop_using_mem_stack); |
| 853 | VG_(track_die_mem_stack_signal) (drd_stop_using_mem_stack_signal); |
bart | 68a8afa | 2010-09-02 14:50:41 +0000 | [diff] [blame] | 854 | VG_(track_pre_deliver_signal) (drd_pre_deliver_signal); |
| 855 | VG_(track_post_deliver_signal) (drd_post_deliver_signal); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 856 | VG_(track_start_client_code) (drd_start_client_code); |
| 857 | VG_(track_pre_thread_ll_create) (drd_pre_thread_create); |
| 858 | VG_(track_pre_thread_first_insn)(drd_post_thread_create); |
| 859 | VG_(track_pre_thread_ll_exit) (drd_thread_finished); |
bart | 5c7e6b6 | 2011-02-03 17:47:50 +0000 | [diff] [blame] | 860 | VG_(atfork) (NULL/*pre*/, NULL/*parent*/, |
| 861 | drd__atfork_child/*child*/); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 862 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 863 | // Other stuff. |
| 864 | DRD_(register_malloc_wrappers)(drd_start_using_mem_w_ecu, |
| 865 | drd_stop_using_nonstack_mem); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 866 | |
bart | e44bccc | 2012-01-18 09:46:57 +0000 | [diff] [blame] | 867 | DRD_(bm_module_init)(); |
| 868 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 869 | DRD_(clientreq_init)(); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 870 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 871 | DRD_(suppression_init)(); |
bart | 4bb53d8 | 2008-02-28 19:06:34 +0000 | [diff] [blame] | 872 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 873 | DRD_(clientobj_init)(); |
bart | e5e0efa | 2009-06-24 18:35:02 +0000 | [diff] [blame] | 874 | |
bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 875 | DRD_(thread_init)(); |
| 876 | |
bart | e5e0efa | 2009-06-24 18:35:02 +0000 | [diff] [blame] | 877 | { |
florian | 19f91bb | 2012-11-10 22:29:54 +0000 | [diff] [blame] | 878 | HChar* const smi = VG_(getenv)("DRD_SEGMENT_MERGING_INTERVAL"); |
bart | e5e0efa | 2009-06-24 18:35:02 +0000 | [diff] [blame] | 879 | if (smi) |
| 880 | DRD_(thread_set_segment_merge_interval)(VG_(strtoll10)(smi, NULL)); |
| 881 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | |
| 885 | VG_DETERMINE_INTERFACE_VERSION(drd_pre_clo_init) |