]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
drd: Add command-line option --ptrace-addr.
authorBart Van Assche <bvanassche@acm.org>
Tue, 24 Jan 2012 18:39:29 +0000 (18:39 +0000)
committerBart Van Assche <bvanassche@acm.org>
Tue, 24 Jan 2012 18:39:29 +0000 (18:39 +0000)
This command-line option has been used to track down the recently fixed race in
drd/drd_pthread_intercepts.c.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12354

drd/drd_clientreq.c
drd/drd_main.c
drd/drd_suppression.c
drd/drd_suppression.h

index 3173282becc0a2db6003061151dbcd51fff1689c..be165447858330fdab3274cd3e3c7f31097199cf 100644 (file)
@@ -220,7 +220,7 @@ static Bool handle_client_request(ThreadId vg_tid, UWord* arg, UWord* ret)
       break;
 
    case VG_USERREQ__DRD_START_TRACE_ADDR:
-      DRD_(start_tracing_address_range)(arg[1], arg[1] + arg[2]);
+      DRD_(start_tracing_address_range)(arg[1], arg[1] + arg[2], False);
       break;
 
    case VG_USERREQ__DRD_STOP_TRACE_ADDR:
index 26e04a032536c69b89914bbf0757fbb816425571..364795e06a8819a92f1ea1eb2116f07e76e1eea4 100644 (file)
@@ -90,6 +90,7 @@ static Bool DRD_(process_cmd_line_option)(Char* arg)
    int trace_semaphore        = -1;
    int trace_suppression      = -1;
    Char* trace_address        = 0;
+   Char* ptrace_address       = 0;
 
    if      VG_BOOL_CLO(arg, "--check-stack-var",     check_stack_accesses) {}
    else if VG_INT_CLO (arg, "--join-list-vol",       join_list_vol) {}
@@ -119,6 +120,7 @@ static Bool DRD_(process_cmd_line_option)(Char* arg)
    else if VG_BOOL_CLO(arg, "--trace-suppr",         trace_suppression) {}
    else if VG_BOOL_CLO(arg, "--var-info",            s_var_info) {}
    else if VG_INT_CLO (arg, "--exclusive-threshold", exclusive_threshold_ms) {}
+   else if VG_STR_CLO (arg, "--ptrace-addr",         ptrace_address) {}
    else if VG_INT_CLO (arg, "--shared-threshold",    shared_threshold_ms)    {}
    else if VG_STR_CLO (arg, "--trace-addr",          trace_address) {}
    else
@@ -151,10 +153,13 @@ static Bool DRD_(process_cmd_line_option)(Char* arg)
       DRD_(thread_set_segment_merge_interval)(segment_merge_interval);
    if (show_confl_seg != -1)
       DRD_(set_show_conflicting_segments)(show_confl_seg);
-   if (trace_address)
-   {
+   if (trace_address) {
       const Addr addr = VG_(strtoll16)(trace_address, 0);
-      DRD_(start_tracing_address_range)(addr, addr + 1);
+      DRD_(start_tracing_address_range)(addr, addr + 1, False);
+   }
+   if (ptrace_address) {
+      const Addr addr = VG_(strtoll16)(ptrace_address, 0);
+      DRD_(start_tracing_address_range)(addr, addr + 1, True);
    }
    if (trace_barrier != -1)
       DRD_(barrier_set_trace)(trace_barrier);
@@ -217,6 +222,10 @@ static void DRD_(print_usage)(void)
 "    --show-stack-usage=yes|no Print stack usage at thread exit time [no].\n"
 "\n"
 "  drd options for monitoring process behavior:\n"
+"    --ptrace-addr=<address>   Trace all load and store activity for the\n"
+"                              specified address and keep doing that even after\n"
+"                              the memory at that address has been freed and\n"
+"                              reallocated [off].\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"
index 69c48c482a54df687f55e3b7cd7729299f4bc379..07b81df108df342626954d8906ebde55f08e125b 100644 (file)
@@ -112,30 +112,52 @@ Bool DRD_(range_contains_suppression_or_hbvar)(const Addr a1, const Addr a2)
    return DRD_(bm_has_any_access)(s_suppressed, a1, a2);
 }
 
-void DRD_(start_tracing_address_range)(const Addr a1, const Addr a2)
+/**
+ * Start tracing memory accesses in the range [a1,a2). If persistent == True,
+ * keep tracing even after memory deallocation and reallocation.
+ */
+void DRD_(start_tracing_address_range)(const Addr a1, const Addr a2,
+                                       const Bool persistent)
 {
    tl_assert(a1 <= a2);
 
+   if (s_trace_suppression)
+      VG_(message)(Vg_DebugMsg, "start_tracing(0x%lx, %ld) %s\n",
+                   a1, a2 - a1, persistent ? "persistent" : "non-persistent");
+
    DRD_(bm_access_range_load)(s_traced, a1, a2);
-   if (!DRD_(g_any_address_traced))
+   if (persistent)
+      DRD_(bm_access_range_store)(s_traced, a1, a2);
+   if (!DRD_(g_any_address_traced) && a1 < a2)
       DRD_(g_any_address_traced) = True;
 }
 
+/**
+ * Stop tracing memory accesses in the range [a1,a2).
+ */
 void DRD_(stop_tracing_address_range)(const Addr a1, const Addr a2)
 {
    tl_assert(a1 <= a2);
 
-   DRD_(bm_clear_load)(s_traced, a1, a2);
-   if (DRD_(g_any_address_traced))
-      DRD_(g_any_address_traced)
-         = DRD_(bm_has_any_load_g)(s_traced);
+   if (s_trace_suppression)
+      VG_(message)(Vg_DebugMsg, "stop_tracing(0x%lx, %ld)\n",
+                   a1, a2 - a1);
+
+   if (DRD_(g_any_address_traced)) {
+      DRD_(bm_clear)(s_traced, a1, a2);
+      DRD_(g_any_address_traced) = DRD_(bm_has_any_load_g)(s_traced);
+   }
 }
 
 Bool DRD_(is_any_traced)(const Addr a1, const Addr a2)
 {
-   return DRD_(bm_has_any_load)(s_traced, a1, a2);
+   return DRD_(bm_has_any_access)(s_traced, a1, a2);
 }
 
+/**
+ * Stop using the memory range [a1,a2). Stop tracing memory accesses to
+ * non-persistent address ranges.
+ */
 void DRD_(suppression_stop_using_mem)(const Addr a1, const Addr a2)
 {
    if (s_trace_suppression) {
@@ -151,5 +173,5 @@ void DRD_(suppression_stop_using_mem)(const Addr a1, const Addr a2)
    tl_assert(a1);
    tl_assert(a1 <= a2);
    DRD_(bm_clear)(s_suppressed, a1, a2);
-   DRD_(bm_clear)(s_traced, a1, a2);
+   DRD_(bm_clear_load)(s_traced, a1, a2);
 }
index 15fc8ed3bb9f8507d052b7edbe7fc2c5dc345b03..0fe8bdf0821a0dfedc57fba1847efe082375a7e5 100644 (file)
@@ -18,7 +18,8 @@ Bool DRD_(is_suppressed)(const Addr a1, const Addr a2);
 Bool DRD_(is_any_suppressed)(const Addr a1, const Addr a2);
 void DRD_(mark_hbvar)(const Addr a1);
 Bool DRD_(range_contains_suppression_or_hbvar)(const Addr a1, const Addr a2);
-void DRD_(start_tracing_address_range)(const Addr a1, const Addr a2);
+void DRD_(start_tracing_address_range)(const Addr a1, const Addr a2,
+                                       const Bool persistent);
 void DRD_(stop_tracing_address_range)(const Addr a1, const Addr a2);
 Bool DRD_(is_any_traced)(const Addr a1, const Addr a2);
 void DRD_(suppression_stop_using_mem)(const Addr a1, const Addr a2);