【问题标题】:Global variable in intel Pin英特尔 Pin 中的全局变量
【发布时间】:2017-02-20 11:54:16
【问题描述】:

我的 pintool 中有这个全局变量,我想在指令(我的检测函数)中获取它的内容。

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 和 static,但没有任何东西给我正确的值。

【问题讨论】:

    标签: c++ global-variables global intel intel-pin


    【解决方案1】:

    静态全局变量(在文件范围内)应该可以工作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-30
      • 2018-07-30
      • 2018-04-20
      • 2018-05-17
      • 2020-10-23
      • 2014-11-09
      • 2019-06-28
      • 2019-03-03
      相关资源
      最近更新 更多