Search code examples
intel-pin

How to find RTN by name in pintool?


I use RTN_FindByName() to search for a specific RTN, but it didn't work with me, moreover i try to force the compiler to not inline the RTN, but still not working,
test code:

void __attribute__ ((noinline)) MyFunInApp() 
{
  printf(" function inside application environmental \n");
}

code in pintool:

VOID ImageLoad(IMG img, VOID *v)
 {
   RTN MyRtn = RTN_FindByName(img,"MyFunInApp");
   if (RTN_Valid(MyRtn))
    {
      cout<< "Found RTN"<< endl;
    }
    else
    {
      cout<< "Not Found RTN"<< endl;
    }
}

How can i fix that, or do that by another way ?

Compiler: gcc version 4.8
C++ Language
O.S : Ubuntu 14.04 LTS, 64-bit
Output (of test code) :
Not Found RTN
Not Found RTN
Not Found RTN


Solution

  • What you're seeing (the function name wrapped with characters) is called function name decoration/mangling. It's the way that C++ implements overloading natively. Unfortunately mangling isn't standardized and every compiler does it differently.

    You can either look for the mangled name, or alternatively iterate over the rtns in an image (you can see samples in the kit on how to do this) and use Pin's PIN_UndecorateSymbolName API to get the clean function name. Just remember that due to mangling you may get more than one such symbol.