A controller is usually an ALARM with some coordination for stop and start and some built in command line switches.
The example below can be found in InstLibExamples/control.cpp
#include <iostream> #include "pin.H" #include "instlib.H" using namespace INSTLIB; #if defined(__GNUC__) # if defined(__APPLE__) # define ALIGN_LOCK __attribute__ ((aligned(16))) /* apple only supports 16B alignment */ # else # define ALIGN_LOCK __attribute__ ((aligned(64))) # endif #else # define ALIGN_LOCK __declspec(align(64)) #endif LOCALVAR PIN_LOCK ALIGN_LOCK output_lock; // Track the number of instructions executed ICOUNT icount; // Contains knobs and instrumentation to recognize start/stop points CONTROL control(false, "controller_"); VOID Handler(CONTROL_EVENT ev, VOID * v, CONTEXT * ctxt, VOID * ip, THREADID tid) { GetLock(&output_lock, tid+1); std::cout << "tid: " << tid << " "; std::cout << "ip: " << ip << " " << icount.Count() ; switch(ev) { case CONTROL_START: std::cout << "Start" << endl; break; case CONTROL_STOP: std::cout << "Stop" << endl; break; case CONTROL_THREADID: std::cout << "ThreadID" << endl; break; default: ASSERTX(false); break; } ReleaseLock(&output_lock); } INT32 Usage() { cerr << "This pin tool demonstrates use of CONTROL to identify start/stop points in a program\n" "\n"; cerr << KNOB_BASE::StringKnobSummary() << endl; return -1; } // argc, argv are the entire command line, including pin -t <toolname> -- ... int main(int argc, char * argv[]) { if( PIN_Init(argc,argv) ) { return Usage(); } InitLock(&output_lock); icount.Activate(); // Activate alarm, must be done before PIN_StartProgram control.CheckKnobs(Handler, 0); // Start the program, never returns PIN_StartProgram(); return 0; }
|
Type for generic event handler |
|