You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.3 KiB
73 lines
2.3 KiB
/*
|
|
* 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.
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include "pin.H"
|
|
using std::ofstream;
|
|
using std::ios;
|
|
using std::string;
|
|
using std::endl;
|
|
|
|
// The running count of instructions is kept here
|
|
// make it static to help the compiler optimize docount
|
|
static UINT64 icount = 0;
|
|
|
|
// This function is called before every block
|
|
// Use the fast linkage for calls
|
|
VOID PIN_FAST_ANALYSIS_CALL docount(ADDRINT c) { icount += c; }
|
|
|
|
// Pin calls this function every time a new basic block is encountered
|
|
// It inserts a call to docount
|
|
VOID Trace(TRACE trace, VOID *v)
|
|
{
|
|
// Visit every basic block in the trace
|
|
for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl))
|
|
{
|
|
// Insert a call to docount for every bbl, passing the number of instructions.
|
|
// IPOINT_ANYWHERE allows Pin to schedule the call anywhere in the bbl to obtain best performance.
|
|
// Use a fast linkage for the call.
|
|
BBL_InsertCall(bbl, IPOINT_ANYWHERE, AFUNPTR(docount), IARG_FAST_ANALYSIS_CALL, IARG_UINT32, BBL_NumIns(bbl), IARG_END);
|
|
}
|
|
}
|
|
|
|
KNOB<string> KnobOutputFile(KNOB_MODE_WRITEONCE, "pintool",
|
|
"o", "inscount.out", "specify output file name");
|
|
|
|
// This function is called when the application exits
|
|
VOID Fini(INT32 code, VOID *v)
|
|
{
|
|
// Write to a file since cout and cerr maybe closed by the application
|
|
ofstream OutFile;
|
|
OutFile.open(KnobOutputFile.Value().c_str());
|
|
OutFile.setf(ios::showbase);
|
|
OutFile << "Count " << icount << endl;
|
|
OutFile.close();
|
|
}
|
|
|
|
// argc, argv are the entire command line, including pin -t <toolname> -- ...
|
|
int main(int argc, char * argv[])
|
|
{
|
|
// Initialize pin
|
|
PIN_Init(argc, argv);
|
|
|
|
// Register Instruction to be called to instrument instructions
|
|
TRACE_AddInstrumentFunction(Trace, 0);
|
|
|
|
// Register Fini to be called when the application exits
|
|
PIN_AddFiniFunction(Fini, 0);
|
|
|
|
// Start the program, never returns
|
|
PIN_StartProgram();
|
|
|
|
return 0;
|
|
}
|