/* * Copyright 2002-2019 Intel Corporation. * * This software is provided to you as Sample Source Code as defined in the accompanying * End User License Agreement for the Intel(R) Software Development Products ("Agreement") * section 1.L. * * This software and the related documents are provided as is, with no express or implied * warranties, other than those that are expressly stated in the License. */ /* * Check interface PIN_UndecorateSymbolName() * */ #include #include #include #include #include "pin.H" using std::ofstream; using std::cout; using std::string; using std::endl; KNOB KnobOutput(KNOB_MODE_WRITEONCE,"pintool", "o", "undecorate.out", "Name for log file"); KNOB KnobVerbose(KNOB_MODE_WRITEONCE,"pintool", "v", "0", "Verbose output to log file"); static ofstream out; // Define the names we expect to demangle static struct { const string fullName; const string noArgsName; } testNames[] = { {"A MyMethod(A&)", "MyMethod" }, {"A::MyMethod1(std::vector > const&)", "A::MyMethod1"}, {"A::MyMethod2(std::string)","A::MyMethod2"}, {"MyMethod1::MyMethod1()","MyMethod1::MyMethod1"}, {"A::MyMethod3(std::string) const","A::MyMethod3"}, {"Foo()","Foo"}, {"int my_operator(int const&)", "my_operator"} }; VOID ImageLoad(IMG img, VOID *v) { for (SEC sec = IMG_SecHead(img); SEC_Valid(sec); sec = SEC_Next(sec) ) { for (RTN rtn = SEC_RtnHead(sec); RTN_Valid(rtn); rtn = RTN_Next(rtn) ) { string rtnName = RTN_Name(rtn); if (rtnName.find("MyMethod") != string::npos || rtnName.find("Foo") != string::npos || rtnName.find("my_operator") != string::npos) { // The tested application has class "A" with interface "MyMethod" // We just check that A::MyMethod is successfully demangled string demangledName = PIN_UndecorateSymbolName(rtnName, UNDECORATION_COMPLETE); string demangledNameNoParams = PIN_UndecorateSymbolName(rtnName, UNDECORATION_NAME_ONLY); out << "Mangled name: " << rtnName << endl; out << "Full demangled name: " << demangledName << endl; out << "Demangled name w/o parameters: " << demangledNameNoParams << endl; BOOL matched = FALSE; for (UINT32 i=0; i " << endl; out << " " << complete << endl; out << " " << nameOnly << endl; } } } } int main(INT32 argc, CHAR **argv) { PIN_InitSymbols(); PIN_Init(argc, argv); out.open(KnobOutput.Value().c_str()); IMG_AddInstrumentFunction(ImageLoad, 0); // Never returns PIN_StartProgram(); return 0; }