110 likes | 228 Views
PIN AOTI Extension CGO’04 Tutorial 3/21/04 Vijay Janapa Reddi, University of Colorado. What is AOTI?. A head O f T ime I nstrumentation ATOM model Not execution driven instrumentation Does not affect current PIN environment. Dynamic vs. Static Instrumentation. Dynamic Run time
E N D
PINAOTI ExtensionCGO’04 Tutorial3/21/04Vijay Janapa Reddi, University of Colorado
What is AOTI? • Ahead Of Time Instrumentation • ATOM model • Not execution driven instrumentation • Does not affect current PIN environment
Dynamic vs. Static Instrumentation • Dynamic • Run time • Instrument every instruction • Account only instructions that are executed • Static • Load time • Instrument every instruction • Account every instructionexecuted/unexecuted
Dynamic Static 1’ 1 1 1’ 2 2 3’ 3 3 2’ 4’ 4 5’ 5 4 5 2’ 6’ 6 6 7’ Code Cache 7’ 7 7 Code Cache Dynamic vs. Static Instrumentation
Dynamic counts VOID Fini(int n, VOID *v) { cout << dec << "(AOTI) brCount: " << brAOTI << endl; cout << dec << "(NORM) brCount: " << brNORM << endl; } VOID inc_brAOTI() { brAOTI++; } VOID inc_brNORM() { brNORM++; } VOID static(PIN_IMAGE *image, PROC head, VOID *v) { for (PROC proc = head; proc != PROC_Invalid(); proc = PROC_Next(proc)) for (INS ins = PROC_FirstIns(proc); ins != INS_INVALID(); ins = INS_Next(ins)) if (INS_Category(ins) == TYPE_CAT_BRANCH) PIN_InsertCall(IPOINT_BEFORE, ins, (AFUNPTR)inc_brAOTI, IARG_END); } VOID dynamic(INS ins, VOID *v) { if (INS_Category(ins) == TYPE_CAT_BRANCH) PIN_InsertCall(IPOINT_BEFORE, ins, (AFUNPTR)inc_brNORM, IARG_END); } int main(int argc, char *argv[]) { PIN_AddInstrumentImageFunction(static, 0); PIN_AddInstrumentInstructionFunction(dynamic, 0); PIN_AddFiniFunction(Fini, 0); PIN_StartProgram(); } (Static) brCount : 101969 (Dynamic) brCount : 101969
Static counts VOID Fini(int n, VOID *v) { cout << dec << "(AOTI) brCount: " << brAOTI << endl; cout << dec << "(NORM) brCount: " << brNORM << endl; } VOID static(PIN_IMAGE *image, PROC head, VOID *v) { for (PROC proc = head; proc != PROC_Invalid(); proc = PROC_Next(proc)) for (INS ins = PROC_FirstIns(proc); ins != INS_INVALID(); ins = INS_Next(ins)) if (INS_Category(ins) == TYPE_CAT_BRANCH) brAOTI++; } VOID dynamic(INS ins, VOID *v) { if (INS_Category(ins) == TYPE_CAT_BRANCH) brNORM++; } int main(int argc, char *argv[]) { PIN_AddInstrumentImageFunction(static, 0); PIN_AddInstrumentInstructionFunction(dynamic, 0); PIN_AddFiniFunction(Fini, 0); PIN_StartProgram(); } (Static) brCount : 36279 (Dynamic) brCount : 1308
AOTI API • PIN_AddInstrumentImageFunction(VOID (*fun)(PIN_IMAGE *, PROC head, VOID *), VOID *val) • Name of AOTI instrumentation function • PROC_First(VOID) • The first procedure in the current image • PROC_Next(PROC curr_sym) • The next procedure following the current procedure • PROC_Name(PROC curr_sym) • The current procedure name • PROC_FirstIns(PROC sym) • The first instruction in the current procedure symbol • PROC_Invalid() • Check to see if we have reached the end of the current procedure
PROC Address Range MakeInsRange AOTI Backend design Extract Elf Info. Extract Symbol .o/.so/.a Load Next Image AddInstrumentImageFunction’s
Advantages • Ability to see every instruction in images • Example: • Profiling • AOTI facilitates easy profiling at procedure/instruction level • Code coverage analysis • Function • Call
Disadvantages • No basic blocks • Longer execution runtime • More demand on memory
Future of PIN • XPin • A visual program analysis tool supporting PIN