|
From: <sv...@va...> - 2010-08-29 09:19:15
|
Author: bart
Date: 2010-08-29 10:19:07 +0100 (Sun, 29 Aug 2010)
New Revision: 11301
Log:
Added command-line option --trace-alloc and disabled --free-is-write by default.
Modified:
trunk/drd/docs/drd-manual.xml
trunk/drd/drd_load_store.c
trunk/drd/drd_load_store.h
trunk/drd/drd_main.c
trunk/drd/drd_thread.c
trunk/drd/drd_thread.h
Modified: trunk/drd/docs/drd-manual.xml
===================================================================
--- trunk/drd/docs/drd-manual.xml 2010-08-29 09:15:19 UTC (rev 11300)
+++ trunk/drd/docs/drd-manual.xml 2010-08-29 09:19:07 UTC (rev 11301)
@@ -364,12 +364,12 @@
<varlistentry>
<term>
<option>
- <![CDATA[--free-is-write=<yes|no> [default: yes]]]>
+ <![CDATA[--free-is-write=<yes|no> [default: no]]]>
</option>
</term>
<listitem>
<para>
- 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.
</para>
@@ -493,6 +493,17 @@
</varlistentry>
<varlistentry>
<term>
+ <option><![CDATA[--trace-alloc=<yes|no> [default: no]]]></option>
+ </term>
+ <listitem>
+ <para>
+ Trace all memory allocations and deallocations. May produce a huge
+ amount of output.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
<option><![CDATA[--trace-barrier=<yes|no> [default: no]]]></option>
</term>
<listitem>
Modified: trunk/drd/drd_load_store.c
===================================================================
--- trunk/drd/drd_load_store.c 2010-08-29 09:15:19 UTC (rev 11300)
+++ trunk/drd/drd_load_store.c 2010-08-29 09:19:07 UTC (rev 11301)
@@ -114,12 +114,12 @@
}
}
-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 @@
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 @@
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)))));
}
Modified: trunk/drd/drd_load_store.h
===================================================================
--- trunk/drd/drd_load_store.h 2010-08-29 09:15:19 UTC (rev 11300)
+++ trunk/drd/drd_load_store.h 2010-08-29 09:19:07 UTC (rev 11301)
@@ -40,6 +40,8 @@
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,
Modified: trunk/drd/drd_main.c
===================================================================
--- trunk/drd/drd_main.c 2010-08-29 09:15:19 UTC (rev 11300)
+++ trunk/drd/drd_main.c 2010-08-29 09:19:07 UTC (rev 11301)
@@ -59,6 +59,7 @@
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 @@
{}
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 @@
" --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 @@
" drd options for monitoring process behavior:\n"
" --trace-addr=<address> 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 __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 @@
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 @@
{
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 @@
{
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 @@
{
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 @@
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 @@
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)
Modified: trunk/drd/drd_thread.c
===================================================================
--- trunk/drd/drd_thread.c 2010-08-29 09:15:19 UTC (rev 11300)
+++ trunk/drd/drd_thread.c 2010-08-29 09:19:07 UTC (rev 11301)
@@ -1104,7 +1104,8 @@
* [ 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 @@
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);
}
}
Modified: trunk/drd/drd_thread.h
===================================================================
--- trunk/drd/drd_thread.h 2010-08-29 09:15:19 UTC (rev 11300)
+++ trunk/drd/drd_thread.h 2010-08-29 09:19:07 UTC (rev 11301)
@@ -165,7 +165,8 @@
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);
|