/* * trace inspection (instrumentation function) * * traverse the basic blocks (BBLs) on the trace and * inspect every instruction for instrumenting it * accordingly * * @trace: instructions trace; given by PIN * @v: callback value */ static void trace_inspect(TRACE trace, VOID *v) { /* iterators */ BBL bbl; INS ins; xed_iclass_enum_t ins_indx; /* versioning support */ ADDRINT version, version_mask = (ADDRINT)v; if (version_mask) { /* * ignore code cache versions that we * are not supposed to instrument */ version = TRACE_Version(trace); if ((version & version_mask) == 0) return; } /* traverse all the BBLs in the trace */ for (bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl)) { /* traverse all the instructions in the BBL */ for (ins = BBL_InsHead(bbl); INS_Valid(ins); ins = INS_Next(ins)) { /* * use XED to decode the instruction and * extract its opcode */ ins_indx = (xed_iclass_enum_t)INS_Opcode(ins); /* * invoke the pre-ins instrumentation callback */ if (ins_desc[ins_indx].pre != NULL) ins_desc[ins_indx].pre(ins); /* * analyze the instruction (default handler) */ if (ins_desc[ins_indx].dflact == INSDFL_ENABLE) ins_inspect(ins); /* * invoke the post-ins instrumentation callback */ if (ins_desc[ins_indx].post != NULL) ins_desc[ins_indx].post(ins); } } }
/* * trace inspection (instrumentation function) * * traverse the basic blocks (BBLs) on the trace and * inspect every instruction for instrumenting it * accordingly * * @trace: instructions trace; given by PIN * @v: callback value */ static void trace_inspect(TRACE trace, VOID *v) { /* iterators */ BBL bbl; INS ins; xed_iclass_enum_t ins_indx; //printf("dealing trace!\n"); /* traverse all the BBLs in the trace */ for (bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl)) { /* traverse all the instructions in the BBL */ ins = BBL_InsHead(bbl); for (ins = BBL_InsHead(bbl); INS_Valid(ins); ins = INS_Next(ins)) { /* * use XED to decode the instruction and * extract its opcode */ ins_indx = (xed_iclass_enum_t)INS_Opcode(ins); /* * invoke the pre-ins instrumentation callback */ if (ins_desc[ins_indx].pre != NULL) ins_desc[ins_indx].pre(ins); /* * analyze the instruction (default handler) */ if (ins_desc[ins_indx].dflact == INSDFL_ENABLE){ ins_inspect(ins); //printf("dealing ins_inspect!\n"); } /* * invoke the post-ins instrumentation callback */ if (ins_desc[ins_indx].post != NULL) ins_desc[ins_indx].post(ins); } } }