/*!
 * The main procedure of the tool.
 * This function is called when the application image is loaded but not yet started.
 * @param[in]   argc            total number of elements in the argv array
 * @param[in]   argv            array of command line arguments,
 *                              including pin -t <toolname> -- ...
 */
int main(int argc, char *argv[])
{
#if 0
    string internalState = LEVEL_BASE::KNOB_BASE::StringLongAll();
    printf ("In main: internalState:\n%s \n",internalState.c_str());
#endif
#if 0
    string knobSummary = LEVEL_BASE::KNOB_BASE::StringKnobSummary();
    printf ("In main: knobSummary:\n%s \n",knobSummary.c_str());
#endif

    // Initialize PIN library. Print help message if -h(elp) is specified
    // in the command line or the command line is invalid
    if ( PIN_Init(argc,argv) )
    {
        printf ("Commandline error in pin tool! \n");
        return Usage();
    }

    if (KnobCount)
    {
        // Specify callback function when each image is loaded (main program or shared libraries).
        IMG_AddInstrumentFunction(ImageLoad, 0);

        // Register function to be called to instrument traces
        TRACE_AddInstrumentFunction(Trace, 0);

        // Register function to be called for every thread before it starts running
        PIN_AddThreadStartFunction(ThreadStart, 0);

        // Register function to be called when the application exits
        PIN_AddFiniFunction(Fini, 0);
    }

    cerr <<  "===============================================" << endl;
    cerr <<  "This application is instrumented by MyPinTool" << endl;
    if (!KnobOutputFile.Value().empty())
    {
        cerr << "See file " << KnobOutputFile.Value() << " for analysis results" << endl;
    }
    cerr <<  "===============================================" << endl;

    // Start the program, never returns
    PIN_StartProgram();

    return 0;
}
VOID Fini(INT32 code, VOID *v)
{
    if (haveError)
    {
        std::cerr << "***error in expected values, see the file " << KnobOutfile.Value() << std::endl;
        exit (-1);
    }
}
/*!
 * Print out analysis results.
 * This function is called when the application exits.
 * @param[in]   code            exit code of the application
 * @param[in]   v               value specified by the tool in the
 *                              PIN_AddFiniFunction function call
 */
VOID Fini(INT32 code, VOID *v)
{
    const string fileName = KnobOutputFile.Value();
    if (!fileName.empty())
    {
        delete out;
    }
}
int main(int argc, char * argv[])
{
    PIN_Init(argc, argv);

    Out.open(KnobOutfile.Value().c_str());
    if (!Out.good())
    {
        std::cerr << "Unable to open '" << KnobOutfile.Value() << "'" << std::endl;
        return 1;
    }

    INS_AddInstrumentFunction(InstrumentIndirects, 0);
    PIN_AddFiniFunction(Fini, 0);

    PIN_StartProgram();
    return 0;
}
Example #5
0
int main(int argc, char *argv[])
{

    // Initialize pin & symbol manager
    PIN_InitSymbols();
    if( PIN_Init(argc,argv) )
    {
        return Usage();
    }
    
    inputFile.open(KnobInputFile.Value().c_str());
    if(buildFuncList(inputFile))
	return Usage();

    if(strlen(KnobScriptPath.Value().c_str()) > 0)
    {
	scriptProvided = TRUE;

	int cmdLen = strlen(KnobScriptPath.Value().c_str()) + 2 + MAX_PID_DIGITS;
	scriptCMDPartI = (char*)malloc(cmdLen);
	if(scriptCMDPartI == NULL)
	{
	    cerr << "Couldn't malloc " << endl;
	    exit(-1);
	}
	snprintf(scriptCMDPartI, cmdLen, "%s %d", KnobScriptPath.Value().c_str(), getpid());
    }

    /* Register Image to be called to instrument functions.*/
    IMG_AddInstrumentFunction(Image, 0);

    /* Register Analysis routines to be called when a thread begins/ends */
    PIN_AddThreadStartFunction(ThreadStart, 0);
    PIN_AddThreadFiniFunction(ThreadFini, 0);
    
    /* Register the application-start function */
    PIN_AddApplicationStartFunction(ApplicationStart, 0);

    filter.Activate();

    /* Never returns */
    PIN_StartProgram();
    
    return 0;
    
}
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 << "Count " << icount << endl;
    OutFile.close();
}
Example #7
0
static bool LaunchGdb()
{
    // Ask Pin for the TCP port that it is listening on.  GDB needs to
    // connect to this port via the "target remote" command.
    //
    DEBUG_CONNECTION_INFO info;
    PIN_GetDebugConnectionInfo(&info);
    std::ofstream outf(KnobOut.Value().c_str());
    outf << "set remotetimeout " << KnobTimeout.Value() << "\n";
    outf << "target remote :" << info._tcpServer._tcpPort << "\n";
    outf.close();

    // The "makefile" should launch GDB when we write the output file above.
    // Wait for GDB to launch and connect.
    //
    return PIN_WaitForDebuggerToConnect(1000*KnobTimeout.Value());
}
Example #8
0
static void DoBreakpoint(CONTEXT *ctxt, THREADID tid)
{
    if (IsFirstBreakpoint)
    {
        IsFirstBreakpoint = FALSE;
        PIN_ApplicationBreakpoint(ctxt, tid, KnobWaitForDebugger.Value(), "The tool wants to stop");
    }
}
Example #9
0
/* ================================================================== */
VOID InitCounters()
{
    string logFileName = KnobOutputFile.Value();
    TraceFile.open(logFileName.c_str());

    numLinks = 0;
    numUnlinks = 0;
}
VOID Fini(INT32 code, VOID *v)
{  
	// Write to a file 
	ofstream OutFile;
	OutFile.open(KnobOutputFile.Value().c_str());
	OutFile.setf(ios::showbase);
	cout<<disp<<endl;
	OutFile.close();
}
/* ================================================================== */
VOID InitCounters()
{
    string logFileName = KnobOutputFile.Value();
    if( KnobPid )
        logFileName += "." + decstr( getpid_portable() );
    TraceFile.open(logFileName.c_str());

    insertions = 0;
}
Example #12
0
/* ===================================================================== */
VOID Fini(int, VOID * v) {
  FILE* outfile;
  assert(outfile = fopen(KnobOutputFile.Value().c_str(),"w"));
  fprintf(
      outfile,
      "takenCorrect %llu  takenIncorrect %llu notTakenCorrect %llu notTakenIncorrect %llu\n",
      predictionStats[TRUE][TRUE], predictionStats[TRUE][FALSE],
      predictionStats[FALSE][TRUE], predictionStats[FALSE][FALSE]);
}
Example #13
0
static void DoBreakpoint(CONTEXT *ctxt, THREADID tid)
{
    if (IsFirstBreakpoint)
    {
        std::cout << "Tool stopping at breakpoint" << std::endl;
        IsFirstBreakpoint = FALSE;
        PIN_ApplicationBreakpoint(ctxt, tid, KnobWaitForDebugger.Value(), "The tool wants to stop");
    }
}
Example #14
0
/*
 Clear the cache flush count
*/
VOID InitFlushCount()
{
    string logFileName = KnobOutputFile.Value();
    if( KnobPid )
        logFileName += "." + decstr( getpid_portable() );
    SwooshFile.open(logFileName.c_str());
    flushes = 0;
    acks = 0;
}
int main(int argc, char **argv)
{
    if (PIN_Init(argc, argv))
    {
        Usage();
        return EXIT_FAILURE;
    }
    if (KnobAssertionNumber.Value() < 0 || KnobAssertionNumber.Value() > 2)
    {
        cerr << "Assertion number must be between 0 to 2" << endl;
        return EXIT_FAILURE;
    }

    INS_AddInstrumentFunction(Instruction, NULL);

    PIN_StartProgram();
    return EXIT_FAILURE;
}
static VOID ImageLoad(IMG img, VOID * v)
{
    if (IMG_IsMainExecutable(img))
    {
        // Find the placeholder for PIN_ExecuteAt
        RTN executeAtRtn = RTN_FindByName(img, "ExecuteAt");
        assert(RTN_Valid(executeAtRtn));

        // Find and application's ChangeRegisterValue function.
        RTN changeRegisterValueRtn = RTN_FindByName(img, "ChangeRegisterValue");
        assert(RTN_Valid(changeRegisterValueRtn));
        RTN_Open(changeRegisterValueRtn);
        if (KnobModificationMethod.Value() == "context")
        {
            RTN_InsertCall(changeRegisterValueRtn, IPOINT_BEFORE, AFUNPTR(ChangeRegisterAndExecute),
                                                                  IARG_CONTEXT,
                                                                  IARG_ADDRINT, RTN_Address(executeAtRtn),
                                                                  IARG_END);
        }
        else if (KnobModificationMethod.Value() == "partial")
        {
            REGSET regsin;
            REGSET regsout;
            REGSET_Clear(regsin);
            REGSET_Clear(regsout);
            REGSET_Insert(regsout, testedRegister);
            RTN_InsertCall(changeRegisterValueRtn, IPOINT_BEFORE, AFUNPTR(ChangeRegister),
                                                                  IARG_PARTIAL_CONTEXT, &regsin, &regsout,
                                                                  IARG_END);
        }
        else if (KnobModificationMethod.Value() == "reference")
        {
            RTN_InsertCall(changeRegisterValueRtn, IPOINT_BEFORE, AFUNPTR(ChangeRegisterReference),
                                                                  IARG_REG_REFERENCE, GetRegister(),
                                                                  IARG_END);
        }
        else
        {
            OutFile << "ERROR: Unknown modification method specified: " << KnobModificationMethod.Value() << endl;
            PIN_ExitApplication(12); // never returns
        }
        RTN_Close(changeRegisterValueRtn);
    }
}
Example #17
0
VOID ILDJIT_startLoop(THREADID tid, ADDRINT ip, ADDRINT loop) {
    // This is for when there are serial loops within an executing parallel loop.
    if (simulating_parallel_loop) {
        thread_state_t* tstate = get_tls(tid);
        lk_lock(&tstate->lock, tid + 1);
        tstate->ignore = true;
        lk_unlock(&tstate->lock);
    }

    string loop_string = (string)(char*) loop;

    // Increment invocation counter for this loop
    if (invocation_counts.count(loop_string) == 0) {
        invocation_counts[loop_string] = 0;
    } else {
        invocation_counts[loop_string]++;
    }

    if (KnobWarmLLC.Value()) {
        if ((!reached_warm_invocation) && (warm_loop == loop_string) &&
            (invocation_counts[loop_string] == warm_loop_invocation)) {
            assert(invocation_counts[loop_string] == warm_loop_invocation);
            cerr << "Called warmLoop() for the warm invocation!:" << loop_string << endl;
            reached_warm_invocation = true;
            cerr << "Detected that we need to warm!:" << loop_string << endl;
            cerr << "FastWarm runtime:";
            printElapsedTime();
            cerr << "Do late!" << endl;
            doLateILDJITInstrumentation();
            cerr << "Done late!" << endl;
        }
    }

    if ((!reached_start_invocation) && (start_loop == loop_string) &&
        (invocation_counts[loop_string] == start_loop_invocation)) {
        assert(invocation_counts[loop_string] == start_loop_invocation);
        cerr << "Called startLoop() for the start invocation!:" << loop_string << endl;
        reached_start_invocation = true;
        if (start_loop_iteration == (UINT32)-1) {
            cerr << "Detected that we need to start the next parallel loop!:" << loop_string
                 << endl;
            reached_start_iteration = true;
        }
    }

    if ((!reached_end_invocation) && (end_loop == loop_string) &&
        (invocation_counts[loop_string] == end_loop_invocation)) {
        assert(invocation_counts[loop_string] == end_loop_invocation);
        cerr << "Called startLoop() for the end invocation!:" << (CHAR*)loop << endl;
        reached_end_invocation = true;
        if (end_loop_iteration == (UINT32)-1) {
            cerr << "Detected that we need to end the next parallel loop!:" << loop_string << endl;
            reached_end_iteration = true;
        }
    }
}
int main(int argc, char * argv[])
{
    PIN_Init(argc, argv);

    Out.open(KnobOutputFile.Value().c_str());

    PIN_AddSignalInterceptFunction(SIGUSR1, SigFunc, 0);
    PIN_StartProgram();
    return 0;
}
Example #19
0
/* ================================================================== */
VOID InitCounters()
{
    string logFileName = KnobOutputFile.Value();
    if( KnobPid )
        logFileName += "." + decstr( getpid_portable() );
    TraceFile.open(logFileName.c_str());

    numJumpsIntoCodeCache = 0;
    numJumpsOutofCodeCache = 0;
}
Example #20
0
/* ===================================================================== */
VOID InitCounters()
{
    string logFileName = KnobOutputFile.Value();
    TraceFile.open(logFileName.c_str());

    insertions = 0;
    deletions = 0;
    readyToDelete = 0;
    hotAddress = 0x4000d8c0;
}
Example #21
0
 thread_data_t(THREADID tid) : calltrace(vector<TUP*>(BufferSize)), index(0) {
   string filename = KnobOutputFile.Value() + ".thread" + decstr(tid) ;
   _ofile.open(filename.c_str());
   if ( ! _ofile )
     {
       cerr << "Error: could not open output file." << endl;
       exit(1);
     }
   _ofile << hex;
 }
Example #22
0
BOOL TOOL_FollowChild(CHILD_PROCESS childProcess, VOID * userData) {

	INT pinArgc = 0;
    CHAR const * pinArgv[16];

    INT appArgc;
    CHAR const * const * appArgv;

    OS_PROCESS_ID pid = CHILD_PROCESS_GetId(childProcess);
	OS_PROCESS_ID ppid = WIND::GetCurrentProcessId();
    CHILD_PROCESS_GetCommandLine(childProcess, &appArgc, &appArgv);
	fprintf(trace, "[%d] Process is forking!!\n", ppid);
	fprintf(trace, "[%d] \t Child process (%s) with pid %d is executing\n", ppid, appArgv[0], pid);
	fflush(trace);

	// Begin
	string pin = KnobPinPath.Value() + "\\" + KnobPinName.Value();
	pinArgv[pinArgc++] = pin.c_str();
    
	//-xyzzy -mesgon warning
	pinArgv[pinArgc++] = "-xyzzy";
	pinArgv[pinArgc++] = "-mesgon";
	pinArgv[pinArgc++] = "warning";

	// Follow_exec
	pinArgv[pinArgc++] = "-follow_execv";
    
	// -t 
	pinArgv[pinArgc++] = "-t";
	string tool = (KnobToolPath.Value() + "\\" + KnobToolName.Value());
	pinArgv[pinArgc++] = tool.c_str();

	// -pin_path 
	pinArgv[pinArgc++] = "-pin_path";
	string pin_path = KnobPinPath.Value();
	pinArgv[pinArgc++] = pin_path.c_str();
	
	// -tool_path 
	pinArgv[pinArgc++] = "-tool_path";
	string tool_path = KnobToolPath.Value();
	pinArgv[pinArgc++] = tool_path.c_str();
	
	// -tool_name $(PINTOOL_FILE)
	pinArgv[pinArgc++] = "-tool_name";
	string tool_name = KnobToolName.Value();
	pinArgv[pinArgc++] = tool_name.c_str();

	// -firstprocess
	pinArgv[pinArgc++] = "-first_process";
	pinArgv[pinArgc++] = "0";

	// END
    pinArgv[pinArgc++] = "--";

    CHILD_PROCESS_SetPinCommandLine(childProcess, pinArgc, pinArgv);
    return TRUE;
}
Example #23
0
int main(int argc, char * argv[])
{
    PIN_Init(argc, argv);

    OutFile.open(KnobOutputFile.Value().c_str());

    PIN_AddFiniFunction(OnExit, 0);

    PIN_StartProgram();
    return 0;
}
static BOOL SigFunc(THREADID tid, INT32 sig, CONTEXT *ctxt, BOOL hasHndlr, VOID *)
{
    Out << "Got signal ";
    if (sig == SIGUSR1)
        Out << "SIGUSR1";
    else
        Out << "<signal " << std::dec << sig << ">";
    Out << std::endl;

    return KnobPassToApp.Value();
}
int main(int argc, char * argv[])
{
    PIN_Init(argc, argv);

    Out.open(KnobOut.Value().c_str());
    Out << std::dec << PIN_GetPid() << std::endl;
    Out.close();

    PIN_StartProgram();
    return 0;
}
Example #26
0
/* ===================================================================== */
LOCALFUN VOID OpenFile(THREADID tid)
{
    char num[100];
    if (KnobPid)
        sprintf(num, ".T.%u.%d.bbtrace", (unsigned)Pid, (int)tid);
    else
        sprintf(num, ".T.%d.bbtrace", (int)tid);
    string tname = num;
    profiles[tid]->BbFile.open((KnobOutputFile.Value()+tname).c_str());
    profiles[tid]->BbFile.setf(ios::showbase);
}
Example #27
0
//
// routine for openning output file
//
LOCALFUN VOID OpenOutputFile() {

  ResultFile.open(KnobResultFile.Value().c_str());
  ResultFile << dec << "N:" << N << " Threads: " << gThreadNum << " total_time:" << gWalltime  << endl;  
  ResultFile << "ws\t";
  for(TStamp j=0;j<MAX_THREAD;j++) {
    ResultFile << j+1 << "\t";
  }
  ResultFile << endl;

}
Example #28
0
    //! The pintool's entry point
    int main(int argc, char *argv[]) {
      PIN_InitSymbols();
      PIN_SetSyntaxIntel();
      if(PIN_Init(argc, argv))
          return Usage();

      /* Init the Triton module */
      triton::bindings::python::inittriton();

      /* Define Triton architecure */
      if (sizeof(void*) == QWORD_SIZE)
        tracer::pintool::api.setArchitecture(triton::arch::ARCH_X86_64);
      else
        tracer::pintool::api.setArchitecture(triton::arch::ARCH_X86);

      /* During the execution provide concrete values only if Triton needs them - cf #376, #632 and #645 */
      tracer::pintool::api.addCallback(tracer::pintool::context::needConcreteRegisterValue);
      tracer::pintool::api.addCallback(tracer::pintool::context::needConcreteMemoryValue);

      /* Image callback */
      IMG_AddInstrumentFunction(IMG_Instrumentation, nullptr);

      /* Instruction callback */
      TRACE_AddInstrumentFunction(TRACE_Instrumentation, nullptr);

      /* End instrumentation callback */
      PIN_AddFiniFunction(callbackFini, nullptr);

      /* Syscall entry callback */
      PIN_AddSyscallEntryFunction(callbackSyscallEntry, nullptr);

      /* Syscall exit callback */
      PIN_AddSyscallExitFunction(callbackSyscallExit, nullptr);

      /* Signals callback */
      PIN_InterceptSignal(SIGHUP,  callbackSignals, nullptr);
      PIN_InterceptSignal(SIGINT,  callbackSignals, nullptr);
      PIN_InterceptSignal(SIGQUIT, callbackSignals, nullptr);
      PIN_InterceptSignal(SIGILL,  callbackSignals, nullptr);
      PIN_InterceptSignal(SIGABRT, callbackSignals, nullptr);
      PIN_InterceptSignal(SIGFPE,  callbackSignals, nullptr);
      PIN_InterceptSignal(SIGKILL, callbackSignals, nullptr);
      PIN_InterceptSignal(SIGSEGV, callbackSignals, nullptr);
      PIN_InterceptSignal(SIGPIPE, callbackSignals, nullptr);
      PIN_InterceptSignal(SIGALRM, callbackSignals, nullptr);
      PIN_InterceptSignal(SIGTERM, callbackSignals, nullptr);
      PIN_InterceptSignal(SIGBUS,  callbackSignals, nullptr);

      /* Exec the Pin's python bindings */
      tracer::pintool::initBindings(argc, argv);
      tracer::pintool::execScript(KnobPythonModule.Value().c_str());

      return 0;
    }
Example #29
0
int main(int argc, char * argv[])
{
    PIN_InitSymbols();
    PIN_Init(argc, argv);
    
    TraceFile.open(KnobOutputFile.Value().c_str());

    IMG_AddInstrumentFunction(OnImage, 0);

    PIN_StartProgram();
    return 0;
}
Example #30
0
/* ===================================================================== */
VOID InitCounters()
{
    string logFileName = KnobOutputFile.Value();
    if( KnobPid )
        logFileName += "." + decstr( getpid_portable() );
    TraceFile.open(logFileName.c_str());

    insertions = 0;
    deletions = 0;
    readyToDelete = 0;
    hotAddress = 0x4000d8c0;
}