/* * Atom instrumentation program * special features: * - change the character string "tested" to be the * name of the procedure you want instrumented -- * only instructions executing within that procedure will * be instrumented * - only data loads & stores are instrumented; not instruction fetches */ #include #include static const char * SafeProcName(Proc *); const char *tested = "mymatmul"; void InstrumentInit(int p1, char **p2) { AddCallProto("OpenFile()"); AddCallProto("DataLoad(VALUE)"); AddCallProto("DataStore(VALUE)"); AddCallProto("CloseFile()"); AddCallProgram(ProgramBefore,"OpenFile"); AddCallProgram(ProgramAfter,"CloseFile"); } Instrument(int argc, char **argv, Obj *obj) { Proc *p; Block *b; Inst *i; for (p = GetFirstObjProc(obj); p != NULL; p = GetNextProc(p)) { if (strcmp(SafeProcName(p), tested) == 0) { for (b = GetFirstBlock(p); b != NULL; b = GetNextBlock(b)) { for (i = GetFirstInst(b); i != NULL; i = GetNextInst(i)) { if (IsInstType(i,InstTypeLoad)) AddCallInst(i,InstBefore,"DataLoad",EffAddrValue); if (IsInstType(i,InstTypeStore)) AddCallInst(i,InstBefore,"DataStore",EffAddrValue); } } } } } static const char *SafeProcName(Proc *p) { const char * name; static char buf[128]; name = ProcName(p); if (name) return(name); sprintf(buf, "proc_at_0x%lx", ProcPC(p)); return(buf); }