/* * Copyright 2002-2019 Intel Corporation. * * This software is provided to you as Sample Source Code as defined in the accompanying * End User License Agreement for the Intel(R) Software Development Products ("Agreement") * section 1.L. * * This software and the related documents are provided as is, with no express or implied * warranties, other than those that are expressly stated in the License. */ // // This tool prints a trace of image load and unload events // #include #include #include "pin.H" using std::cerr; using std::endl; // Pin calls this function every time a new img is loaded // It can instrument the image, but this example merely // counts the number of static instructions in the image VOID ImageLoad(IMG img, VOID *v) { UINT32 count = 0; for (SEC sec = IMG_SecHead(img); SEC_Valid(sec); sec = SEC_Next(sec)) { for (RTN rtn = SEC_RtnHead(sec); RTN_Valid(rtn); rtn = RTN_Next(rtn)) { // Prepare for processing of RTN, an RTN is not broken up into BBLs, // it is merely a sequence of INSs RTN_Open(rtn); for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins)) { count++; } // to preserve space, release data associated with RTN after we have processed it RTN_Close(rtn); } } fprintf(stderr, "Image %s has %d instructions\n", IMG_Name(img).c_str(), count); } /* ===================================================================== */ /* Print Help Message */ /* ===================================================================== */ INT32 Usage() { cerr << "This tool prints a log of image load and unload events" << endl; cerr << " along with static instruction counts for each image." << endl; cerr << endl << KNOB_BASE::StringKnobSummary() << endl; return -1; } /* ===================================================================== */ /* Main */ /* ===================================================================== */ int main(int argc, char * argv[]) { // prepare for image instrumentation mode PIN_InitSymbols(); // Initialize pin if (PIN_Init(argc, argv)) return Usage(); // Register ImageLoad to be called when an image is loaded IMG_AddInstrumentFunction(ImageLoad, 0); // Start the program, never returns PIN_StartProgram(); return 0; }