2016-10-11 6 views
0

이 pintool에이 전역 변수가 있고 그 내용을 Instruction (내 계측 기능) 안에 넣고 싶습니다.intel의 전역 변수 Pin

UINT32 windowCnt=0; 

LOCALFUN VOID Instruction(INS ins, VOID *v) 
{ 

    const AFUNPTR InsRefFun = ((wcount % 2)==0 ? (AFUNPTR) InsRef_Skip : (AFUNPTR) InsRef); 



    INS_InsertIfCall(
     ins, IPOINT_BEFORE, (AFUNPTR)InsRefFun, 
     IARG_THREAD_ID, 
     IARG_INST_PTR, 
     IARG_END); 
    ... 
} 

어떻게하면됩니까? 나는 GLOBALVAR, LOCALVAR, const 및 정적을 시도했지만 아무 것도 정확한 값을 돌려주지 않았습니다. (파일 범위에서)

답변

0

정적 전역 변수가 작동합니다 :

static UINT32 foo = 0; 

그렇지 않으면, 당신은 INS_AddInstrumentFunction의 두 번째 매개 변수를 사용할 수 있습니다

int main(int argc, char * argv[]) 
{ 
    // Initialize pin 
    if (PIN_Init(argc, argv)) return Usage(); 

    UINT32 foo = 0; 

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

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

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

    return 0; 
} 

그리고 당신의 계측 기능에

, 따라 뭔가 :

// Pin calls this function every time a new instruction is encountered 
VOID Instruction(INS ins, VOID *v) 
{ 
    if(v == NULL) 
     return; 

    UINT32 myfoo = *((UINT32*)v); //in c++: myFoo = *reinterptet_cast<UINT32*>(v) 

    // Insert a call to doSomething before every instruction, no arguments are passed 
    INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)doSomething, IARG_END); 
}