]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Added command-line option --trace-alloc and disabled --free-is-write by default.
authorBart Van Assche <bvanassche@acm.org>
Sun, 29 Aug 2010 09:19:07 +0000 (09:19 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sun, 29 Aug 2010 09:19:07 +0000 (09:19 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11301

drd/docs/drd-manual.xml
drd/drd_load_store.c
drd/drd_load_store.h
drd/drd_main.c
drd/drd_thread.c
drd/drd_thread.h

index 10907d29a189287c898d048f40135937e7bd0dc2..44812f1013e7f981205c58aa80bc642dc2b10413 100644 (file)
@@ -364,12 +364,12 @@ behavior of the DRD tool itself:</para>
   <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>
@@ -491,6 +491,17 @@ client program:
       </para>
     </listitem>
   </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>
index 2b6d6f50266219d513374e3b0f35e497701d07ab..be6667175a81d7962486e2f3e72f23defdaf7282 100644 (file)
@@ -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)))));
    }
index be6df7b9352ea46496504f7105516e62ecd38a4e..f80e31b8cb79bf36d8f8e1e69da232ae1aa5ebd9 100644 (file)
@@ -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,
index b8a6f54edb6e0d55df4fb12630ca2703fc96b0f0..8b2024e4d21b9c2db5e48cf99723d0cd25a7f245 100644 (file)
@@ -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=<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 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)
index a12553a4289d8af807609e3fe60f5db43707e4be..f9edc6a06a46e849d017616c774c442369ed83e3 100644 (file)
@@ -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);
       }
    }
 
index a3601896d6f7683cc29838f01967eb6a39f52e6c..d9651393e7327a25bdfc7fc0c7bf9ac28d78e22b 100644 (file)
@@ -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);