0

I have this global variable in my pintool and i want to get its content inside Instruction (my instrumentation function).

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

How can i do this? I've tried GLOBALVAR, LOCALVAR, const and static but nothing gave me back the correct value.

Orion Papadakis
  • 398
  • 1
  • 14

1 Answers1

0

A static global variable (at file scope) should work:

static UINT32 foo = 0;

Otherwise, you can use the second parameter of 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;
}

And in your instrumentation function, something along:

// 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);
}
Neitsa
  • 7,693
  • 1
  • 28
  • 45