2016-10-11 1 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の2番目のパラメータを使用することができます。

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); 
}