Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    if (PIN_Init(argc, argv)) return Usage();
    
    // Initialize the memory reference buffer
    bufId = PIN_DefineTraceBuffer(sizeof(struct MEMREF), NUM_BUF_PAGES,
                                  BufferFull, 0);

    if(bufId == BUFFER_ID_INVALID){
        cerr << "Error allocating initial buffer" << endl;
        return 1;
    }
    
    //int len=sizeof(struct MEMREF);
    //buf_ref=(struct MEMREF*)malloc(MAX_SIZE*len);

    trace = fopen("pinatrace.out", "w");
    outfile = fopen("buffer.out", "w");
    

    // add an instrumentation function
    TRACE_AddInstrumentFunction(Instruction, 0);
    PIN_AddFiniFunction(Fini, 0);

    // Never returns
    PIN_StartProgram();
    
    return 0;
}
int main(int argc, char * argv[])
{
    // Initialize pin
    PIN_Init(argc, argv);

    // Initialize the memory reference buffer
    bufId = PIN_DefineTraceBuffer(sizeof(PIN_MULTI_MEM_ACCESS_INFO), NUM_BUF_PAGES,
                                  BufferFull, 0);

    if(bufId == BUFFER_ID_INVALID)
    {
        fprintf (stderr, "Error allocating initial buffer\n");
        return 1;
    }

    // Register Instruction to be called to instrument instructions
    INS_AddInstrumentFunction(Instruction, 0);

    // Register function to be called when the application exits
    PIN_AddFiniFunction(Fini, 0);
    
    // Start the program, never returns
    PIN_StartProgram();
    
    return 0;
}
Ejemplo n.º 3
0
/*!
 * 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[])
{
    // 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();
    }
    
    // Initialize the memory reference buffer
    bufId1 = PIN_DefineTraceBuffer(sizeof(struct MEMREF), NUM_BUF_PAGES,
                                   BufferFull1, 0);
    if(bufId1 == BUFFER_ID_INVALID){
        cerr << "Error allocating initial buffer 1" << endl;
        return 1;
    }
    
    // Initialize the memory reference buffer
    bufId2 = PIN_DefineTraceBuffer(sizeof(struct MEMREF), NUM_BUF_PAGES,
                                   BufferFull2, 0);
    if(bufId2 == BUFFER_ID_INVALID){
        cerr << "Error allocating initial buffer 2" << endl;
        return 1;
    }
    
    outfile = fopen("two_buffers.out", "w");
    if(!outfile){
        cerr << "Couldn't open two_buffers.out" << endl;
        return 1;
    }

    PIN_InitLock(&fileLock);

    // add an instrumentation function
    TRACE_AddInstrumentFunction(Trace, 0);
    
    // Register function to be called when the application exits
    PIN_AddFiniFunction(Fini, 0);

    // Start the program, never returns
    PIN_StartProgram();
    
    return 0;
}
Ejemplo n.º 4
0
// -------------------------------------------------------------
// Tool startup function
// -------------------------------------------------------------
void STool_Run(STool_TSetup* s) {

    // make setup configuration globally available
    gSetup = *s;

    // extract application (path)name and full application command line
    for (int i=0; i<gSetup.argc-1;) 
        if (!strcmp("--", gSetup.argv[i++])) {
            int len = 0, j;
            for (j=i; j<gSetup.argc; ++j) len += strlen(gSetup.argv[j])+1;
            gAppName = gSetup.argv[i]; 
            gCommandLine = (char*)calloc(len, 1);
            if (gCommandLine == NULL) exit((printf("Can't allocate command line string\n"),1));
            strcat(gCommandLine, gSetup.argv[i]);
            for (j=i+1; j<gSetup.argc; ++j) {
                strcat(gCommandLine, " ");
                strcat(gCommandLine, gSetup.argv[j]);
            }
        }

    // initialize symbol table code, needed for rtn instrumentation
    PIN_InitSymbols();

    // initialize pin
    if (PIN_Init(gSetup.argc, gSetup.argv)) {
        Usage();
        return;
    }

    // obtain  a key for TLS storage.
    gTlsKey = PIN_CreateThreadDataKey(0);
    
    // if using memory operations buffering, define a BUF_SIZE-pages trace buffer 
    // and register BufferOverflow to be called when the buffer fills up
    if (gSetup.memBuf) buf_id = PIN_DefineTraceBuffer(sizeof(STool_TMemRec), BUF_SIZE, BufferOverflow, 0);

    // register ThreadStart to be called when a thread starts
    PIN_AddThreadStartFunction(ThreadStart, 0);

    // register ThreadEnd to be called when a thread ends
	PIN_AddThreadFiniFunction(ThreadEnd, 0);

    // register I_Trace to be called to instrument traces
    TRACE_AddInstrumentFunction(I_Trace, 0);
   
    // register Fini to be called when application exits
    if (gSetup.appEnd) PIN_AddFiniFunction(Fini, 0);

    // start the program, never returns
    PIN_StartProgram();
}