static void ShowFunctions (BPatch_image *appImage) { BPatch_Vector<BPatch_function *> *vfunctions = appImage->getProcedures (false); cout << PACKAGE_NAME << ": " << vfunctions->size() << " functions found in binary " << endl; unsigned i = 0; while (i < vfunctions->size()) { char name[1024]; BPatch_function *f = (*vfunctions)[i]; f->getName (name, 1024); if (VerboseLevel) { char mname[1024], tname[1024], modname[1024]; f->getMangledName (mname, 1024); f->getTypedName (tname, 1024); f->getModuleName (modname, 1024); cout << " * " << i+1 << " of " << vfunctions->size() << ", Name: " << name << endl << " Mangled Name: " << mname << endl << " Typed Name : " << tname << endl << " Module name : " << modname << endl << " Base address: " << f->getBaseAddr() << endl << " Instrumentable? " << (f->isInstrumentable()?"yes":"no") << endl << " In shared library? " << (f->isSharedLib()?"yes":"no") << endl << " Number of BB: " << getBasicBlocksSize(f) << endl; if (f->isSharedLib()) { char sharedlibname[1024]; BPatch_module *mod = f->getModule(); mod->getFullName (sharedlibname, 1024); cout << " Full library name: " << sharedlibname << endl; } cout << endl; } else { cout << name << endl; } i++; } }
static void ShowFunctions (BPatch_image *appImage) { BPatch_Vector<BPatch_function *> *vfunctions = appImage->getProcedures (false); cout << PACKAGE_NAME << ": " << vfunctions->size() << " functions found in binary " << endl; unsigned i = 0; while (i < vfunctions->size()) { char name[1024]; BPatch_function *f = (*vfunctions)[i]; f->getName (name, 1024); char mname[1024], tname[1024], modname[1024]; f->getMangledName (mname, 1024); f->getTypedName (tname, 1024); f->getModuleName (modname, 1024); cout << " * " << i+1 << " of " << vfunctions->size() << ", Name: " << name << endl << " Mangled Name: " << mname << endl << " Typed Name : " << tname << endl << " Module name : " << modname << endl << " Base address: " << f->getBaseAddr() << endl << " Instrumentable? " << (f->isInstrumentable()?"yes":"no") << endl << " In shared library? " << (f->isSharedLib()?"yes":"no") << endl; if (f->isSharedLib()) { //Old Dyninst API < 9.x //char sharedlibname[1024]; //mod->getFullName (sharedlibname, 1024); BPatch_module *mod = f->getModule(); string sharedlibname; sharedlibname = mod->getObject()->name(); cout << " Full library name: " << sharedlibname << endl; } cout << endl; i++; } }
static void GenerateSymFile (set<string> &ParFunc, set<string> &UserFunc, BPatch_image *appImage, BPatch_addressSpace *appProces) { ofstream symfile; string symname = string(::XML_GetFinalDirectory())+string("/")+string(::XML_GetTracePrefix())+".sym"; symfile.open (symname.c_str()); if (!symfile.good()) { cerr << "Cannot create the symbolic file" << symname << endl; return; } for (set<string>::iterator iter = ParFunc.begin(); iter != ParFunc.end(); iter++) { BPatch_function *f = getRoutine ((*iter).c_str(), appImage); if (f != NULL) { BPatch_Vector< BPatch_statement > lines; appProces->getSourceLines ((unsigned long) f->getBaseAddr(), lines); if (lines.size() > 0) { symfile << "P " << hex << f->getBaseAddr() << dec << " \"" << *iter << "\" \"" << lines[0].fileName() << "\" " << lines[0].lineNumber() << endl; } else { /* this happens if the application was not compiled with -g */ char modname[1024]; f->getModuleName (modname, 1024); symfile << "P " << hex << f->getBaseAddr() << dec << " \"" << *iter << "\" \"" << modname << "\" 0" << endl; } } } for (set<string>::iterator iter = UserFunc.begin(); iter != UserFunc.end(); iter++) { BPatch_function *f = getRoutine ((*iter).c_str(), appImage); if (f != NULL) { BPatch_Vector< BPatch_statement > lines; appProces->getSourceLines ((unsigned long) f->getBaseAddr(), lines); if (lines.size() > 0) { symfile << "U " << hex << f->getBaseAddr() << dec << " \"" << *iter << "\" \"" << lines[0].fileName() << "\" " << lines[0].lineNumber() << endl; } else { /* this happens if the application was not compiled with -g */ char modname[1024]; f->getModuleName (modname, 1024); symfile << "U " << hex << f->getBaseAddr() << dec << " \"" << *iter << "\" \"" << modname << "\" 0" << endl; } } } map<string, unsigned>::iterator BB_symbols_iter = BB_symbols->begin(); map<string, unsigned>::iterator BB_symbols_end = BB_symbols->end(); while(BB_symbols_iter != BB_symbols_end){ symfile << "b " << BB_symbols_iter->second << " \"" << BB_symbols_iter->first << "\"\n"; BB_symbols_iter++; } symfile.close(); }