3 added code
source | link

You can pass an additional argument to INS_InsertPredicatedCall with the string name and construct a map with function names with (instruction, addr). Parse that map in PIN_AddFiniFunction added callback. Here's a simple example. Implement your mapping in RecordMemRead

map<string, vector<pair<UINT64, UINT64>>> RtnToRead;

VOID RecordMemRead(ADDRINT address, UINT64 memOp, std::string rname) {
 
    std::cout << std::hex << rname << " : " << RtnToRead[rname].pb(mp(address << " : " <<, memOp
              << endl;));
}

VOID Routine(RTN rtn, VOID *v) {

    RTN_Open(rtn);

    string name = RTN_Name(rtn);

    for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins)) {

        UINT32 memOperands = INS_MemoryOperandCount(ins);
 
        for (UINT32 memOp = 0; memOp < memOperands; memOp++) {
            if (INS_MemoryOperandIsRead(ins, memOp)) {
                INS_InsertPredicatedCall(ins, IPOINT_BEFORE,
                                         (AFUNPTR)RecordMemRead, IARG_INST_PTR,
                                         IARG_MEMORYOP_EA, memOp, IARG_PTR,
                                         new string(name), IARG_END);
            }
        }
    }

    RTN_Close(rtn);
}

VOID Fini(INT32 code, VOID *v) {
    for (auto &rtn : RtnToRead) {
        cout << rtn.fs << " :" << endl;
        for (auto &e : rtn.second) {
            cout << "\t" << hex << e.fs << " : " << e.sc << endl;
        }
    }
}

I have added a simple example here

EDIT : I have copied code from the gist which fits your case perfectly.

You can pass an additional argument to INS_InsertPredicatedCall with the string name and construct a map with function names with (instruction, addr). Parse that map in PIN_AddFiniFunction added callback. Here's a simple example. Implement your mapping in RecordMemRead

VOID RecordMemRead(ADDRINT address, UINT64 memOp, std::string rname) {
 
    std::cout << std::hex << rname << " : " << address << " : " << memOp
              << endl;
}

VOID Routine(RTN rtn, VOID *v) {

    RTN_Open(rtn);

    string name = RTN_Name(rtn);

    for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins)) {

        UINT32 memOperands = INS_MemoryOperandCount(ins);
 
        for (UINT32 memOp = 0; memOp < memOperands; memOp++) {
            if (INS_MemoryOperandIsRead(ins, memOp)) {
                INS_InsertPredicatedCall(ins, IPOINT_BEFORE,
                                         (AFUNPTR)RecordMemRead, IARG_INST_PTR,
                                         IARG_MEMORYOP_EA, memOp, IARG_PTR,
                                         new string(name), IARG_END);
            }
        }
    }

    RTN_Close(rtn);
}

I have added a simple example here

You can pass an additional argument to INS_InsertPredicatedCall with the string name and construct a map with function names with (instruction, addr). Parse that map in PIN_AddFiniFunction added callback. Here's a simple example. Implement your mapping in RecordMemRead

map<string, vector<pair<UINT64, UINT64>>> RtnToRead;

VOID RecordMemRead(ADDRINT address, UINT64 memOp, string rname) {
    RtnToRead[rname].pb(mp(address, memOp));
}

VOID Routine(RTN rtn, VOID *v) {

    RTN_Open(rtn);

    string name = RTN_Name(rtn);

    for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins)) {

        UINT32 memOperands = INS_MemoryOperandCount(ins);
        for (UINT32 memOp = 0; memOp < memOperands; memOp++) {
            if (INS_MemoryOperandIsRead(ins, memOp)) {
                INS_InsertPredicatedCall(ins, IPOINT_BEFORE,
                                         (AFUNPTR)RecordMemRead, IARG_INST_PTR,
                                         IARG_MEMORYOP_EA, memOp, IARG_PTR,
                                         new string(name), IARG_END);
            }
        }
    }

    RTN_Close(rtn);
}

VOID Fini(INT32 code, VOID *v) {
    for (auto &rtn : RtnToRead) {
        cout << rtn.fs << " :" << endl;
        for (auto &e : rtn.second) {
            cout << "\t" << hex << e.fs << " : " << e.sc << endl;
        }
    }
}

I have added a simple example here

EDIT : I have copied code from the gist which fits your case perfectly.

2 added 120 characters in body
source | link

You can pass an additional argument to INS_InsertPredicatedCall with the string name and construct a map with function names with (instruction, addr). Parse that map in PIN_AddFiniFunction added callback. Here's a simple example. Implement your mapping in RecordMemRead

VOID RecordMemRead(ADDRINT address, UINT64 memOp, std::string rname) {

    std::cout << std::hex << rname << " : " << address << " : " << memOp
              << endl;
}

VOID Routine(RTN rtn, VOID *v) {

    RTN_Open(rtn);

    string name = RTN_Name(rtn);

    for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins)) {

        UINT32 memOperands = INS_MemoryOperandCount(ins);

        for (UINT32 memOp = 0; memOp < memOperands; memOp++) {
            if (INS_MemoryOperandIsRead(ins, memOp)) {
                INS_InsertPredicatedCall(ins, IPOINT_BEFORE,
                                         (AFUNPTR)RecordMemRead, IARG_INST_PTR,
                                         IARG_MEMORYOP_EA, memOp, IARG_PTR,
                                         new string(name), IARG_END);
            }
        }
    }

    RTN_Close(rtn);
}

I have added a simple example here

You can pass an additional argument to INS_InsertPredicatedCall with the string name and construct a map with function names with (instruction, addr). Parse that map in PIN_AddFiniFunction added callback. Here's a simple example. Implement your mapping in RecordMemRead

VOID RecordMemRead(ADDRINT address, UINT64 memOp, std::string rname) {

    std::cout << std::hex << rname << " : " << address << " : " << memOp
              << endl;
}

VOID Routine(RTN rtn, VOID *v) {

    RTN_Open(rtn);

    string name = RTN_Name(rtn);

    for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins)) {

        UINT32 memOperands = INS_MemoryOperandCount(ins);

        for (UINT32 memOp = 0; memOp < memOperands; memOp++) {
            if (INS_MemoryOperandIsRead(ins, memOp)) {
                INS_InsertPredicatedCall(ins, IPOINT_BEFORE,
                                         (AFUNPTR)RecordMemRead, IARG_INST_PTR,
                                         IARG_MEMORYOP_EA, memOp, IARG_PTR,
                                         new string(name), IARG_END);
            }
        }
    }

    RTN_Close(rtn);
}

You can pass an additional argument to INS_InsertPredicatedCall with the string name and construct a map with function names with (instruction, addr). Parse that map in PIN_AddFiniFunction added callback. Here's a simple example. Implement your mapping in RecordMemRead

VOID RecordMemRead(ADDRINT address, UINT64 memOp, std::string rname) {

    std::cout << std::hex << rname << " : " << address << " : " << memOp
              << endl;
}

VOID Routine(RTN rtn, VOID *v) {

    RTN_Open(rtn);

    string name = RTN_Name(rtn);

    for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins)) {

        UINT32 memOperands = INS_MemoryOperandCount(ins);

        for (UINT32 memOp = 0; memOp < memOperands; memOp++) {
            if (INS_MemoryOperandIsRead(ins, memOp)) {
                INS_InsertPredicatedCall(ins, IPOINT_BEFORE,
                                         (AFUNPTR)RecordMemRead, IARG_INST_PTR,
                                         IARG_MEMORYOP_EA, memOp, IARG_PTR,
                                         new string(name), IARG_END);
            }
        }
    }

    RTN_Close(rtn);
}

I have added a simple example here

1
source | link

You can pass an additional argument to INS_InsertPredicatedCall with the string name and construct a map with function names with (instruction, addr). Parse that map in PIN_AddFiniFunction added callback. Here's a simple example. Implement your mapping in RecordMemRead

VOID RecordMemRead(ADDRINT address, UINT64 memOp, std::string rname) {

    std::cout << std::hex << rname << " : " << address << " : " << memOp
              << endl;
}

VOID Routine(RTN rtn, VOID *v) {

    RTN_Open(rtn);

    string name = RTN_Name(rtn);

    for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins)) {

        UINT32 memOperands = INS_MemoryOperandCount(ins);

        for (UINT32 memOp = 0; memOp < memOperands; memOp++) {
            if (INS_MemoryOperandIsRead(ins, memOp)) {
                INS_InsertPredicatedCall(ins, IPOINT_BEFORE,
                                         (AFUNPTR)RecordMemRead, IARG_INST_PTR,
                                         IARG_MEMORYOP_EA, memOp, IARG_PTR,
                                         new string(name), IARG_END);
            }
        }
    }

    RTN_Close(rtn);
}