void FollowChild(THREADID threadid, const CONTEXT* ctxt, VOID * arg)
{
	char *new_name;
	int x;

	std::cerr << "New child " << PIN_GetPid() << std::endl;

	x = asprintf(&new_name, "%s_%d", KnobOutfile.Value().c_str(), PIN_GetPid());

	fout.close();
	fout.open(new_name, std::ios_base::out);

	free(new_name);

	(void)x;
	// fout.open(KnobOutfile.Value().c_str(), std::ios_base::out|std::ios_base::app);
	// assert(fout.is_open());
}
 void handle_fork_before (THREADID thr_id, const OASIS::Pin::Const_Context &)
 {
   do
   {
     OASIS::Pin::Guard <OASIS::Pin::Lock> (this->lock_, thr_id + 1);
     std::cerr << "TOOL: Before fork." << std::endl;
   } while (false);
   
   this->parent_pid_ = PIN_GetPid ();
 }
Esempio n. 3
0
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;
}
 void handle_fork_after_in_parent (THREADID thr_id, const OASIS::Pin::Const_Context &)
 {
   do
   {
     OASIS::Pin::Guard <OASIS::Pin::Lock> (this->lock_, thr_id + 1);
     std::cerr << "TOOL: After fork in parent." << std::endl;
   } while (false);
   
   if (PIN_GetPid () != this->parent_pid_)
   {
     std::cerr << "PIN_GetPid () fails in parent process" << std::endl;
     exit (-1);
   }    
 }
//--------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{    
    time(&m_StartTime); 

    // 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))
    {
        return Usage();
    }

    cerr << APP_NAME;

    for (int i = 0; i < argc; i++)
    {
        m_CommandLine += argv[i];
        m_CommandLine += " ";
    }

    m_ProcessId = PIN_GetPid();

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

    // Register function to be called for every loaded module
    IMG_AddInstrumentFunction(ImageLoad, 0);

    // Register functions to be called for every thread starting and termination
    PIN_AddThreadStartFunction(ThreadStart, 0);
    PIN_AddThreadFiniFunction(ThreadEnd, 0);

    // Register function to be called when the application exits
    PIN_AddFiniFunction(Fini, 0);
    
    cerr << "Starting application..." << endl;

    // Start the program, never returns
    PIN_StartProgram();
    
    return 0;
}
Esempio n. 6
0
int main (int argc, char *argv[])
{
	char buff[20];

	if(PIN_Init(argc,argv)) {
		printf("command line error\n");
		return 1;
	}

	pid = PIN_GetPid();

	sprintf(buff, "ct%d.log", pid);
	logfp = fopen(buff, "w");
	if (logfp == NULL) {
		printf("cannot open '%s' for writing\n", buff);
		return 1;
	}

	sprintf(buff, "ct%d.trace", pid);
	if (tb_create(buff)) {
		fprintf(logfp, "tb_create() failed\n");
		fflush(logfp);
		return 1;
	}

	PIN_AddFiniFunction(fini, 0);
	PIN_AddThreadStartFunction(thread_start, 0);
	PIN_AddThreadFiniFunction(thread_fini, 0);
	IMG_AddInstrumentFunction(img_load, NULL);
	IMG_AddUnloadFunction(img_unload, NULL);
	TRACE_AddInstrumentFunction(trace, NULL);
	INS_AddInstrumentFunction(instruction, NULL);
	PIN_AddSyscallEntryFunction(sys_enter, NULL);
	PIN_AddSyscallExitFunction(sys_exit, NULL);
	PIN_AddContextChangeFunction(context_switch, NULL);

	PIN_InitSymbols();

	PIN_StartProgram(); // Never returns
	return 0;
}