From: Bart Van Assche Date: Sun, 29 Aug 2010 09:19:07 +0000 (+0000) Subject: Added command-line option --trace-alloc and disabled --free-is-write by default. X-Git-Tag: svn/VALGRIND_3_6_0~156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1d51679d979bd861fe0a5e1e5749c7f0bb739bb;p=thirdparty%2Fvalgrind.git Added command-line option --trace-alloc and disabled --free-is-write by default. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11301 --- diff --git a/drd/docs/drd-manual.xml b/drd/docs/drd-manual.xml index 10907d29a1..44812f1013 100644 --- a/drd/docs/drd-manual.xml +++ b/drd/docs/drd-manual.xml @@ -364,12 +364,12 @@ behavior of the DRD tool itself: - Whether to report reading freed memory as a race. Helps to detect + Whether to report accessing freed memory as a race. Helps to detect memory accesses that occur after memory has been freed but might cause DRD to run slightly slower. @@ -491,6 +491,17 @@ client program: + + + + + + + Trace all memory allocations and deallocations. May produce a huge + amount of output. + + + diff --git a/drd/drd_load_store.c b/drd/drd_load_store.c index 2b6d6f5026..be6667175a 100644 --- a/drd/drd_load_store.c +++ b/drd/drd_load_store.c @@ -114,12 +114,12 @@ void DRD_(trace_mem_access)(const Addr addr, const SizeT size, } } -static VG_REGPARM(2) void drd_trace_mem_load(const Addr addr, const SizeT size) +VG_REGPARM(2) void DRD_(trace_mem_load)(const Addr addr, const SizeT size) { return DRD_(trace_mem_access)(addr, size, eLoad); } -static VG_REGPARM(2) void drd_trace_mem_store(const Addr addr,const SizeT size) +VG_REGPARM(2) void DRD_(trace_mem_store)(const Addr addr,const SizeT size) { return DRD_(trace_mem_access)(addr, size, eStore); } @@ -324,7 +324,7 @@ static void instrument_load(IRSB* const bb, unsafeIRDirty_0_N(/*regparms*/2, "drd_trace_load", VG_(fnptr_to_fnentry) - (drd_trace_mem_load), + (DRD_(trace_mem_load)), mkIRExprVec_2(addr_expr, mkIRExpr_HWord(size))))); } @@ -389,7 +389,7 @@ static void instrument_store(IRSB* const bb, unsafeIRDirty_0_N(/*regparms*/2, "drd_trace_store", VG_(fnptr_to_fnentry) - (drd_trace_mem_store), + (DRD_(trace_mem_store)), mkIRExprVec_2(addr_expr, mkIRExpr_HWord(size))))); } diff --git a/drd/drd_load_store.h b/drd/drd_load_store.h index be6df7b935..f80e31b8cb 100644 --- a/drd/drd_load_store.h +++ b/drd/drd_load_store.h @@ -40,6 +40,8 @@ Bool DRD_(get_check_stack_accesses)(void); void DRD_(set_check_stack_accesses)(const Bool c); Bool DRD_(get_first_race_only)(void); void DRD_(set_first_race_only)(const Bool fro); +VG_REGPARM(2) void DRD_(trace_mem_load)(const Addr addr, const SizeT size); +VG_REGPARM(2) void DRD_(trace_mem_store)(const Addr addr,const SizeT size); IRSB* DRD_(instrument)(VgCallbackClosure* const closure, IRSB* const bb_in, VexGuestLayout* const layout, diff --git a/drd/drd_main.c b/drd/drd_main.c index b8a6f54edb..8b2024e4d2 100644 --- a/drd/drd_main.c +++ b/drd/drd_main.c @@ -59,6 +59,7 @@ static Bool s_free_is_write = False; static Bool s_print_stats = False; static Bool s_var_info = False; static Bool s_show_stack_usage = False; +static Bool s_trace_alloc = False; /** @@ -99,6 +100,7 @@ static Bool DRD_(process_cmd_line_option)(Char* arg) {} else if VG_BOOL_CLO(arg, "--show-confl-seg", show_confl_seg) {} else if VG_BOOL_CLO(arg, "--show-stack-usage", s_show_stack_usage) {} + else if VG_BOOL_CLO(arg, "--trace-alloc", s_trace_alloc) {} else if VG_BOOL_CLO(arg, "--trace-barrier", trace_barrier) {} else if VG_BOOL_CLO(arg, "--trace-clientobj", trace_clientobj) {} else if VG_BOOL_CLO(arg, "--trace-cond", trace_cond) {} @@ -186,7 +188,7 @@ static void DRD_(print_usage)(void) " --first-race-only=yes|no Only report the first data race that occurs on\n" " a memory location instead of all races [no].\n" " --free-is-write=yes|no Whether to report races between freeing memory\n" -" and subsequent accesses of that memory[yes].\n" +" and subsequent accesses of that memory[no].\n" " --report-signal-unlocked=yes|no Whether to report calls to\n" " pthread_cond_signal() where the mutex associated\n" " with the signal via pthread_cond_wait() is not\n" @@ -206,6 +208,7 @@ static void DRD_(print_usage)(void) " drd options for monitoring process behavior:\n" " --trace-addr=
Trace all load and store activity for the.\n" " specified address [off].\n" +" --trace-alloc=yes|no Trace all memory allocations and deallocations\n"" [no].\n" " --trace-barrier=yes|no Trace all barrier activity [no].\n" " --trace-cond=yes|no Trace all condition variable activity [no].\n" " --trace-fork-join=yes|no Trace all thread fork/join activity [no].\n" @@ -282,10 +285,16 @@ static void drd_post_mem_write(const CorePart part, } static __inline__ -void drd_start_using_mem(const Addr a1, const SizeT len) +void drd_start_using_mem(const Addr a1, const SizeT len, + const Bool is_stack_mem) { tl_assert(a1 < a1 + len); + if (!is_stack_mem && s_trace_alloc) + VG_(message)(Vg_UserMsg, "Started using memory range 0x%lx + %ld%s\n", + a1, len, DRD_(running_thread_inside_pthread_create)() + ? " (inside pthread_create())" : ""); + if (UNLIKELY(DRD_(any_address_is_traced)())) { DRD_(trace_mem_access)(a1, len, eStart); @@ -301,14 +310,14 @@ static void drd_start_using_mem_w_ecu(const Addr a1, const SizeT len, UInt ec_uniq) { - drd_start_using_mem(a1, len); + drd_start_using_mem(a1, len, False); } static void drd_start_using_mem_w_tid(const Addr a1, const SizeT len, ThreadId tid) { - drd_start_using_mem(a1, len); + drd_start_using_mem(a1, len, False); } static __inline__ @@ -323,15 +332,20 @@ void drd_stop_using_mem(const Addr a1, const SizeT len, { DRD_(trace_mem_access)(a1, len, eEnd); } + + if (!is_stack_mem && s_trace_alloc) + VG_(message)(Vg_UserMsg, "Stopped using memory range 0x%lx + %ld\n", + a1, len); + if (! is_stack_mem || DRD_(get_check_stack_accesses)()) { - DRD_(thread_stop_using_mem)(a1, a2); + DRD_(thread_stop_using_mem)(a1, a2, !is_stack_mem && s_free_is_write); DRD_(clientobj_stop_using_mem)(a1, a2); DRD_(suppression_stop_using_mem)(a1, a2); } if (! is_stack_mem && s_free_is_write) { - DRD_(trace_store)(a1, len); + DRD_(trace_mem_store)(a1, len); } } @@ -349,7 +363,7 @@ void DRD_(clean_memory)(const Addr a1, const SizeT len) { const Bool is_stack_memory = DRD_(thread_address_on_any_stack)(a1); drd_stop_using_mem(a1, len, is_stack_memory); - drd_start_using_mem(a1, len); + drd_start_using_mem(a1, len, is_stack_memory); } /** @@ -408,7 +422,7 @@ void drd_start_using_mem_w_perms(const Addr a, const SizeT len, { DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)()); - drd_start_using_mem(a, len); + drd_start_using_mem(a, len, False); DRD_(suppress_relocation_conflicts)(a, len); } @@ -422,7 +436,8 @@ void drd_start_using_mem_stack(const Addr a, const SizeT len) DRD_(thread_set_stack_min)(DRD_(thread_get_running_tid)(), a - VG_STACK_REDZONE_SZB); drd_start_using_mem(a - VG_STACK_REDZONE_SZB, - len + VG_STACK_REDZONE_SZB); + len + VG_STACK_REDZONE_SZB, + True); } /* Called by the core when the stack of a thread shrinks, to indicate that */ @@ -450,7 +465,7 @@ static void drd_start_using_mem_stack_signal(const Addr a, const SizeT len, ThreadId tid) { DRD_(thread_set_vg_running_tid)(VG_(get_running_tid)()); - drd_start_using_mem(a, len); + drd_start_using_mem(a, len, True); } static void drd_stop_using_mem_stack_signal(Addr a, SizeT len) diff --git a/drd/drd_thread.c b/drd/drd_thread.c index a12553a428..f9edc6a06a 100644 --- a/drd/drd_thread.c +++ b/drd/drd_thread.c @@ -1104,7 +1104,8 @@ void DRD_(thread_new_segment_and_combine_vc)(DrdThreadId tid, const Segment* sg) * [ a1, a2 [, e.g. because of a call to free() or a stack pointer * increase. */ -void DRD_(thread_stop_using_mem)(const Addr a1, const Addr a2) +void DRD_(thread_stop_using_mem)(const Addr a1, const Addr a2, + const Bool dont_clear_access) { DrdThreadId other_user; unsigned i; @@ -1119,13 +1120,18 @@ void DRD_(thread_stop_using_mem)(const Addr a1, const Addr a2) if (other_user == DRD_INVALID_THREADID && i != DRD_(g_drd_running_tid)) { - if (UNLIKELY(DRD_(bm_test_and_clear)(DRD_(sg_bm)(p), a1, a2))) + if (UNLIKELY((!dont_clear_access + && DRD_(bm_test_and_clear)(DRD_(sg_bm)(p), a1, a2)) + || (dont_clear_access + && DRD_(bm_has_any_access)(DRD_(sg_bm)(p), a1, a2)) + )) { other_user = i; } continue; } - DRD_(bm_clear)(DRD_(sg_bm)(p), a1, a2); + if (!dont_clear_access) + DRD_(bm_clear)(DRD_(sg_bm)(p), a1, a2); } } diff --git a/drd/drd_thread.h b/drd/drd_thread.h index a3601896d6..d9651393e7 100644 --- a/drd/drd_thread.h +++ b/drd/drd_thread.h @@ -165,7 +165,8 @@ void DRD_(thread_new_segment_and_combine_vc)(DrdThreadId tid, void DRD_(thread_update_conflict_set)(const DrdThreadId tid, const VectorClock* const old_vc); -void DRD_(thread_stop_using_mem)(const Addr a1, const Addr a2); +void DRD_(thread_stop_using_mem)(const Addr a1, const Addr a2, + const Bool dont_clear_access); void DRD_(thread_set_record_loads)(const DrdThreadId tid, const Bool enabled); void DRD_(thread_set_record_stores)(const DrdThreadId tid, const Bool enabled); void DRD_(thread_print_all)(void);