I am using pin 3.0(build 76991) and visual studio 2012. I have tried the following to instrument routine entry to fill an entry in pin fast buffer
- Used RTN_InsertFillBuffer for the required routine during image instrumentation, but the compiler threw the error:
RTN_InsertFillBuffer identifier not found.
- Found the routine via comparing names in image instrumentation callback. Used
RTN_InsHead
to get the starting instruction. Then added anINS_InsertFillBuffer
on that instruction. But I got asegmentation fault
. ThePIN_DefineTraceBuffer
documentation says that the buffers are allocated implicitly when a thread starts. Now as pin does routine discovery statically and the program has not started when the images are being instrumented, so the buffer may not be allocated during image instrumentation and hence a call toINS_InsertFillBuffer
may give segmentation fault. I also tried allocating the buffer using PIN_AllocateBuffer in image instrumentation, but it was of no help. - Tried step 2 by routine instrumentation instead of Image instrumentation, but the same error persisted.
So how can I instrument the start of a routine to add an entry to the pin fast buffer ?
Code for 1st method:
Instrumentation Callback:
VOID Image(IMG img, VOID *v)
{
for (SYM sym = IMG_RegsymHead(img); SYM_Valid(sym); sym = SYM_Next(sym)){
string undFuncName = PIN_UndecorateSymbolName(SYM_Name(sym), UNDECORATION_NAME_ONLY);
if(!undFuncName.compare("RtlUnwind")){
RTN allocRtn = RTN_FindByAddress(IMG_LowAddress(img) + SYM_Value(sym));
RTN_InsertFillBuffer(allocRtn,IPOINT_BEFORE, bufId,
IARG_THREAD_ID, offsetof(BufferElement, tid),
IARG_FUNCARG_ENTRYPOINT_VALUE, 0, offsetof(BufferElement, exceptionUnwindingHaltPoint),
IARG_UINT32, SET_UNWIND_HALT, offsetof(BufferElement, entryType),
IARG_END);
}
}
}
Instrumentation:
IMG_AddInstrumentFunction(Image,0);
Code or 2nd method:
Instrumentation Callback:
VOID Image(IMG img, VOID *v)
{
for (SYM sym = IMG_RegsymHead(img); SYM_Valid(sym); sym = SYM_Next(sym)){
string undFuncName = PIN_UndecorateSymbolName(SYM_Name(sym), UNDECORATION_NAME_ONLY);
if(!undFuncName.compare("RtlUnwind")){
RTN allocRtn = RTN_FindByAddress(IMG_LowAddress(img) + SYM_Value(sym));
if (RTN_Valid(allocRtn)){
RTN_Open(allocRtn);
INS headIns = RTN_InsHeadOnly(allocRtn);
if(INS_Valid(headIns)){
INS_InsertFillBuffer(headIns,IPOINT_BEFORE, bufId,
IARG_THREAD_ID, offsetof(BufferElement, tid),
IARG_FUNCARG_ENTRYPOINT_VALUE, 0, offsetof(BufferElement, exceptionUnwindingHaltPoint),
IARG_UINT32, 12, offsetof(BufferElement, entryType),
IARG_END);
}
RTN_Close(allocRtn);
}
}
}
Instrumentation:
IMG_AddInstrumentFunction(Image,0);
Code for 3rd Method:
Instrumentation callback:
VOID Routine(RTN rtn, VOID *v){
if(RTN_Valid(rtn) && RTN_Name(rtn).compare("RtlUnwind")){
RTN_Open(rtn);
INS headIns = RTN_InsHeadOnly(rtn);
if(INS_Valid(headIns)){
INS_InsertFillBuffer(headIns,IPOINT_BEFORE, bufId,
IARG_THREAD_ID, offsetof(BufferElement, tid),
IARG_FUNCARG_ENTRYPOINT_VALUE, 0, offsetof(BufferElement, exceptionUnwindingHaltPoint),
IARG_UINT32, SET_UNWIND_HALT, offsetof(BufferElement, entryType),
IARG_END);
}
RTN_Close(rtn);
}
}
Instrumentation:
RTN_AddInstrumentFunction(Routine,0);