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
00012 map<unsigned long long, unsigned long> instMap;
00013
00014
00015
00016 void addToMap (void *ip)
00017 {
00018 unsigned long long addr = reinterpret_cast<unsigned long long>(ip);
00019 instMap[addr]++;
00020 }
00021
00022
00023 VOID Instruction(INS ins, VOID *v)
00024 {
00025
00026 INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)addToMap, IARG_INST_PTR, IARG_END);
00027 }
00028
00029
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
00042 int main(int argc, char * argv[])
00043 {
00044
00045 PIN_Init(argc, argv);
00046
00047
00048 INS_AddInstrumentFunction(Instruction, 0);
00049
00050
00051 PIN_AddFiniFunction(Fini, 0);
00052
00053
00054 PIN_StartProgram();
00055
00056 return 0;
00057 }