VOID Trace(TRACE trace, VOID *v) { if ( KnobNoSharedLibs.Value() && IMG_Type(SEC_Img(RTN_Sec(TRACE_Rtn(trace)))) == IMG_TYPE_SHAREDLIB) return; for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl)) { // Insert instrumentation to count the number of times the bbl is executed BBLSTATS * bblstats = new BBLSTATS(BBL_Address(bbl), BBL_Size(bbl)); INS_InsertCall(BBL_InsHead(bbl), IPOINT_BEFORE, AFUNPTR(docount), IARG_PTR, &(bblstats->_executed), IARG_END); // Remember the counter and stats so we can compute a summary at the end statsList.push_back(bblstats); } }
//-------------------------------------------------------------------------------------- VOID Trace(TRACE TraceInfo, VOID *v) { // Visit every basic block in the trace for (BBL Bbl = TRACE_BblHead(TraceInfo); BBL_Valid(Bbl); Bbl = BBL_Next(Bbl)) { // Forward pass over all instructions in bbl for (INS Ins = BBL_InsHead(Bbl); INS_Valid(Ins); Ins = INS_Next(Ins)) { // check for the CALL if (INS_IsCall(Ins)) { INS_InsertCall( Ins, IPOINT_BEFORE, (AFUNPTR)InstCallHandler, IARG_INST_PTR, IARG_BRANCH_TARGET_ADDR, IARG_END ); } // check for the RET if (INS_IsRet(Ins)) { INS_InsertCall( Ins, IPOINT_BEFORE, (AFUNPTR)InstRetHandler, IARG_INST_PTR, IARG_END ); } } // Insert a call to CountBbl() before every basic bloc, passing the number of instructions BBL_InsertCall( Bbl, IPOINT_BEFORE, (AFUNPTR)CountBbl, IARG_INST_PTR, (UINT32)IARG_UINT32, BBL_Size(Bbl), IARG_UINT32, BBL_NumIns(Bbl), IARG_END ); } }