I'm trying to track how many times certain basic blocks are executed by inserting a clean call that increments an array of counters.
But my clean call is being inserted multiple times for the same basic block?
How do I prevent this?
My callback is being registered with drmgr_register_bb_instrumentation_event
My DynamoRIO client code
|
|
v
static dr_emit_flags_t
event_app_instruction(void* drcontext, void* tag, instrlist_t* bb, instr_t* inst,
bool for_trace, bool translating, void* user_data)
{
if (drmgr_is_first_instr(drcontext, inst))
{
for (int i = 0; i < MAX_ENTRIES && bbList[i] != NULL; i++)
{
if (instr_get_app_pc(inst) == bbList[i])
{
// (?) weirdly this is hitting multiple times for the same basic block over the course of the program's lifetime
dr_printf("first: %p second: %p\n", bbList[i], instr_get_app_pc(inst));
dr_insert_clean_call(drcontext, bb, inst, incrementCounters, false, 1, OPND_CREATE_INT32(i));
dr_printf("Found match!\n");
}
}
}
return DR_EMIT_DEFAULT;
}