my_itrace.cpp

Go to the documentation of this file.
00001 #include "pin.H"
00002 
00003 #include <algorithm>
00004 #include <map>
00005 #include <ostream>
00006 #include <iostream>
00007 #include <fstream>
00008 
00009 using namespace std;
00010 
00011 // Map stores for each address how often it was executed
00012 map<unsigned long long, unsigned long> instMap;
00013 
00014 // This function is called before every instruction is executed
00015 // and prints the IP
00016 void addToMap (void *ip) 
00017 { 
00018     unsigned long long addr = reinterpret_cast<unsigned long long>(ip);
00019     instMap[addr]++;
00020 }
00021 
00022 // Pin calls this function every time a new instruction is encountered
00023 VOID Instruction(INS ins, VOID *v)
00024 {
00025     // Insert a call to printip before every instruction, and pass it the IP
00026     INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)addToMap, IARG_INST_PTR, IARG_END);
00027 }
00028 
00029 // This function is called when the application exits
00030 void Fini(INT32 code, void *v)
00031 {
00032     ofstream fStream ("itrace.pin");
00033     
00034 
00035     map<unsigned long long,unsigned long>::iterator it = instMap.begin();
00036     for(; it != instMap.end(); ++it)
00037         fStream << hex << it->first << "\t" << dec << it->second << endl;
00038     
00039 }
00040 
00041 // argc, argv are the entire command line, including pin -t <toolname> -- ...
00042 int main(int argc, char * argv[])
00043 {    
00044     // Initialize pin
00045     PIN_Init(argc, argv);
00046 
00047     // Register Instruction to be called to instrument instructions
00048     INS_AddInstrumentFunction(Instruction, 0);
00049 
00050     // Register Fini to be called when the application exits
00051     PIN_AddFiniFunction(Fini, 0);
00052     
00053     // Start the program, never returns
00054     PIN_StartProgram();
00055     
00056     return 0;
00057 }

Generated on Tue Sep 15 14:48:47 2009 for RoseQtWidgets by  doxygen 1.4.7