Exemplo n.º 1
0
  bool Locality_Splitter::match_instance (
      uint32_t instance,
      const FILTER &filter) const
  {
    DANCEX11_LOG_TRACE ("Locality_Splitter::match_instance");

    // check if the node for the instance matches the filter
    bool match =
        filter.node ().empty () ||
          (filter.node () == this->plan_.instance ()[instance].node ());
    if (match)
      {
        // check if instance explicitly included or any allowed
        match = filter.included_instances ().empty () ||
                  filter.includes_instance (
                    this->plan_.instance ()[instance].node ());
      }
    return match;
  }
Exemplo n.º 2
0
/*
 Instrumentation function;
 Track the trace, the usage of the code in the bbls and the bbl exits
*/
VOID Trace(TRACE trace, VOID *v)
{
	
	  if (!filter.SelectTrace(trace))
        return;
    /* Add trace to db */
    Trace_Info(TRACE_Address(trace),
               TRACE_NumBbl(trace),
               TRACE_NumIns(trace));

    /* Inc. trace execution count */
    TRACE_InsertCall(trace, IPOINT_BEFORE,
                     (AFUNPTR) Trace_Info,
                     IARG_ADDRINT, TRACE_Address(trace),
                     IARG_UINT32, TRACE_NumBbl(trace),
                     IARG_UINT32, TRACE_NumIns(trace),
                     IARG_END);

    USIZE accum_code_size = 0;
    for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl))
    {
        accum_code_size += BBL_Size(bbl);

        /* Add bbl to db */
        Bbl_Info(BBL_Address(bbl),
                    BBL_NumIns(bbl),
                    TRACE_Address(trace),
                    BBL_Size(bbl),
                    accum_code_size);

        INS ins = BBL_InsTail(bbl);

        if (INS_IsBranchOrCall(ins) || INS_IsRet(ins))
        {
            /* Inc. bbl exit count */
            INS_InsertCall(ins, IPOINT_TAKEN_BRANCH,
                           (AFUNPTR) BblExit_Info,
                           IARG_ADDRINT, BBL_Address(bbl),
                           IARG_ADDRINT, TRACE_Address(trace),
                           IARG_END);
        }
    }

    /* Trace falloff in the case the bbl is too big and does not
       necessarily end with a bbl terminating op                */
    INS ins = BBL_InsTail(TRACE_BblTail(trace));
    if (! INS_IsBranchOrCall(ins))
    {
        /* Inc. trace falloff exit count */
        INS_InsertCall(ins, IPOINT_BEFORE,
                       (AFUNPTR) TraceFall_Info,
                       IARG_ADDRINT, TRACE_Address(trace),
                       IARG_END);
    }
}
Exemplo 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( unlikely(PIN_Init(argc,argv) ))
    {
        return Usage();
    }
    
    // Initialize the memory reference buffer;
    // set up the callback to process the buffer.
    //
    bufId = PIN_DefineTraceBuffer(sizeof(struct TRACEREF), KnobNumPagesInBuffer,
                                  BufferFull, 0);

    if(unlikely(bufId == BUFFER_ID_INVALID))
    {
        cerr << "Error: could not allocate initial buffer" << endl;
        return 1;
    }

   // Obtain  a key for TLS storage.
    mlog_key = PIN_CreateThreadDataKey(0);

    CODECACHE_AddCacheInitFunction(LimitTraces, 0);

    thread_ctx_ptr = PIN_ClaimToolRegister();
    ScratchReg = PIN_ClaimToolRegister();
    if (unlikely(!(REG_valid(thread_ctx_ptr) && REG_valid(ScratchReg))))
    {
        std::cerr << "Cannot allocate a scratch register.\n";
        std::cerr << std::flush;
        return 1;
    }


    // add callbacks
    PIN_AddThreadStartFunction(ThreadStart, 0);
    PIN_AddThreadFiniFunction(ThreadFini, 0);
    
    
        // add an instrumentation function
    TRACE_AddInstrumentFunction(Trace, 0);
    
    filter.Activate();

    // Start the program, never returns
    PIN_StartProgram();
    
    return 0;
}
Exemplo n.º 4
0
// Call every time a basic block is hit
VOID Trace(TRACE trace, VOID *v) {
  // Use filtering to select traces. See filter.H in $PIN_ROOT/source/tools/InstLib
  // for the possible options that can be used as a filter

  // I typically use the -filter_no_shared_libs option. Make sure that you
  // specify the tool before using this flag
  // (e.g., $PIN_ROOT/pin -t bb_trace.so -filter_no_shared_libs -- EXE ARGS) -JL
  if (!filter.SelectTrace(trace))
    return;
  
  for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl))
    {
      BBL_InsertCall(bbl, IPOINT_BEFORE, (AFUNPTR)printip, IARG_INST_PTR,
      IARG_UINT32, BBL_NumIns(bbl), IARG_UINT32, BBL_NumIns(bbl), IARG_END);
    }
}
Exemplo n.º 5
0
/*
 * Insert code to write data to a thread-specific buffer for instructions
 * that access memory.
 */
VOID Trace(TRACE trace, VOID *v)
{
    if (!filter.SelectTrace(trace))
        return;
       
    TRACE_InsertCall(trace, IPOINT_BEFORE, AFUNPTR(traceAddr),IARG_FAST_ANALYSIS_CALL, IARG_REG_VALUE, thread_ctx_ptr, IARG_END);
    ADDRINT trace_addr = TRACE_Address(trace);
    for(BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl=BBL_Next(bbl))
    {
    	INS ins = BBL_InsTail(bbl); //Last instruction of bbl
     
      if (INS_IsBranchOrCall(ins) || INS_IsRet(ins))
      {

    	  INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)setCJMP,
     	 		 IARG_CALL_ORDER, CALL_ORDER_FIRST,
     	 		 IARG_FAST_ANALYSIS_CALL,
     	 		 IARG_REG_VALUE, thread_ctx_ptr,
     	 		 IARG_ADDRINT, trace_addr,
                 IARG_BRANCH_TAKEN,
                 IARG_RETURN_REGS, ScratchReg,
                 IARG_END);

  //  	    thread_ctx_t *temp = reinterpret_cast<thread_ctx_t *>(thread_ctx_ptr);
            INS_InsertFillBuffer(ins, IPOINT_TAKEN_BRANCH, bufId,
            		                IARG_REG_VALUE, ScratchReg, offsetof(struct TRACEREF, traceId),
 	 	     	                                       //  IARG_UINT32, TraceCount, offsetof(struct TRACEREF, traceCount),
 	 	     	       	 	     	                     IARG_END);

     	 	/*
            INS_InsertFillBuffer(ins, IPOINT_TAKEN_BRANCH, bufId,
            		                                    // IARG_ADDRINT, ((TRACE_Address(trace) & 0x00ffffff)<<8), offsetof(struct TRACEREF, traceId),
            		                                       IARG_REG_VALUE, ScratchReg, offsetof(struct TRACEREF, traceId),
            		                                    //  IARG_UINT32, TraceCount, offsetof(struct TRACEREF, traceCount),
 	 	     	       	 	     	                     IARG_END);
           */
    	/*
   	 	INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR) setCJMP,
               IARG_FAST_ANALYSIS_CALL,
               IARG_BRANCH_TAKEN,
               IARG_END);
        INS_InsertFillBuffer(ins, IPOINT_TAKEN_BRANCH, bufId, IARG_ADDRINT, ((TraceAddr & 0x00ffffff)<<8|BBNumber), offsetof(struct TRACEREF, traceId), IARG_END);
        */
      }
    }
}
Exemplo n.º 6
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;
    
}
Exemplo n.º 7
0
// argc, argv are the entire command line, including pin -t <toolname> -- ...
int main(int argc, char * argv[])
{
    if( PIN_Init(argc,argv) )
    {
        return Usage();
    }

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

    TRACE_AddInstrumentFunction(Trace, 0);

    filter.Activate();

    PIN_AddFiniFunction(Fini, NULL);

    // Start the program, never returns
    PIN_StartProgram();
    return 0;
}
Exemplo n.º 8
0
/*
 Initialize and begin program execution under the control of Pin
*/
int main(INT32 argc, CHAR **argv)
{
    if( PIN_Init(argc,argv) )
    {
        return Usage();
    }
    
    CODECACHE_AddCacheInitFunction(LimitTraces, 0);
    
    TRACE_AddInstrumentFunction(Trace, 0);

    PIN_AddFiniFunction(DumpTraceInfo, 0);
    
    filter.Activate();
    
    PIN_StartProgram();
    
    return 0;
}
Exemplo n.º 9
0
int main(int argc, char * argv[])
{
    // Initialize pin
    if (PIN_Init(argc, argv)) return Usage();

    trace = fopen("cjmp-sequence.out", "w");

    // 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);
    
    filter.Activate();
    
    // Start the program, never returns
    PIN_StartProgram();
    
    return 0;
}
Exemplo n.º 10
0
// Pin calls this function every time a new basic block is encountered
// It inserts a call to docount
VOID Trace(TRACE trace, VOID *v)
{
   	  if (!filter.SelectTrace(trace))
        return;

    TRACE_InsertCall(trace, IPOINT_BEFORE, AFUNPTR(print2), IARG_FAST_ANALYSIS_CALL, IARG_ADDRINT, TRACE_Address(trace), IARG_END);
    // Visit every basic block  in the trace
    for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl))
    {
      
       INS ins = BBL_InsTail(bbl); //Last instruction of bbl
      if (INS_IsBranchOrCall(ins) || INS_IsRet(ins))
      {
     
           	 	INS_InsertIfCall(ins, IPOINT_BEFORE, (AFUNPTR) setCJMP,
                       IARG_FAST_ANALYSIS_CALL,
                       IARG_BRANCH_TAKEN,
                       IARG_END); 
             //IPOINT_TAKEN_BRANCH
              INS_InsertThenCall(ins, IPOINT_BEFORE, (AFUNPTR) print, IARG_END);          
      }
    }    
}
Exemplo n.º 11
0
VOID Trace(TRACE trace, VOID * val)
{
    if (!filter.SelectTrace(trace))
        return;

    for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl))
    {
        for (INS ins = BBL_InsHead(bbl); INS_Valid(ins); ins = INS_Next(ins))
        {
            out << hex << setw(8) << INS_Address(ins) << " ";

            RTN rtn = TRACE_Rtn(trace);
            if (RTN_Valid(rtn))
            {
                IMG img = SEC_Img(RTN_Sec(rtn));
                if (IMG_Valid(img)) {
                    out << IMG_Name(img) << ":" << RTN_Name(rtn) << " " ;
                }
            }

            out << INS_Disassemble(ins) << endl;
        }
    }
}
Exemplo n.º 12
0
/*
 * Insert code to write data to a thread-specific buffer for instructions
 * that access memory.
 */
VOID Trace(TRACE trace, VOID *v)
{
    if (!filter.SelectTrace(trace))
        return;
       
    TRACE_InsertCall(trace, IPOINT_BEFORE, AFUNPTR(traceAddr), IARG_FAST_ANALYSIS_CALL, IARG_ADDRINT, TRACE_Address(trace), IARG_END);
    for(BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl=BBL_Next(bbl))
    {
    	INS ins = BBL_InsTail(bbl); //Last instruction of bbl
    	
 /*   	if (INS_IsDirectBranch(ins) && INS_Category(ins) == XED_CATEGORY_COND_BR)
    		{
    			INS_InsertFillBuffer(ins, IPOINT_BEFORE, bufId,
                                         IARG_ADDRINT,INS_NextAddress(ins), offsetof(struct TRACEREF, pc),
                                        // IARG_ADDRINT, memOp, offsetof(struct TRACEREF, ea),
                                        // IARG_UINT32, refSize, offsetof(struct TRACEREF, size), 
                                         IARG_BOOL, TRUE, offsetof(struct TRACEREF, direct),
                                         IARG_END);
    		}
    	
    	else if( INS_IsIndirectBranchOrCall(ins) )
    		{
    			
                    INS_InsertFillBuffer(ins, IPOINT_BEFORE, bufId,
                                         IARG_ADDRINT,INS_NextAddress(ins), offsetof(struct TRACEREF, pc),
                                        // IARG_ADDRINT, memOp, offsetof(struct TRACEREF, ea),
                                        // IARG_UINT32, refSize, offsetof(struct TRACEREF, size), 
                                         IARG_BOOL, FALSE, offsetof(struct TRACEREF, direct),
                                         IARG_END);
    		} */
     
      if (INS_IsBranchOrCall(ins) || INS_IsRet(ins))
      {
     	 	INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR) setCJMP,
                 IARG_FAST_ANALYSIS_CALL,
                 IARG_BRANCH_TAKEN,
                 IARG_END);
     	 	if (BranchTaken)
     	 	{
     	 	 	 UINT32 addr_postfix = TraceAddr & 0x00ffffff;
     	 	 	 UINT32 trace_id = (addr_postfix<<8) | FLIP;
     	 	 	if(trace_id != PreviousTraceID)
     	 	 	{
     	 	 		if (TraceCount > 1)
     	 	 		{
     	 	     	 	INS_InsertFillBuffer(ins, IPOINT_BEFORE, bufId,
     	 	     	                                         IARG_ADDRINT,PreviousTraceID, offsetof(struct TRACEREF, traceId),
     	 	     	                                         IARG_UINT32,(TraceCount-1), offsetof(struct TRACEREF, traceCount),
     	 	     	       	 	     	                     IARG_END);
     	 	     	   TraceCount=1;
     	 	 		}

 	 	     	 	INS_InsertFillBuffer(ins, IPOINT_BEFORE, bufId,
 	 	     	                                         IARG_ADDRINT,trace_id, offsetof(struct TRACEREF, traceId),
 	 	     	                                         IARG_UINT32,TraceCount, offsetof(struct TRACEREF, traceCount),
 	 	     	       	 	     	                     IARG_END);
     	 	 	 PreviousTraceID = trace_id;
     	 	 	} // end of "if(trace_id != PreviousTraceID)"
     	 	 	else
     	 	 	{
     	 	 		TraceCount++;
     	 	 	}


     	 	 	TraceAddr=0;
     	 	 	MASK=0;
     	 	 	FLIP=0;
     	 	 	BranchTaken=0;
     	 	}
Exemplo n.º 13
0
/*
 * Insert code to write data to a thread-specific buffer for instructions
 * that access memory.
 */
VOID Trace(TRACE trace, VOID *v)
{
    if (!filter.SelectTrace(trace))
        return;
       
  //  TRACE_InsertCall(trace, IPOINT_BEFORE, AFUNPTR(traceAddr), IARG_FAST_ANALYSIS_CALL, IARG_ADDRINT, TRACE_Address(trace), IARG_END);
  /*
    BBL bbl = TRACE_BblHead(trace);
    if (BBL_Valid(bbl))
    {
    	INS ins = BBL_InsHead(bbl);
    	if(INS_Valid(ins))
    	{
    		INS_InsertFillBuffer(ins, IPOINT_BEFORE, bufId,
    		 	 	     	                                         IARG_ADDRINT, TRACE_Address(trace), offsetof(struct TRACEREF, traceId),
    		 	 	     	                                       //  IARG_UINT32, TraceCount, offsetof(struct TRACEREF, traceCount),
    		 	 	     	       	 	     	                     IARG_END);
    	}
    }
  */
    for(BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl=BBL_Next(bbl))
    {

    	INS ins = BBL_InsTail(bbl); //Last instruction of bbl
    /*
    	if(INS_Valid(ins))
    	{
    		INS_InsertFillBuffer(ins, IPOINT_BEFORE, bufId, IARG_ADDRINT, BBL_Address(bbl), offsetof(struct TRACEREF, traceId),  IARG_END);
    	}
    */
    
    
    	if (likely(INS_IsDirectBranch(ins) && INS_Category(ins) == XED_CATEGORY_COND_BR))
    	    		{
    		//INS_InsertFillBuffer(ins, IPOINT_BEFORE, bufId, IARG_ADDRINT, (BBL_Address(bbl) & 0x0fffffff <<4), offsetof(struct TRACEREF, traceId),  IARG_END);
    		ADDRINT DirectBranchTarget = INS_DirectBranchOrCallTargetAddress(ins);
    		INS_InsertFillBuffer(ins, IPOINT_TAKEN_BRANCH, bufId, IARG_ADDRINT, DirectBranchTarget, offsetof(struct TRACEREF, traceId),  IARG_END);
    		ADDRINT DirectBranchFallThrough = INS_NextAddress(ins);
    		INS_InsertFillBuffer(ins, IPOINT_AFTER, bufId, IARG_ADDRINT, DirectBranchFallThrough, offsetof(struct TRACEREF, traceId),  IARG_END);
    	    		}
    	else if(unlikely(INS_IsIndirectBranchOrCall(ins)))
    		//INS_InsertFillBuffer(ins, IPOINT_BEFORE, bufId, IARG_ADDRINT, ((BBL_Address(bbl) & 0x0fffffff <<4)|0x1), offsetof(struct TRACEREF, traceId),  IARG_END);
    		INS_InsertFillBuffer(ins, IPOINT_BEFORE, bufId, IARG_BRANCH_TARGET_ADDR, offsetof(struct TRACEREF, traceId),  IARG_END);
    }
    
    
        
      

 /*
    for(BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl=BBL_Next(bbl))
    {
    	INS ins = BBL_InsTail(bbl); //Last instruction of bbl
     
      if (INS_IsBranchOrCall(ins) || INS_IsRet(ins))
      {
     	 	INS_InsertIfCall(ins, IPOINT_BEFORE, (AFUNPTR) setCJMP,
                 IARG_FAST_ANALYSIS_CALL,
                 IARG_BRANCH_TAKEN,
                 IARG_END);
       INS_InsertFillBufferThen(ins, IPOINT_BEFORE, bufId,
 	 	     	                                         IARG_ADDRINT, TraceId, offsetof(struct TRACEREF, traceId),
 	 	     	                                       //  IARG_UINT32, TraceCount, offsetof(struct TRACEREF, traceCount),
 	 	     	       	 	     	                     IARG_END);

      }
    }
   */
}