From: Bart Van Assche Date: Sun, 11 Dec 2011 18:49:39 +0000 (+0000) Subject: DRD, --trace-addr: trace stored values too X-Git-Tag: svn/VALGRIND_3_8_0~563 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ffcd373429cc22fbe80e42dc6a1efcb631a27024;p=thirdparty%2Fvalgrind.git DRD, --trace-addr: trace stored values too git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12290 --- diff --git a/drd/drd_load_store.c b/drd/drd_load_store.c index c7bfdedc7c..b531ceb898 100644 --- a/drd/drd_load_store.c +++ b/drd/drd_load_store.c @@ -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; diff --git a/drd/drd_load_store.h b/drd/drd_load_store.h index 64c8ab92e2..55429f32e2 100644 --- a/drd/drd_load_store.h +++ b/drd/drd_load_store.h @@ -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); diff --git a/drd/drd_main.c b/drd/drd_main.c index 5a7b2b2e8b..5b4d83d406 100644 --- a/drd/drd_main.c +++ b/drd/drd_main.c @@ -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", diff --git a/drd/tests/annotate_trace_memory.stderr.exp b/drd/tests/annotate_trace_memory.stderr.exp index ab675c3169..fc74e285e2 100644 --- a/drd/tests/annotate_trace_memory.stderr.exp +++ b/drd/tests/annotate_trace_memory.stderr.exp @@ -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 diff --git a/drd/tests/annotate_trace_memory_xml.stderr.exp b/drd/tests/annotate_trace_memory_xml.stderr.exp index 3aa865b7e4..7602a0e0d7 100644 --- a/drd/tests/annotate_trace_memory_xml.stderr.exp +++ b/drd/tests/annotate_trace_memory_xml.stderr.exp @@ -31,7 +31,7 @@ FLAGS [phb=1, fm=0] test01: positive - store 0x........ size 4 (thread x / vc ...) + store 0x........ size 4 val 0x........ (thread x / vc ...) 0x........ @@ -51,7 +51,7 @@ test01: positive - store 0x........ size 4 (thread x / vc ...) + store 0x........ size 4 val 0x........ (thread x / vc ...) 0x........