blob: a967a95117b9d3dbe3f656bd6261819e470e4029 [file] [log] [blame]
sewardjaf44c822007-11-25 14:01:38 +00001/*
bart86562bd2009-02-16 19:43:56 +00002 This file is part of drd, a thread error detector.
sewardjaf44c822007-11-25 14:01:38 +00003
bart922304f2011-03-13 12:02:44 +00004 Copyright (C) 2006-2011 Bart Van Assche <bvanassche@acm.org>.
sewardjaf44c822007-11-25 14:01:38 +00005
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
sewardj85642922008-01-14 11:54:56 +000025#include "drd_barrier.h"
bart4bb53d82008-02-28 19:06:34 +000026#include "drd_clientobj.h"
bart09dc13f2009-02-14 15:13:31 +000027#include "drd_clientreq.h"
sewardjaf44c822007-11-25 14:01:38 +000028#include "drd_cond.h"
29#include "drd_error.h"
bartc1824672011-03-12 14:07:09 +000030#include "drd_hb.h"
bart09dc13f2009-02-14 15:13:31 +000031#include "drd_load_store.h"
sewardjaf44c822007-11-25 14:01:38 +000032#include "drd_malloc_wrappers.h"
33#include "drd_mutex.h"
bart5bd9f2d2008-03-03 20:31:58 +000034#include "drd_rwlock.h"
sewardjaf44c822007-11-25 14:01:38 +000035#include "drd_segment.h"
sewardj85642922008-01-14 11:54:56 +000036#include "drd_semaphore.h"
sewardjaf44c822007-11-25 14:01:38 +000037#include "drd_suppression.h"
38#include "drd_thread.h"
barteacd9162008-06-16 20:22:18 +000039#include "libvex_guest_offsets.h"
sewardj85642922008-01-14 11:54:56 +000040#include "pub_drd_bitmap.h"
bart024a95a2008-04-01 18:27:41 +000041#include "pub_tool_vki.h" // Must be included before pub_tool_libcproc
sewardjaf44c822007-11-25 14:01:38 +000042#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"
bart024a95a2008-04-01 18:27:41 +000049#include "pub_tool_mallocfree.h" // VG_(malloc)(), VG_(free)()
sewardjaf44c822007-11-25 14:01:38 +000050#include "pub_tool_options.h" // command line options
bartceded212008-03-26 17:39:52 +000051#include "pub_tool_replacemalloc.h"
bart72b751c2008-03-01 13:44:24 +000052#include "pub_tool_threadstate.h" // VG_(get_running_tid)()
sewardjaf44c822007-11-25 14:01:38 +000053#include "pub_tool_tooliface.h"
sewardj234e5582011-02-09 12:47:23 +000054#include "pub_tool_aspacemgr.h" // VG_(am_is_valid_for_client)
sewardjaf44c822007-11-25 14:01:38 +000055
56
bart1335ecc2009-02-14 16:10:53 +000057/* Local variables. */
sewardjaf44c822007-11-25 14:01:38 +000058
bart7d5f5232011-03-13 09:08:10 +000059static Bool s_print_stats;
60static Bool s_var_info;
61static Bool s_show_stack_usage;
62static Bool s_trace_alloc;
sewardjaf44c822007-11-25 14:01:38 +000063
64
bart1335ecc2009-02-14 16:10:53 +000065/**
66 * Implement the needs_command_line_options for drd.
67 */
68static Bool DRD_(process_cmd_line_option)(Char* arg)
sewardjaf44c822007-11-25 14:01:38 +000069{
bartbedfd232009-03-26 19:07:15 +000070 int check_stack_accesses = -1;
bart6d956dc2011-07-28 09:54:37 +000071 int join_list_vol = -1;
bartbedfd232009-03-26 19:07:15 +000072 int exclusive_threshold_ms = -1;
bartf98a5692009-05-03 17:17:37 +000073 int first_race_only = -1;
bartbedfd232009-03-26 19:07:15 +000074 int report_signal_unlocked = -1;
75 int segment_merging = -1;
bart8f822af2009-06-08 18:20:42 +000076 int segment_merge_interval = -1;
bartbedfd232009-03-26 19:07:15 +000077 int shared_threshold_ms = -1;
78 int show_confl_seg = -1;
79 int trace_barrier = -1;
80 int trace_clientobj = -1;
81 int trace_cond = -1;
82 int trace_csw = -1;
83 int trace_fork_join = -1;
bartc1824672011-03-12 14:07:09 +000084 int trace_hb = -1;
bartbedfd232009-03-26 19:07:15 +000085 int trace_conflict_set = -1;
bart8f822af2009-06-08 18:20:42 +000086 int trace_conflict_set_bm = -1;
bartbedfd232009-03-26 19:07:15 +000087 int trace_mutex = -1;
88 int trace_rwlock = -1;
89 int trace_segment = -1;
90 int trace_semaphore = -1;
91 int trace_suppression = -1;
92 Char* trace_address = 0;
sewardjaf44c822007-11-25 14:01:38 +000093
bartbedfd232009-03-26 19:07:15 +000094 if VG_BOOL_CLO(arg, "--check-stack-var", check_stack_accesses) {}
bart6d956dc2011-07-28 09:54:37 +000095 else if VG_INT_CLO (arg, "--join-list-vol", join_list_vol) {}
bart75c1cba2010-08-29 07:20:30 +000096 else if VG_BOOL_CLO(arg, "--drd-stats", s_print_stats) {}
bartf98a5692009-05-03 17:17:37 +000097 else if VG_BOOL_CLO(arg, "--first-race-only", first_race_only) {}
bart7d5f5232011-03-13 09:08:10 +000098 else if VG_BOOL_CLO(arg, "--free-is-write", DRD_(g_free_is_write)) {}
bart8f822af2009-06-08 18:20:42 +000099 else if VG_BOOL_CLO(arg,"--report-signal-unlocked",report_signal_unlocked)
100 {}
bartbedfd232009-03-26 19:07:15 +0000101 else if VG_BOOL_CLO(arg, "--segment-merging", segment_merging) {}
bart8f822af2009-06-08 18:20:42 +0000102 else if VG_INT_CLO (arg, "--segment-merging-interval", segment_merge_interval)
103 {}
bartbedfd232009-03-26 19:07:15 +0000104 else if VG_BOOL_CLO(arg, "--show-confl-seg", show_confl_seg) {}
bart75c1cba2010-08-29 07:20:30 +0000105 else if VG_BOOL_CLO(arg, "--show-stack-usage", s_show_stack_usage) {}
bartf9427fd2010-08-29 09:19:07 +0000106 else if VG_BOOL_CLO(arg, "--trace-alloc", s_trace_alloc) {}
bartbedfd232009-03-26 19:07:15 +0000107 else if VG_BOOL_CLO(arg, "--trace-barrier", trace_barrier) {}
108 else if VG_BOOL_CLO(arg, "--trace-clientobj", trace_clientobj) {}
109 else if VG_BOOL_CLO(arg, "--trace-cond", trace_cond) {}
110 else if VG_BOOL_CLO(arg, "--trace-conflict-set", trace_conflict_set) {}
bart8f822af2009-06-08 18:20:42 +0000111 else if VG_BOOL_CLO(arg, "--trace-conflict-set-bm", trace_conflict_set_bm){}
bartbedfd232009-03-26 19:07:15 +0000112 else if VG_BOOL_CLO(arg, "--trace-csw", trace_csw) {}
113 else if VG_BOOL_CLO(arg, "--trace-fork-join", trace_fork_join) {}
bartc1824672011-03-12 14:07:09 +0000114 else if VG_BOOL_CLO(arg, "--trace-hb", trace_hb) {}
bartbedfd232009-03-26 19:07:15 +0000115 else if VG_BOOL_CLO(arg, "--trace-mutex", trace_mutex) {}
116 else if VG_BOOL_CLO(arg, "--trace-rwlock", trace_rwlock) {}
117 else if VG_BOOL_CLO(arg, "--trace-segment", trace_segment) {}
118 else if VG_BOOL_CLO(arg, "--trace-semaphore", trace_semaphore) {}
119 else if VG_BOOL_CLO(arg, "--trace-suppr", trace_suppression) {}
bart75c1cba2010-08-29 07:20:30 +0000120 else if VG_BOOL_CLO(arg, "--var-info", s_var_info) {}
bartbedfd232009-03-26 19:07:15 +0000121 else if VG_INT_CLO (arg, "--exclusive-threshold", exclusive_threshold_ms) {}
122 else if VG_INT_CLO (arg, "--shared-threshold", shared_threshold_ms) {}
123 else if VG_STR_CLO (arg, "--trace-addr", trace_address) {}
124 else
125 return VG_(replacement_malloc_process_cmd_line_option)(arg);
sewardjaf44c822007-11-25 14:01:38 +0000126
bartbedfd232009-03-26 19:07:15 +0000127 if (check_stack_accesses != -1)
128 DRD_(set_check_stack_accesses)(check_stack_accesses);
129 if (exclusive_threshold_ms != -1)
130 {
131 DRD_(mutex_set_lock_threshold)(exclusive_threshold_ms);
132 DRD_(rwlock_set_exclusive_threshold)(exclusive_threshold_ms);
133 }
bartf98a5692009-05-03 17:17:37 +0000134 if (first_race_only != -1)
135 {
136 DRD_(set_first_race_only)(first_race_only);
137 }
bart6d956dc2011-07-28 09:54:37 +0000138 if (join_list_vol != -1)
139 DRD_(thread_set_join_list_vol)(join_list_vol);
bartbedfd232009-03-26 19:07:15 +0000140 if (report_signal_unlocked != -1)
141 {
142 DRD_(cond_set_report_signal_unlocked)(report_signal_unlocked);
143 }
144 if (shared_threshold_ms != -1)
145 {
146 DRD_(rwlock_set_shared_threshold)(shared_threshold_ms);
147 }
148 if (segment_merging != -1)
149 DRD_(thread_set_segment_merging)(segment_merging);
bart109d5da2009-06-22 18:06:29 +0000150 if (segment_merge_interval != -1)
bart8f822af2009-06-08 18:20:42 +0000151 DRD_(thread_set_segment_merge_interval)(segment_merge_interval);
bartbedfd232009-03-26 19:07:15 +0000152 if (show_confl_seg != -1)
153 DRD_(set_show_conflicting_segments)(show_confl_seg);
154 if (trace_address)
155 {
156 const Addr addr = VG_(strtoll16)(trace_address, 0);
157 DRD_(start_tracing_address_range)(addr, addr + 1);
158 }
159 if (trace_barrier != -1)
160 DRD_(barrier_set_trace)(trace_barrier);
161 if (trace_clientobj != -1)
162 DRD_(clientobj_set_trace)(trace_clientobj);
163 if (trace_cond != -1)
164 DRD_(cond_set_trace)(trace_cond);
165 if (trace_csw != -1)
166 DRD_(thread_trace_context_switches)(trace_csw);
167 if (trace_fork_join != -1)
168 DRD_(thread_set_trace_fork_join)(trace_fork_join);
bartc1824672011-03-12 14:07:09 +0000169 if (trace_hb != -1)
170 DRD_(hb_set_trace)(trace_hb);
bartbedfd232009-03-26 19:07:15 +0000171 if (trace_conflict_set != -1)
172 DRD_(thread_trace_conflict_set)(trace_conflict_set);
bart8f822af2009-06-08 18:20:42 +0000173 if (trace_conflict_set_bm != -1)
174 DRD_(thread_trace_conflict_set_bm)(trace_conflict_set_bm);
bartbedfd232009-03-26 19:07:15 +0000175 if (trace_mutex != -1)
176 DRD_(mutex_set_trace)(trace_mutex);
177 if (trace_rwlock != -1)
178 DRD_(rwlock_set_trace)(trace_rwlock);
179 if (trace_segment != -1)
180 DRD_(sg_set_trace)(trace_segment);
181 if (trace_semaphore != -1)
182 DRD_(semaphore_set_trace)(trace_semaphore);
183 if (trace_suppression != -1)
184 DRD_(suppression_set_trace)(trace_suppression);
sewardjaf44c822007-11-25 14:01:38 +0000185
bartbedfd232009-03-26 19:07:15 +0000186 return True;
sewardjaf44c822007-11-25 14:01:38 +0000187}
188
bart1335ecc2009-02-14 16:10:53 +0000189static void DRD_(print_usage)(void)
bartbd7e56e2008-03-31 18:14:12 +0000190{
bartbedfd232009-03-26 19:07:15 +0000191 VG_(printf)(
bart0ffa4832008-04-05 12:57:01 +0000192" --check-stack-var=yes|no Whether or not to report data races on\n"
193" stack variables [no].\n"
bart9d5b7962008-05-14 12:25:00 +0000194" --exclusive-threshold=<n> Print an error message if any mutex or\n"
bart8600c422010-10-25 18:18:54 +0000195" writer lock is held longer than the specified\n"
196" time (in milliseconds) [off].\n"
bart1a3b0b32009-05-03 17:07:34 +0000197" --first-race-only=yes|no Only report the first data race that occurs on\n"
198" a memory location instead of all races [no].\n"
bart639d0ad2011-03-12 14:26:01 +0000199" --free-is-write=yes|no Whether to report races between freeing memory\n"
200" and subsequent accesses of that memory[no].\n"
bart505b35c2011-10-13 18:51:47 +0000201" --join-list-vol=<n> Number of threads to delay cleanup for [10].\n"
bart46b5fce2008-06-28 13:01:30 +0000202" --report-signal-unlocked=yes|no Whether to report calls to\n"
203" pthread_cond_signal() where the mutex associated\n"
204" with the signal via pthread_cond_wait() is not\n"
205" locked at the time the signal is sent [yes].\n"
bart130463a2008-04-01 17:03:33 +0000206" --segment-merging=yes|no Controls segment merging [yes].\n"
bartbd7e56e2008-03-31 18:14:12 +0000207" Segment merging is an algorithm to limit memory usage of the\n"
208" data race detection algorithm. Disabling segment merging may\n"
209" improve the accuracy of the so-called 'other segments' displayed\n"
210" in race reports but can also trigger an out of memory error.\n"
bart8f822af2009-06-08 18:20:42 +0000211" --segment-merging-interval=<n> Perform segment merging every time n new\n"
212" segments have been created. Default: %d.\n"
bart9d5b7962008-05-14 12:25:00 +0000213" --shared-threshold=<n> Print an error message if a reader lock\n"
bart8600c422010-10-25 18:18:54 +0000214" is held longer than the specified time (in\n"
215" milliseconds) [off]\n"
bart130463a2008-04-01 17:03:33 +0000216" --show-confl-seg=yes|no Show conflicting segments in race reports [yes].\n"
217" --show-stack-usage=yes|no Print stack usage at thread exit time [no].\n"
bartbd7e56e2008-03-31 18:14:12 +0000218"\n"
bartef1b9722008-07-04 15:34:23 +0000219" drd options for monitoring process behavior:\n"
bart8c3de752011-12-12 15:49:00 +0000220" --trace-addr=<address> Trace all load and store activity for the\n"
bart130463a2008-04-01 17:03:33 +0000221" specified address [off].\n"
bartf9427fd2010-08-29 09:19:07 +0000222" --trace-alloc=yes|no Trace all memory allocations and deallocations\n"" [no].\n"
bart130463a2008-04-01 17:03:33 +0000223" --trace-barrier=yes|no Trace all barrier activity [no].\n"
224" --trace-cond=yes|no Trace all condition variable activity [no].\n"
225" --trace-fork-join=yes|no Trace all thread fork/join activity [no].\n"
bart505b35c2011-10-13 18:51:47 +0000226" --trace-hb=yes|no Trace ANNOTATE_HAPPENS_BEFORE() etc. [no].\n"
bart130463a2008-04-01 17:03:33 +0000227" --trace-mutex=yes|no Trace all mutex activity [no].\n"
228" --trace-rwlock=yes|no Trace all reader-writer lock activity[no].\n"
bart8f822af2009-06-08 18:20:42 +0000229" --trace-semaphore=yes|no Trace all semaphore activity [no].\n",
230DRD_(thread_get_segment_merge_interval)()
bartbedfd232009-03-26 19:07:15 +0000231);
sewardjaf44c822007-11-25 14:01:38 +0000232}
233
bart1335ecc2009-02-14 16:10:53 +0000234static void DRD_(print_debug_usage)(void)
bart31b983d2010-02-21 14:52:59 +0000235{
bartbedfd232009-03-26 19:07:15 +0000236 VG_(printf)(
bart130463a2008-04-01 17:03:33 +0000237" --drd-stats=yes|no Print statistics about DRD activity [no].\n"
238" --trace-clientobj=yes|no Trace all client object activity [no].\n"
239" --trace-csw=yes|no Trace all scheduler context switches [no].\n"
barte73b0aa2008-06-28 07:19:56 +0000240" --trace-conflict-set=yes|no Trace all conflict set updates [no].\n"
bart8f822af2009-06-08 18:20:42 +0000241" --trace-conflict-set-bm=yes|no Trace all conflict set bitmap\n"
242" updates [no]. Note: enabling this option\n"
243" will generate a lot of output !\n"
bart987781d2008-06-27 15:00:07 +0000244" --trace-segment=yes|no Trace segment actions [no].\n"
245" --trace-suppr=yes|no Trace all address suppression actions [no].\n"
bartbedfd232009-03-26 19:07:15 +0000246);
sewardjaf44c822007-11-25 14:01:38 +0000247}
248
249
250//
251// Implements the thread-related core callbacks.
252//
253
sewardjaf44c822007-11-25 14:01:38 +0000254static void drd_pre_mem_read(const CorePart part,
255 const ThreadId tid,
256 Char* const s,
257 const Addr a,
258 const SizeT size)
259{
bartbedfd232009-03-26 19:07:15 +0000260 if (size > 0)
261 {
262 DRD_(trace_load)(a, size);
263 }
sewardjaf44c822007-11-25 14:01:38 +0000264}
265
bart5e85d262008-03-01 10:49:37 +0000266static void drd_pre_mem_read_asciiz(const CorePart part,
267 const ThreadId tid,
268 Char* const s,
269 const Addr a)
270{
bartbedfd232009-03-26 19:07:15 +0000271 const char* p = (void*)a;
272 SizeT size = 0;
bart5e85d262008-03-01 10:49:37 +0000273
sewardj234e5582011-02-09 12:47:23 +0000274 // Don't segfault if the string starts in an obviously stupid
275 // place. Actually we should check the whole string, not just
276 // the start address, but that's too much trouble. At least
277 // checking the first byte is better than nothing. See #255009.
278 if (!VG_(am_is_valid_for_client) (a, 1, VKI_PROT_READ))
279 return;
280
bartbedfd232009-03-26 19:07:15 +0000281 /* Note: the expression '*p' reads client memory and may crash if the */
282 /* client provided an invalid pointer ! */
283 while (*p)
284 {
285 p++;
286 size++;
287 }
bartbedfd232009-03-26 19:07:15 +0000288 if (size > 0)
289 {
290 DRD_(trace_load)(a, size);
291 }
bart5e85d262008-03-01 10:49:37 +0000292}
293
sewardjaf44c822007-11-25 14:01:38 +0000294static void drd_post_mem_write(const CorePart part,
295 const ThreadId tid,
296 const Addr a,
297 const SizeT size)
298{
bartbedfd232009-03-26 19:07:15 +0000299 DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)());
300 if (size > 0)
301 {
302 DRD_(trace_store)(a, size);
303 }
sewardjaf44c822007-11-25 14:01:38 +0000304}
305
bart08865622008-06-06 14:31:36 +0000306static __inline__
bartf9427fd2010-08-29 09:19:07 +0000307void drd_start_using_mem(const Addr a1, const SizeT len,
308 const Bool is_stack_mem)
sewardjaf44c822007-11-25 14:01:38 +0000309{
bart639d0ad2011-03-12 14:26:01 +0000310 const Addr a2 = a1 + len;
311
312 tl_assert(a1 <= a2);
bart5e85d262008-03-01 10:49:37 +0000313
bartf9427fd2010-08-29 09:19:07 +0000314 if (!is_stack_mem && s_trace_alloc)
bartad994e82011-10-13 18:04:30 +0000315 DRD_(trace_msg)("Started using memory range 0x%lx + %ld%s",
bartb92ff0f2011-10-08 08:29:29 +0000316 a1, len, DRD_(running_thread_inside_pthread_create)()
317 ? " (inside pthread_create())" : "");
bartf9427fd2010-08-29 09:19:07 +0000318
bart7d5f5232011-03-13 09:08:10 +0000319 if (!is_stack_mem && DRD_(g_free_is_write))
bart639d0ad2011-03-12 14:26:01 +0000320 DRD_(thread_stop_using_mem)(a1, a2);
321
bartbedfd232009-03-26 19:07:15 +0000322 if (UNLIKELY(DRD_(any_address_is_traced)()))
323 {
bart42f32632011-12-13 11:12:05 +0000324 DRD_(trace_mem_access)(a1, len, eStart, 0, 0);
bartbedfd232009-03-26 19:07:15 +0000325 }
bart31b983d2010-02-21 14:52:59 +0000326
bartdd75cdf2009-07-24 08:20:10 +0000327 if (UNLIKELY(DRD_(running_thread_inside_pthread_create)()))
328 {
bart639d0ad2011-03-12 14:26:01 +0000329 DRD_(start_suppression)(a1, a2, "pthread_create()");
bartdd75cdf2009-07-24 08:20:10 +0000330 }
sewardjaf44c822007-11-25 14:01:38 +0000331}
332
sewardj7cf4e6b2008-05-01 20:24:26 +0000333static void drd_start_using_mem_w_ecu(const Addr a1,
334 const SizeT len,
335 UInt ec_uniq)
336{
bartf9427fd2010-08-29 09:19:07 +0000337 drd_start_using_mem(a1, len, False);
sewardj7cf4e6b2008-05-01 20:24:26 +0000338}
339
340static void drd_start_using_mem_w_tid(const Addr a1,
341 const SizeT len,
342 ThreadId tid)
343{
bartf9427fd2010-08-29 09:19:07 +0000344 drd_start_using_mem(a1, len, False);
sewardj7cf4e6b2008-05-01 20:24:26 +0000345}
346
bart0ffa4832008-04-05 12:57:01 +0000347static __inline__
348void drd_stop_using_mem(const Addr a1, const SizeT len,
349 const Bool is_stack_mem)
sewardjaf44c822007-11-25 14:01:38 +0000350{
bartbedfd232009-03-26 19:07:15 +0000351 const Addr a2 = a1 + len;
bart5e85d262008-03-01 10:49:37 +0000352
barta3003982010-09-08 16:29:17 +0000353 tl_assert(a1 <= a2);
bart5e85d262008-03-01 10:49:37 +0000354
bartbedfd232009-03-26 19:07:15 +0000355 if (UNLIKELY(DRD_(any_address_is_traced)()))
bart42f32632011-12-13 11:12:05 +0000356 DRD_(trace_mem_access)(a1, len, eEnd, 0, 0);
bartf9427fd2010-08-29 09:19:07 +0000357
358 if (!is_stack_mem && s_trace_alloc)
bartad994e82011-10-13 18:04:30 +0000359 DRD_(trace_msg)("Stopped using memory range 0x%lx + %ld",
bartb92ff0f2011-10-08 08:29:29 +0000360 a1, len);
bartf9427fd2010-08-29 09:19:07 +0000361
bart07595032010-08-29 09:51:06 +0000362 if (!is_stack_mem || DRD_(get_check_stack_accesses)())
bartbedfd232009-03-26 19:07:15 +0000363 {
bart7d5f5232011-03-13 09:08:10 +0000364 if (is_stack_mem || !DRD_(g_free_is_write))
bart639d0ad2011-03-12 14:26:01 +0000365 DRD_(thread_stop_using_mem)(a1, a2);
bart7d5f5232011-03-13 09:08:10 +0000366 else if (DRD_(g_free_is_write))
bart639d0ad2011-03-12 14:26:01 +0000367 DRD_(trace_store)(a1, len);
bartbedfd232009-03-26 19:07:15 +0000368 DRD_(clientobj_stop_using_mem)(a1, a2);
369 DRD_(suppression_stop_using_mem)(a1, a2);
370 }
bart0ffa4832008-04-05 12:57:01 +0000371}
372
373static __inline__
374void drd_stop_using_nonstack_mem(const Addr a1, const SizeT len)
375{
bartbedfd232009-03-26 19:07:15 +0000376 drd_stop_using_mem(a1, len, False);
sewardjaf44c822007-11-25 14:01:38 +0000377}
378
bart1335ecc2009-02-14 16:10:53 +0000379/**
bartfdaa0182009-03-10 09:25:32 +0000380 * Discard all information DRD has about memory accesses and client objects
381 * in the specified address range.
382 */
383void DRD_(clean_memory)(const Addr a1, const SizeT len)
384{
bartbedfd232009-03-26 19:07:15 +0000385 const Bool is_stack_memory = DRD_(thread_address_on_any_stack)(a1);
386 drd_stop_using_mem(a1, len, is_stack_memory);
bartf9427fd2010-08-29 09:19:07 +0000387 drd_start_using_mem(a1, len, is_stack_memory);
bartfdaa0182009-03-10 09:25:32 +0000388}
389
390/**
bart1335ecc2009-02-14 16:10:53 +0000391 * Suppress data race reports on all addresses contained in .plt and
392 * .got.plt sections inside the address range [ a, a + len [. The data in
393 * these sections is modified by _dl_relocate_object() every time a function
394 * in a shared library is called for the first time. Since the first call
395 * to a function in a shared library can happen from a multithreaded context,
396 * such calls can cause conflicting accesses. See also Ulrich Drepper's
397 * paper "How to Write Shared Libraries" for more information about relocation
398 * (http://people.redhat.com/drepper/dsohowto.pdf).
bartcb2d0072008-05-31 07:55:51 +0000399 */
bart1335ecc2009-02-14 16:10:53 +0000400static void DRD_(suppress_relocation_conflicts)(const Addr a, const SizeT len)
bartcb2d0072008-05-31 07:55:51 +0000401{
bartbedfd232009-03-26 19:07:15 +0000402 const DebugInfo* di;
bartcb2d0072008-05-31 07:55:51 +0000403
404#if 0
bartbedfd232009-03-26 19:07:15 +0000405 VG_(printf)("Evaluating range @ 0x%lx size %ld\n", a, len);
bartcb2d0072008-05-31 07:55:51 +0000406#endif
407
sewardje3f1e592009-07-31 09:41:29 +0000408 for (di = VG_(next_DebugInfo)(0); di; di = VG_(next_DebugInfo)(di))
bartbedfd232009-03-26 19:07:15 +0000409 {
410 Addr avma;
411 SizeT size;
bartcb2d0072008-05-31 07:55:51 +0000412
sewardje3f1e592009-07-31 09:41:29 +0000413 avma = VG_(DebugInfo_get_plt_avma)(di);
414 size = VG_(DebugInfo_get_plt_size)(di);
bartbedfd232009-03-26 19:07:15 +0000415 tl_assert((avma && size) || (avma == 0 && size == 0));
416 if (size > 0)
417 {
bartcb2d0072008-05-31 07:55:51 +0000418#if 0
bartbedfd232009-03-26 19:07:15 +0000419 VG_(printf)("Suppressing .plt @ 0x%lx size %ld\n", avma, size);
bartcb2d0072008-05-31 07:55:51 +0000420#endif
sewardje3f1e592009-07-31 09:41:29 +0000421 tl_assert(VG_(DebugInfo_sect_kind)(NULL, 0, avma) == Vg_SectPLT);
bartbedfd232009-03-26 19:07:15 +0000422 DRD_(start_suppression)(avma, avma + size, ".plt");
423 }
bartcb2d0072008-05-31 07:55:51 +0000424
sewardje3f1e592009-07-31 09:41:29 +0000425 avma = VG_(DebugInfo_get_gotplt_avma)(di);
426 size = VG_(DebugInfo_get_gotplt_size)(di);
bartbedfd232009-03-26 19:07:15 +0000427 tl_assert((avma && size) || (avma == 0 && size == 0));
428 if (size > 0)
429 {
bartcb2d0072008-05-31 07:55:51 +0000430#if 0
bartbedfd232009-03-26 19:07:15 +0000431 VG_(printf)("Suppressing .got.plt @ 0x%lx size %ld\n", avma, size);
bartcb2d0072008-05-31 07:55:51 +0000432#endif
sewardje3f1e592009-07-31 09:41:29 +0000433 tl_assert(VG_(DebugInfo_sect_kind)(NULL, 0, avma) == Vg_SectGOTPLT);
bartbedfd232009-03-26 19:07:15 +0000434 DRD_(start_suppression)(avma, avma + size, ".gotplt");
435 }
436 }
bartcb2d0072008-05-31 07:55:51 +0000437}
438
bart5e85d262008-03-01 10:49:37 +0000439static
440void drd_start_using_mem_w_perms(const Addr a, const SizeT len,
sewardj9c606bd2008-09-18 18:12:50 +0000441 const Bool rr, const Bool ww, const Bool xx,
442 ULong di_handle)
bart5e85d262008-03-01 10:49:37 +0000443{
bartbedfd232009-03-26 19:07:15 +0000444 DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)());
bartd5765912008-03-16 08:40:55 +0000445
bartf9427fd2010-08-29 09:19:07 +0000446 drd_start_using_mem(a, len, False);
bartcb2d0072008-05-31 07:55:51 +0000447
bartbedfd232009-03-26 19:07:15 +0000448 DRD_(suppress_relocation_conflicts)(a, len);
bart5e85d262008-03-01 10:49:37 +0000449}
450
sewardjaf44c822007-11-25 14:01:38 +0000451/* Called by the core when the stack of a thread grows, to indicate that */
452/* the addresses in range [ a, a + len [ may now be used by the client. */
453/* Assumption: stacks grow downward. */
bart08865622008-06-06 14:31:36 +0000454static __inline__
455void drd_start_using_mem_stack(const Addr a, const SizeT len)
sewardjaf44c822007-11-25 14:01:38 +0000456{
bartbedfd232009-03-26 19:07:15 +0000457 DRD_(thread_set_stack_min)(DRD_(thread_get_running_tid)(),
458 a - VG_STACK_REDZONE_SZB);
bart31b983d2010-02-21 14:52:59 +0000459 drd_start_using_mem(a - VG_STACK_REDZONE_SZB,
bartf9427fd2010-08-29 09:19:07 +0000460 len + VG_STACK_REDZONE_SZB,
461 True);
sewardjaf44c822007-11-25 14:01:38 +0000462}
463
464/* Called by the core when the stack of a thread shrinks, to indicate that */
465/* the addresses [ a, a + len [ are no longer accessible for the client. */
466/* Assumption: stacks grow downward. */
bart08865622008-06-06 14:31:36 +0000467static __inline__
468void drd_stop_using_mem_stack(const Addr a, const SizeT len)
sewardjaf44c822007-11-25 14:01:38 +0000469{
bartbedfd232009-03-26 19:07:15 +0000470 DRD_(thread_set_stack_min)(DRD_(thread_get_running_tid)(),
471 a + len - VG_STACK_REDZONE_SZB);
472 drd_stop_using_mem(a - VG_STACK_REDZONE_SZB, len + VG_STACK_REDZONE_SZB,
473 True);
sewardjaf44c822007-11-25 14:01:38 +0000474}
475
bart68a8afa2010-09-02 14:50:41 +0000476static
477Bool on_alt_stack(const Addr a)
478{
479 ThreadId vg_tid;
480 Addr alt_min;
481 SizeT alt_size;
482
483 vg_tid = VG_(get_running_tid)();
484 alt_min = VG_(thread_get_altstack_min)(vg_tid);
485 alt_size = VG_(thread_get_altstack_size)(vg_tid);
486 return (SizeT)(a - alt_min) < alt_size;
487}
488
489static
490void drd_start_using_mem_alt_stack(const Addr a, const SizeT len)
491{
492 if (!on_alt_stack(a))
493 drd_start_using_mem_stack(a, len);
494}
495
496static
497void drd_stop_using_mem_alt_stack(const Addr a, const SizeT len)
498{
499 if (!on_alt_stack(a))
500 drd_stop_using_mem_stack(a, len);
501}
502
503/**
504 * Callback function invoked by the Valgrind core before a signal is delivered.
505 */
506static
507void drd_pre_deliver_signal(const ThreadId vg_tid, const Int sigNo,
508 const Bool alt_stack)
509{
510 DrdThreadId drd_tid;
511
512 drd_tid = DRD_(VgThreadIdToDrdThreadId)(vg_tid);
513 DRD_(thread_set_on_alt_stack)(drd_tid, alt_stack);
514 if (alt_stack)
515 {
516 /*
517 * As soon a signal handler has been invoked on the alternate stack,
518 * switch to stack memory handling functions that can handle the
519 * alternate stack.
520 */
521 VG_(track_new_mem_stack)(drd_start_using_mem_alt_stack);
522 VG_(track_die_mem_stack)(drd_stop_using_mem_alt_stack);
523 }
524}
525
526/**
527 * Callback function invoked by the Valgrind core after a signal is delivered,
528 * at least if the signal handler did not longjmp().
529 */
530static
531void drd_post_deliver_signal(const ThreadId vg_tid, const Int sigNo)
532{
533 DrdThreadId drd_tid;
534
535 drd_tid = DRD_(VgThreadIdToDrdThreadId)(vg_tid);
536 DRD_(thread_set_on_alt_stack)(drd_tid, False);
537 if (DRD_(thread_get_threads_on_alt_stack)() == 0)
538 {
539 VG_(track_new_mem_stack)(drd_start_using_mem_stack);
540 VG_(track_die_mem_stack)(drd_stop_using_mem_stack);
541 }
542}
543
bartbedfd232009-03-26 19:07:15 +0000544/**
545 * Callback function called by the Valgrind core before a stack area is
546 * being used by a signal handler.
547 *
548 * @param[in] a Start of address range.
549 * @param[in] len Address range length.
550 * @param[in] tid Valgrind thread ID for whom the signal frame is being
551 * constructed.
552 */
553static void drd_start_using_mem_stack_signal(const Addr a, const SizeT len,
554 ThreadId tid)
sewardjaf44c822007-11-25 14:01:38 +0000555{
bartbedfd232009-03-26 19:07:15 +0000556 DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)());
bartf9427fd2010-08-29 09:19:07 +0000557 drd_start_using_mem(a, len, True);
sewardjaf44c822007-11-25 14:01:38 +0000558}
559
bart5e85d262008-03-01 10:49:37 +0000560static void drd_stop_using_mem_stack_signal(Addr a, SizeT len)
sewardjaf44c822007-11-25 14:01:38 +0000561{
bartbedfd232009-03-26 19:07:15 +0000562 drd_stop_using_mem(a, len, True);
sewardjaf44c822007-11-25 14:01:38 +0000563}
564
565static
566void drd_pre_thread_create(const ThreadId creator, const ThreadId created)
567{
bartbedfd232009-03-26 19:07:15 +0000568 const DrdThreadId drd_creator = DRD_(VgThreadIdToDrdThreadId)(creator);
569 tl_assert(created != VG_INVALID_THREADID);
570 DRD_(thread_pre_create)(drd_creator, created);
571 if (DRD_(IsValidDrdThreadId)(drd_creator))
572 {
573 DRD_(thread_new_segment)(drd_creator);
574 }
575 if (DRD_(thread_get_trace_fork_join)())
576 {
bartad994e82011-10-13 18:04:30 +0000577 DRD_(trace_msg)("drd_pre_thread_create creator = %d, created = %d",
barte7086002011-10-11 19:08:39 +0000578 drd_creator, created);
bartbedfd232009-03-26 19:07:15 +0000579 }
sewardjaf44c822007-11-25 14:01:38 +0000580}
581
582/* Called by Valgrind's core before any loads or stores are performed on */
583/* the context of thread "created". At startup, this function is called */
584/* with arguments (0,1). */
585static
bart0ffa4832008-04-05 12:57:01 +0000586void drd_post_thread_create(const ThreadId vg_created)
sewardjaf44c822007-11-25 14:01:38 +0000587{
bartbedfd232009-03-26 19:07:15 +0000588 DrdThreadId drd_created;
bart0ffa4832008-04-05 12:57:01 +0000589
bartbedfd232009-03-26 19:07:15 +0000590 tl_assert(vg_created != VG_INVALID_THREADID);
bart0ffa4832008-04-05 12:57:01 +0000591
bartbedfd232009-03-26 19:07:15 +0000592 drd_created = DRD_(thread_post_create)(vg_created);
593 if (DRD_(thread_get_trace_fork_join)())
594 {
bartad994e82011-10-13 18:04:30 +0000595 DRD_(trace_msg)("drd_post_thread_create created = %d", drd_created);
bartbedfd232009-03-26 19:07:15 +0000596 }
597 if (! DRD_(get_check_stack_accesses)())
598 {
599 DRD_(start_suppression)(DRD_(thread_get_stack_max)(drd_created)
600 - DRD_(thread_get_stack_size)(drd_created),
601 DRD_(thread_get_stack_max)(drd_created),
602 "stack");
603 }
sewardjaf44c822007-11-25 14:01:38 +0000604}
605
sewardjaf44c822007-11-25 14:01:38 +0000606/* Called after a thread has performed its last memory access. */
bartd43f8d32008-03-16 17:29:20 +0000607static void drd_thread_finished(ThreadId vg_tid)
sewardjaf44c822007-11-25 14:01:38 +0000608{
bartbedfd232009-03-26 19:07:15 +0000609 DrdThreadId drd_tid;
sewardj85642922008-01-14 11:54:56 +0000610
bartbedfd232009-03-26 19:07:15 +0000611 tl_assert(VG_(get_running_tid)() == vg_tid);
sewardj85642922008-01-14 11:54:56 +0000612
bartbedfd232009-03-26 19:07:15 +0000613 drd_tid = DRD_(VgThreadIdToDrdThreadId)(vg_tid);
614 if (DRD_(thread_get_trace_fork_join)())
615 {
bartad994e82011-10-13 18:04:30 +0000616 DRD_(trace_msg)("drd_thread_finished tid = %d%s", drd_tid,
barte7086002011-10-11 19:08:39 +0000617 DRD_(thread_get_joinable)(drd_tid)
618 ? "" : " (which is a detached thread)");
bartbedfd232009-03-26 19:07:15 +0000619 }
barte7086002011-10-11 19:08:39 +0000620 if (s_show_stack_usage && !VG_(clo_xml)) {
bartbedfd232009-03-26 19:07:15 +0000621 const SizeT stack_size = DRD_(thread_get_stack_size)(drd_tid);
622 const SizeT used_stack
623 = (DRD_(thread_get_stack_max)(drd_tid)
624 - DRD_(thread_get_stack_min_min)(drd_tid));
625 VG_(message)(Vg_UserMsg,
bart63c92ea2009-07-19 17:53:56 +0000626 "thread %d%s finished and used %ld bytes out of %ld"
sewardj1e29ebc2009-07-15 14:49:17 +0000627 " on its stack. Margin: %ld bytes.\n",
bartbedfd232009-03-26 19:07:15 +0000628 drd_tid,
629 DRD_(thread_get_joinable)(drd_tid)
barte7086002011-10-11 19:08:39 +0000630 ? "" : " (which is a detached thread)",
631 used_stack, stack_size, stack_size - used_stack);
sewardjaf44c822007-11-25 14:01:38 +0000632
bartbedfd232009-03-26 19:07:15 +0000633 }
634 drd_stop_using_mem(DRD_(thread_get_stack_min)(drd_tid),
635 DRD_(thread_get_stack_max)(drd_tid)
636 - DRD_(thread_get_stack_min)(drd_tid),
637 True);
bartd45d9952009-05-31 18:53:54 +0000638 DRD_(thread_set_record_loads)(drd_tid, False);
639 DRD_(thread_set_record_stores)(drd_tid, False);
bartbedfd232009-03-26 19:07:15 +0000640 DRD_(thread_finished)(drd_tid);
sewardjaf44c822007-11-25 14:01:38 +0000641}
642
bart5c7e6b62011-02-03 17:47:50 +0000643/*
644 * Called immediately after fork for the child process only. 'tid' is the
645 * only surviving thread in the child process. Cleans up thread state.
646 * See also http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_atfork.html for a detailed discussion of using fork() in combination with mutexes.
647 */
648static
649void drd__atfork_child(ThreadId tid)
650{
651 DRD_(drd_thread_atfork_child)(tid);
652}
653
654
sewardjaf44c822007-11-25 14:01:38 +0000655//
656// Implementation of the tool interface.
657//
658
bart1335ecc2009-02-14 16:10:53 +0000659static void DRD_(post_clo_init)(void)
sewardjdcbb8d32007-11-26 21:34:30 +0000660{
bart0c6bf352009-07-25 14:03:53 +0000661#if defined(VGO_linux) || defined(VGO_darwin)
bartc6ef4af2009-07-23 10:10:30 +0000662 /* fine */
bartc6ef4af2009-07-23 10:10:30 +0000663#else
664 VG_(printf)("\nWARNING: DRD has not yet been tested on this operating system.\n\n");
sewardjdcbb8d32007-11-26 21:34:30 +0000665# endif
bart95761b52008-03-29 08:34:03 +0000666
bart75c1cba2010-08-29 07:20:30 +0000667 if (s_var_info)
bartbedfd232009-03-26 19:07:15 +0000668 {
669 VG_(needs_var_info)();
670 }
sewardjdcbb8d32007-11-26 21:34:30 +0000671}
sewardjaf44c822007-11-25 14:01:38 +0000672
sewardjaf44c822007-11-25 14:01:38 +0000673static void drd_start_client_code(const ThreadId tid, const ULong bbs_done)
674{
bartbedfd232009-03-26 19:07:15 +0000675 tl_assert(tid == VG_(get_running_tid)());
676 DRD_(thread_set_vg_running_tid)(tid);
sewardjaf44c822007-11-25 14:01:38 +0000677}
678
bart1335ecc2009-02-14 16:10:53 +0000679static void DRD_(fini)(Int exitcode)
sewardjaf44c822007-11-25 14:01:38 +0000680{
bartbedfd232009-03-26 19:07:15 +0000681 // thread_print_all();
sewardj2d9e8742009-08-07 15:46:56 +0000682 if (VG_(clo_verbosity) == 1 && !VG_(clo_xml)) {
barte7086002011-10-11 19:08:39 +0000683 VG_(message)(Vg_UserMsg, "For counts of detected and suppressed errors, "
sewardj2d9e8742009-08-07 15:46:56 +0000684 "rerun with: -v\n");
685 }
686
barte7086002011-10-11 19:08:39 +0000687 if ((VG_(clo_stats) || s_print_stats) && !VG_(clo_xml))
bartbedfd232009-03-26 19:07:15 +0000688 {
barte5214662009-06-21 11:51:23 +0000689 ULong pu = DRD_(thread_get_update_conflict_set_count)();
690 ULong pu_seg_cr = DRD_(thread_get_update_conflict_set_new_sg_count)();
691 ULong pu_mtx_cv = DRD_(thread_get_update_conflict_set_sync_count)();
692 ULong pu_join = DRD_(thread_get_update_conflict_set_join_count)();
693
bartbedfd232009-03-26 19:07:15 +0000694 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000695 " thread: %lld context switches.\n",
bart54803fe2009-06-21 09:26:27 +0000696 DRD_(thread_get_context_switch_count)());
bartbedfd232009-03-26 19:07:15 +0000697 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000698 "confl set: %lld full updates and %lld partial updates;\n",
barte7086002011-10-11 19:08:39 +0000699 DRD_(thread_get_compute_conflict_set_count)(),
700 pu);
bartbedfd232009-03-26 19:07:15 +0000701 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000702 " %lld partial updates during segment creation,\n",
barte7086002011-10-11 19:08:39 +0000703 pu_seg_cr);
barte5214662009-06-21 11:51:23 +0000704 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000705 " %lld because of mutex/sema/cond.var. operations,\n",
barte7086002011-10-11 19:08:39 +0000706 pu_mtx_cv);
barte5214662009-06-21 11:51:23 +0000707 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000708 " %lld because of barrier/rwlock operations and\n",
barte5214662009-06-21 11:51:23 +0000709 pu - pu_seg_cr - pu_mtx_cv - pu_join);
710 VG_(message)(Vg_UserMsg,
711 " %lld partial updates because of thread join"
barte7086002011-10-11 19:08:39 +0000712 " operations.\n",
713 pu_join);
barte5214662009-06-21 11:51:23 +0000714 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000715 " segments: created %lld segments, max %lld alive,\n",
bart9dedafe2009-06-21 18:09:02 +0000716 DRD_(sg_get_segments_created_count)(),
717 DRD_(sg_get_max_segments_alive_count)());
bartbedfd232009-03-26 19:07:15 +0000718 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000719 " %lld discard points and %lld merges.\n",
bart9dedafe2009-06-21 18:09:02 +0000720 DRD_(thread_get_discard_ordered_segments_count)(),
bart1a3b0b32009-05-03 17:07:34 +0000721 DRD_(sg_get_segment_merge_count)());
722 VG_(message)(Vg_UserMsg,
bart54803fe2009-06-21 09:26:27 +0000723 "segmnt cr: %lld mutex, %lld rwlock, %lld semaphore and"
sewardj1e29ebc2009-07-15 14:49:17 +0000724 " %lld barrier.\n",
bartbedfd232009-03-26 19:07:15 +0000725 DRD_(get_mutex_segment_creation_count)(),
726 DRD_(get_rwlock_segment_creation_count)(),
727 DRD_(get_semaphore_segment_creation_count)(),
728 DRD_(get_barrier_segment_creation_count)());
729 VG_(message)(Vg_UserMsg,
bart9dedafe2009-06-21 18:09:02 +0000730 " bitmaps: %lld level one"
sewardj1e29ebc2009-07-15 14:49:17 +0000731 " and %lld level two bitmaps were allocated.\n",
bartbedfd232009-03-26 19:07:15 +0000732 DRD_(bm_get_bitmap_creation_count)(),
bartbedfd232009-03-26 19:07:15 +0000733 DRD_(bm_get_bitmap2_creation_count)());
734 VG_(message)(Vg_UserMsg,
sewardj1e29ebc2009-07-15 14:49:17 +0000735 " mutex: %lld non-recursive lock/unlock events.\n",
bartbedfd232009-03-26 19:07:15 +0000736 DRD_(get_mutex_lock_count)());
737 DRD_(print_malloc_stats)();
738 }
sewardjaf44c822007-11-25 14:01:38 +0000739}
740
sewardjaf44c822007-11-25 14:01:38 +0000741static
742void drd_pre_clo_init(void)
743{
njnf76d27a2009-05-28 01:53:07 +0000744 // Basic tool stuff.
bartbedfd232009-03-26 19:07:15 +0000745 VG_(details_name) ("drd");
746 VG_(details_version) (NULL);
747 VG_(details_description) ("a thread error detector");
bart922304f2011-03-13 12:02:44 +0000748 VG_(details_copyright_author)("Copyright (C) 2006-2011, and GNU GPL'd,"
bartbedfd232009-03-26 19:07:15 +0000749 " by Bart Van Assche.");
750 VG_(details_bug_reports_to) (VG_BUGS_TO);
sewardjaf44c822007-11-25 14:01:38 +0000751
bartbedfd232009-03-26 19:07:15 +0000752 VG_(basic_tool_funcs) (DRD_(post_clo_init),
753 DRD_(instrument),
754 DRD_(fini));
sewardjaf44c822007-11-25 14:01:38 +0000755
bartbedfd232009-03-26 19:07:15 +0000756 // Command line stuff.
757 VG_(needs_command_line_options)(DRD_(process_cmd_line_option),
758 DRD_(print_usage),
759 DRD_(print_debug_usage));
barte7086002011-10-11 19:08:39 +0000760 VG_(needs_xml_output) ();
sewardjaf44c822007-11-25 14:01:38 +0000761
bartbedfd232009-03-26 19:07:15 +0000762 // Error handling.
763 DRD_(register_error_handlers)();
sewardjaf44c822007-11-25 14:01:38 +0000764
bartbedfd232009-03-26 19:07:15 +0000765 // Core event tracking.
766 VG_(track_pre_mem_read) (drd_pre_mem_read);
767 VG_(track_pre_mem_read_asciiz) (drd_pre_mem_read_asciiz);
768 VG_(track_post_mem_write) (drd_post_mem_write);
769 VG_(track_new_mem_brk) (drd_start_using_mem_w_tid);
770 VG_(track_new_mem_mmap) (drd_start_using_mem_w_perms);
771 VG_(track_new_mem_stack) (drd_start_using_mem_stack);
772 VG_(track_new_mem_stack_signal) (drd_start_using_mem_stack_signal);
773 VG_(track_new_mem_startup) (drd_start_using_mem_w_perms);
774 VG_(track_die_mem_brk) (drd_stop_using_nonstack_mem);
775 VG_(track_die_mem_munmap) (drd_stop_using_nonstack_mem);
776 VG_(track_die_mem_stack) (drd_stop_using_mem_stack);
777 VG_(track_die_mem_stack_signal) (drd_stop_using_mem_stack_signal);
bart68a8afa2010-09-02 14:50:41 +0000778 VG_(track_pre_deliver_signal) (drd_pre_deliver_signal);
779 VG_(track_post_deliver_signal) (drd_post_deliver_signal);
bartbedfd232009-03-26 19:07:15 +0000780 VG_(track_start_client_code) (drd_start_client_code);
781 VG_(track_pre_thread_ll_create) (drd_pre_thread_create);
782 VG_(track_pre_thread_first_insn)(drd_post_thread_create);
783 VG_(track_pre_thread_ll_exit) (drd_thread_finished);
bart5c7e6b62011-02-03 17:47:50 +0000784 VG_(atfork) (NULL/*pre*/, NULL/*parent*/,
785 drd__atfork_child/*child*/);
sewardjaf44c822007-11-25 14:01:38 +0000786
bartbedfd232009-03-26 19:07:15 +0000787 // Other stuff.
788 DRD_(register_malloc_wrappers)(drd_start_using_mem_w_ecu,
789 drd_stop_using_nonstack_mem);
sewardjaf44c822007-11-25 14:01:38 +0000790
bartbedfd232009-03-26 19:07:15 +0000791 DRD_(clientreq_init)();
sewardjaf44c822007-11-25 14:01:38 +0000792
bartbedfd232009-03-26 19:07:15 +0000793 DRD_(suppression_init)();
bart4bb53d82008-02-28 19:06:34 +0000794
bartbedfd232009-03-26 19:07:15 +0000795 DRD_(clientobj_init)();
barte5e0efa2009-06-24 18:35:02 +0000796
797 {
798 Char* const smi = VG_(getenv)("DRD_SEGMENT_MERGING_INTERVAL");
799 if (smi)
800 DRD_(thread_set_segment_merge_interval)(VG_(strtoll10)(smi, NULL));
801 }
sewardjaf44c822007-11-25 14:01:38 +0000802}
803
804
805VG_DETERMINE_INTERFACE_VERSION(drd_pre_clo_init)