-
Notifications
You must be signed in to change notification settings - Fork 2
/
FuncCount.cpp
executable file
·54 lines (44 loc) · 1.09 KB
/
FuncCount.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "pin.H"
#include <iostream>
using std::cout;
using std::endl;
UINT64 funcCount = 0; // total # of functions executed
/*
* analysis function (called whenever a function is executed)
*/
VOID incrementFuncCount ()
{
funcCount++;
}
/*
* instrumentation procedure (called when a new function is executed for the
* first time)
*/
VOID instrumentFunction (RTN func, VOID *v)
{
RTN_Open(func);
RTN_InsertCall(func, IPOINT_BEFORE, (AFUNPTR)incrementFuncCount, IARG_END);
RTN_Close(func);
}
/*
* output procedure (called when program exits)
*/
VOID printResults (INT32 code, VOID *v)
{
cout << "Total function execution count: " << funcCount << endl;
cout << "Exit code: " << code << endl;
}
int main(int argc, char *argv[])
{
// initialize Pin
if (PIN_Init(argc,argv)) {
cout << "Usage: pin -t <tool name> -- <exefile>" << endl;
return -1;
}
// install Pin callbacks
RTN_AddInstrumentFunction(instrumentFunction, 0);
PIN_AddFiniFunction(printResults, 0);
// start the program (never returns!)
PIN_StartProgram();
return 0;
}