|
From: Dave A. <ai...@gm...> - 2006-03-08 01:26:43
|
I want to trace all writes to an mmaped piece of RAM (a GPU) using valgrind=
,
I wrote a trivial store interceptor copying from lackey, and I've set
it up to intercept mmap (changed new_mem_mmap to see the offset) and
if I like the offset I want to dump info in that area.
This is fine and I can tell when the app writes to the address, and
what address it is and how much, however I'm not really sure how I can
actually extract the data the app is writing.
Do I need to do something along the lines of memcheck with all the
shadowing stuff in order to get what data is being written into the
area in my handler function?
Some of my code is below (unworking.. can't push non-32 or 64-bit words)
Dave.
static struct mmt_memmap {
Addr addr;
SizeT len;
} mmt_gpu_reg;
static VG_REGPARM(3) void trace_store(Addr addr, SizeT size)
{
if ((addr > mmt_gpu_reg.addr) && (addr < mmt_gpu_reg.addr+mmt_gpu_reg.len=
))
VG_(printf)("store: %p, %d\n", addr-mmt_gpu_reg.addr, size);
}
static void mmt_post_clo_init(void)
{
}
static
IRBB* mmt_instrument ( VgCallbackClosure* closure,
IRBB* bb_in,
VexGuestLayout* layout,
VexGuestExtents* vge,
IRType gWordTy, IRType hWordTy )
{
IRBB* bb;
IRStmt* st;
IRDirty* di;
int i;
IRExpr** argv;
IRExpr* addr_expr;
IRExpr* size_expr;
IRExpr* data_expr;
IRType arg_ty;
if (gWordTy !=3D hWordTy) {
/* We don't currently support this case. */
VG_(tool_panic)("host/guest word size mismatch");
}
/* Set up BB */
bb =3D emptyIRBB();
bb->tyenv =3D dopyIRTypeEnv(bb_in->tyenv);
bb->next =3D dopyIRExpr(bb_in->next);
bb->jumpkind =3D bb_in->jumpkind;
// Copy verbatim any IR preamble preceding the first IMark
for (i =3D 0; i < bb_in->stmts_used; i++) {
st =3D bb_in->stmts[i];
tl_assert(st);
switch(st->tag) {
case Ist_Store:
arg_ty =3D typeOfIRExpr(bb->tyenv, st->Ist.Store.data);
addr_expr =3D st->Ist.Store.addr;
size_expr =3D mkIRExpr_HWord(sizeofIRType(arg_ty));
data_expr =3D st->Ist.Store.data;
switch(arg_ty)
{
}
switch(data_expr->tag) {
case Iex_Tmp:
case Iex_Const:
=09argv =3D mkIRExprVec_3( addr_expr, size_expr, data_expr );
=09di =3D unsafeIRDirty_0_N( /*regparms*/2,
=09=09=09=09"trace_store",
=09=09=09=09VG_(fnptr_to_fnentry)( trace_store ),
=09=09=09=09argv );
=09addStmtToIRBB( bb, IRStmt_Dirty(di) );
=09break;
default:
=09break;
}
default:
break;
}
addStmtToIRBB( bb, st );
}
return bb;
|