]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
DRD, --trace-addr: trace stored values too
authorBart Van Assche <bvanassche@acm.org>
Sun, 11 Dec 2011 18:49:39 +0000 (18:49 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sun, 11 Dec 2011 18:49:39 +0000 (18:49 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12290

drd/drd_load_store.c
drd/drd_load_store.h
drd/drd_main.c
drd/tests/annotate_trace_memory.stderr.exp
drd/tests/annotate_trace_memory_xml.stderr.exp

index c7bfdedc7c9c0b4fd2debb981b861acc0bc950cb..b531ceb89834ecbcc8f93a065bd1bd8199a8013c 100644 (file)
@@ -85,19 +85,26 @@ void DRD_(set_first_race_only)(const Bool fro)
 }
 
 void DRD_(trace_mem_access)(const Addr addr, const SizeT size,
-                            const BmAccessTypeT access_type)
+                            const BmAccessTypeT access_type,
+                            const HWord stored_value)
 {
    if (DRD_(is_any_traced)(addr, addr + size))
    {
       char* vc;
 
       vc = DRD_(vc_aprint)(DRD_(thread_get_vc)(DRD_(thread_get_running_tid)()));
-      DRD_(trace_msg_w_bt)("%s 0x%lx size %ld (thread %d / vc %s)",
-                           access_type == eLoad ? "load "
-                           : access_type == eStore ? "store"
-                           : access_type == eStart ? "start"
-                           : access_type == eEnd ? "end  " : "????",
-                           addr, size, DRD_(thread_get_running_tid)(), vc);
+      if (access_type == eStore && size <= sizeof(HWord)) {
+         DRD_(trace_msg_w_bt)("store 0x%lx size %ld val 0x%lx (thread %d /"
+                              " vc %s)", addr, size, stored_value,
+                              DRD_(thread_get_running_tid)(), vc);
+      } else {
+         DRD_(trace_msg_w_bt)("%s 0x%lx size %ld (thread %d / vc %s)",
+                              access_type == eLoad ? "load "
+                              : access_type == eStore ? "store"
+                              : access_type == eStart ? "start"
+                              : access_type == eEnd ? "end  " : "????",
+                              addr, size, DRD_(thread_get_running_tid)(), vc);
+      }
       VG_(free)(vc);
       tl_assert(DRD_(DrdThreadIdToVgThreadId)(DRD_(thread_get_running_tid)())
                 == VG_(get_running_tid)());
@@ -106,12 +113,13 @@ 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)
 {
-   return DRD_(trace_mem_access)(addr, size, eLoad);
+   return DRD_(trace_mem_access)(addr, size, eLoad, 0);
 }
 
-static VG_REGPARM(2) void drd_trace_mem_store(const Addr addr,const SizeT size)
+static VG_REGPARM(3) void drd_trace_mem_store(const Addr addr,const SizeT size,
+                                              const HWord stored_value)
 {
-   return DRD_(trace_mem_access)(addr, size, eStore);
+   return DRD_(trace_mem_access)(addr, size, eStore, stored_value);
 }
 
 static void drd_report_race(const Addr addr, const SizeT size,
@@ -363,23 +371,61 @@ static void instrument_load(IRSB* const bb,
    addStmtToIRSB(bb, IRStmt_Dirty(di));
 }
 
-static void instrument_store(IRSB* const bb,
-                             IRExpr* const addr_expr,
-                             const HWord size)
+static const IROp u_widen_irop[5][9] = {
+   [1][2] = Iop_8Uto16,
+   [1][4] = Iop_8Uto32,
+   [1][8] = Iop_8Uto64,
+   [2][4] = Iop_16Uto32,
+   [2][8] = Iop_16Uto64,
+   [4][8] = Iop_32Uto64,
+};
+
+static void instrument_store(IRSB* const bb, IRExpr* const addr_expr,
+                             IRExpr* const data_expr)
 {
    IRExpr* size_expr;
    IRExpr** argv;
    IRDirty* di;
+   HWord size;
+
+   size = sizeofIRType(typeOfIRExpr(bb->tyenv, data_expr));
 
    if (UNLIKELY(DRD_(any_address_is_traced)()))
    {
+      IRExpr *hword_data_expr;
+
+      if (size == sizeof(HWord)) {
+         hword_data_expr = data_expr;
+      } else {
+         IROp widen_op;
+
+         tl_assert(sizeof(HWord) == 4 || sizeof(HWord) == 8);
+         if (size < sizeof(u_widen_irop)/sizeof(u_widen_irop[0])) {
+            widen_op = u_widen_irop[size][sizeof(HWord)];
+            if (!widen_op)
+               widen_op = Iop_INVALID;
+         } else {
+            widen_op = Iop_INVALID;
+         }
+         if (widen_op != Iop_INVALID) {
+            IRTemp tmp;
+
+            tmp = newIRTemp(bb->tyenv, sizeof(HWord) == 4 ? Ity_I32 : Ity_I64);
+            addStmtToIRSB(bb,
+                          IRStmt_WrTmp(tmp, IRExpr_Unop(widen_op, data_expr)));
+            hword_data_expr = IRExpr_RdTmp(tmp);
+         } else {
+            hword_data_expr = mkIRExpr_HWord(0);
+         }
+      }
       addStmtToIRSB(bb,
          IRStmt_Dirty(
-            unsafeIRDirty_0_N(/*regparms*/2,
-                             "drd_trace_mem_store",
-                             VG_(fnptr_to_fnentry)
-                             (drd_trace_mem_store),
-                             mkIRExprVec_2(addr_expr, mkIRExpr_HWord(size)))));
+            unsafeIRDirty_0_N(/*regparms*/3,
+                              "drd_trace_mem_store",
+                              VG_(fnptr_to_fnentry)
+                              (drd_trace_mem_store),
+                              mkIRExprVec_3(addr_expr, mkIRExpr_HWord(size),
+                                            hword_data_expr))));
    }
 
    if (!s_check_stack_accesses && is_stack_access(bb, addr_expr))
@@ -479,12 +525,7 @@ IRSB* DRD_(instrument)(VgCallbackClosure* const closure,
 
       case Ist_Store:
          if (instrument)
-         {
-            instrument_store(bb,
-                             st->Ist.Store.addr,
-                             sizeofIRType(typeOfIRExpr(bb->tyenv,
-                                                       st->Ist.Store.data)));
-         }
+            instrument_store(bb, st->Ist.Store.addr, st->Ist.Store.data);
          addStmtToIRSB(bb, st);
          break;
 
index 64c8ab92e2b154c55d415e3e8e49502f6fa41e86..55429f32e2997534a3492c47c0240ab812439402 100644 (file)
@@ -46,7 +46,8 @@ IRSB* DRD_(instrument)(VgCallbackClosure* const closure,
                        IRType const gWordTy,
                        IRType const hWordTy);
 void DRD_(trace_mem_access)(const Addr addr, const SizeT size,
-                            const BmAccessTypeT access_type);
+                            const BmAccessTypeT access_type,
+                            const HWord stored_value);
 VG_REGPARM(2) void DRD_(trace_load)(Addr addr, SizeT size);
 VG_REGPARM(2) void DRD_(trace_store)(Addr addr, SizeT size);
 void DRD_(clean_memory)(const Addr a1, const SizeT len);
index 5a7b2b2e8ba1c3d6fbfcad9cb838b81dc51559e6..5b4d83d4063dbdd4fa1cbbc2342f30063bc7e67b 100644 (file)
@@ -321,7 +321,7 @@ void drd_start_using_mem(const Addr a1, const SizeT len,
 
    if (UNLIKELY(DRD_(any_address_is_traced)()))
    {
-      DRD_(trace_mem_access)(a1, len, eStart);
+      DRD_(trace_mem_access)(a1, len, eStart, 0);
    }
 
    if (UNLIKELY(DRD_(running_thread_inside_pthread_create)()))
@@ -353,7 +353,7 @@ void drd_stop_using_mem(const Addr a1, const SizeT len,
    tl_assert(a1 <= a2);
 
    if (UNLIKELY(DRD_(any_address_is_traced)()))
-      DRD_(trace_mem_access)(a1, len, eEnd);
+      DRD_(trace_mem_access)(a1, len, eEnd, 0);
 
    if (!is_stack_mem && s_trace_alloc)
       DRD_(trace_msg)("Stopped using memory range 0x%lx + %ld",
index ab675c3169d9f775583e0f54daaf422171243350..fc74e285e2d0f0bd392f59d31bc9d62627cbfaeb 100644 (file)
@@ -1,10 +1,10 @@
 
 FLAGS [phb=1, fm=0]
 test01: positive
-store 0x........ size 4 (thread x / vc ...)
+store 0x........ size 4 val 0x........ (thread x / vc ...)
    at 0x........: test01::Worker() (tsan_unittest.cpp:?)
    by 0x........: MyThread::ThreadBody(MyThread*) (tsan_thread_wrappers_pthread.h:?)
-store 0x........ size 4 (thread x / vc ...)
+store 0x........ size 4 val 0x........ (thread x / vc ...)
    at 0x........: test01::Parent() (tsan_unittest.cpp:?)
    by 0x........: test01::Run() (tsan_unittest.cpp:?)
 Conflicting store by thread x at 0x........ size 4
index 3aa865b7e4e194de9acbda394f067a6b07d25692..7602a0e0d7d128dd9d6f6040d94f4f149e770525 100644 (file)
@@ -31,7 +31,7 @@
 
 FLAGS [phb=1, fm=0]
 test01: positive
-  <trace><text>store 0x........ size 4 (thread x / vc ...)</text>
+  <trace><text>store 0x........ size 4 val 0x........ (thread x / vc ...)</text>
   <stack>
     <frame>
       <ip>0x........</ip>
@@ -51,7 +51,7 @@ test01: positive
     </frame>
   </stack>
   </trace>
-  <trace><text>store 0x........ size 4 (thread x / vc ...)</text>
+  <trace><text>store 0x........ size 4 val 0x........ (thread x / vc ...)</text>
   <stack>
     <frame>
       <ip>0x........</ip>