本文整理汇总了C++中BPatch_function::getName方法的典型用法代码示例。如果您正苦于以下问题:C++ BPatch_function::getName方法的具体用法?C++ BPatch_function::getName怎么用?C++ BPatch_function::getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BPatch_function
的用法示例。
在下文中一共展示了BPatch_function::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Instrumentcall
void Instrumentcall (BPatch_image *appImage, BPatch_process *appProcess)
{
unsigned insertion = 0;
unsigned i = 0;
BPatch_Vector<BPatch_function *> *vfunctions = appImage->getProcedures (true);
cout << vfunctions->size() << " functions found in binary " << endl;
cout << "Parsing functions " << flush;
while (i < vfunctions->size())
{
char name[1024], sharedlibname[1024];
BPatch_function *f = (*vfunctions)[i];
(f->getModule())->getFullName (sharedlibname, 1024);
f->getName (name, 1024);
BPatch_Vector<BPatch_point *> *vpoints = f->findPoint (BPatch_subroutine);
unsigned j = 0;
while (j < vpoints->size())
{
BPatch_function *called = ((*vpoints)[j])->getCalledFunction();
if (NULL != called)
{
char calledname[1024];
called->getName (calledname, 1024);
if (strcmp (calledname, "functionB") == 0)
{
string s = "functionA";
BPatch_function *patch = getRoutine (s, appImage);
if (patch != NULL)
{
bool replaced = appProcess->replaceFunctionCall (*((*vpoints)[j]), *patch);
if (replaced)
cout << "call to functionA has been successfully replaced by a call to functionB" << endl;
else
cout << "call to functionA failed to replace a call to functionB" << endl;
insertion++;
}
}
}
j++;
}
i++;
}
cout << endl;
cout << "insertion = " << insertion << endl;
}
示例2: replaceFunctionCall
/*
* BPatch_addressSpace::replaceFunctionCall
*
* Replace a function call with a call to a different function. Returns true
* upon success, false upon failure.
*
* point The call site that is to be changed.
* newFunc The function that the call site will now call.
*/
bool BPatch_addressSpace::replaceFunctionCall(BPatch_point &point,
BPatch_function &newFunc)
{
char name[1024];
newFunc.getName(name, 1024);
// Can't make changes to code when mutations are not active.
if (!getMutationsActive())
return false;
assert(point.point && newFunc.lowlevel_func());
/* PatchAPI stuffs */
AddressSpace* addr_space = point.getAS();
DynModifyCallCommand* rep_call = DynModifyCallCommand::create(addr_space,
point.point->block(), newFunc.lowlevel_func(), point.point->func());
addr_space->patcher()->add(rep_call);
/* End of PatchAPI */
if (pendingInsertions == NULL) {
// Trigger it now
bool tmp;
finalizeInsertionSet(false, &tmp);
}
return true;
}
示例3: prepareCatchupInstr
void instrCodeNode::prepareCatchupInstr(pdvector<instReqNode *> &nodes_for_catchup)
{
if (instrCatchuped()) return;
for (unsigned instIter = 0; instIter < V.instRequests.size(); instIter++)
{
instReqNode *curInstReq = V.instRequests[instIter];
//prepareCatchupInstr_debug(V.instRequests[instIter]);
if (pd_debug_catchup) {
char buf[2048];
BPatch_function *bpf = const_cast<BPatch_function *>(curInstReq->Point()->getFunction());
if (! bpf) {
sprintf(buf, "<bad function> in instReq");
}
else
bpf->getName(buf, 2048);
cerr << " looking at instReq [" << instIter << "], in func: "
<< buf <<endl;
}
BPatchSnippetHandle *sh = curInstReq->snippetHandle();
}
// don't mark catchup as having completed because we don't want to mark
// this until the processMetFocusNode has completed initiating catchup for
// all of the threads
}
示例4: printCallingSites
static void printCallingSites (int id, int total, char *name, string sharedlibname, BPatch_Vector<BPatch_point *> *vpoints)
{
if (vpoints->size() > 0)
{
unsigned j = 0;
cout << id << " of " << total << " - Calling sites for " << name << " within " << sharedlibname << " (num = " << vpoints->size() << "):" << endl;
while (j < vpoints->size())
{
BPatch_function *called = ((*vpoints)[j])->getCalledFunction();
if (NULL != called)
{
char calledname[1024];
called->getName (calledname, 1024);
cout << j+1 << " Calling " << calledname;
BPatch_procedureLocation loc = ((*vpoints)[j])->getPointType();
if (loc == BPatch_entry)
cout << " (entry)" << endl;
else if (loc == BPatch_exit)
cout << " (exit)" << endl;
else if (loc == BPatch_subroutine)
cout << " (subroutine)" << endl;
else
cout << " (unknown point type)" << endl;
}
else
{
cout << j+1 << " Undetermined " << endl;
}
j++;
}
cout << endl;
}
}
示例5: BPatch_variableExpr
//
// findVariable
// scp - a BPatch_point that defines the scope of the current search
// name - name of the variable to find.
//
BPatch_variableExpr *BPatch_image::findVariableInScope(BPatch_point &scp,
const char *name)
{
// Get the function to search for it's local variables.
// XXX - should really use more detailed scoping info here - jkh 6/30/99
BPatch_function *func = const_cast<BPatch_function *> (scp.getFunction());
if (!func) {
pdstring msg = pdstring("point passed to findVariable lacks a function\n address point type passed?");
showErrorCallback(100, msg);
return NULL;
}
BPatch_localVar *lv = func->findLocalVar(name);
if (!lv) {
// look for it in the parameter scope now
lv = func->findLocalParam(name);
}
if (lv) {
// create a local expr with the correct frame offset or absolute
// address if that is what is needed
return new BPatch_variableExpr(proc, (void *) lv->getFrameOffset(),
lv->getRegister(), lv->getType(), lv->getStorageClass(), &scp);
}
// finally check the global scope.
// return findVariable(name);
/* If we have something else to try, don't report errors on this failure. */
bool reportErrors = true;
char mangledName[100];
func->getName( mangledName, 100 );
char * lastScoping = NULL;
if( strrchr( mangledName, ':' ) != NULL ) {
reportErrors = false;
}
BPatch_variableExpr * gsVar = findVariable( name, reportErrors );
if( gsVar == NULL ) {
/* Try finding it with the function's scope prefixed. */
if( (lastScoping = strrchr( mangledName, ':' )) != NULL ) {
* (lastScoping + sizeof(char)) = '\0';
char scopedName[200];
memmove( scopedName, mangledName, strlen( mangledName ) );
memmove( scopedName + strlen( mangledName ), name, strlen( name ) );
scopedName[ strlen( mangledName ) + strlen( name ) ] = '\0';
bperr( "Searching for scoped name '%s'\n", scopedName );
gsVar = findVariable( scopedName );
}
}
return gsVar;
}
示例6: instrumentModule
void instrumentModule(BPatch_module *module)
{
char funcname[BUFFER_STRING_LEN];
instrumentPLTSection(module);
std::vector<BPatch_function *>* functions;
functions = module->getProcedures();
for (unsigned i = 0; i < functions->size(); i++) {
BPatch_function *function = functions->at(i);
function->getName(funcname, BUFFER_STRING_LEN);
instrumentFunction(function);
}
}
示例7: ShowFunctions
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++;
}
}
示例8: handleModule
void handleModule(BPatch_module *mod, const char *name)
{
char funcname[BUFFER_STRING_LEN];
// get list of all functions
std::vector<BPatch_function *>* functions;
functions = mod->getProcedures();
// for each function ...
for (unsigned i = 0; i < functions->size(); i++) {
BPatch_function *function = functions->at(i);
function->getName(funcname, BUFFER_STRING_LEN);
printf(" FUNC: %s (%lx)\n", funcname, (unsigned long)function->getBaseAddr());
}
}
示例9: ShowFunctions
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++;
}
}
示例10: logerror
//
// Start Test Case #3 - (overload operator)
//
// static int mutatorTest(BPatch_thread *appThread, BPatch_image *appImage)
test_results_t test5_3_Mutator::executeTest() {
BPatch_Vector<BPatch_function *> bpfv;
const char *fn = "overload_op_test::func_cpp";
if (NULL == appImage->findFunction(fn, bpfv) || !bpfv.size()
|| NULL == bpfv[0]){
logerror("**Failed** test #3 (overloaded operation)\n");
logerror(" Unable to find function %s\n", fn);
return FAILED;
}
BPatch_function *f1 = bpfv[0];
BPatch_Vector<BPatch_point *> *point3_1 = f1->findPoint(BPatch_subroutine);
assert(point3_1);
if (point3_1->size() == 0) {
logerror("**Failed test5_3 (overload operation)\n");
logerror(" Can't find overloaded operator call points\n");
return FAILED;
}
unsigned int index = 0;
char fn3[256];
BPatch_function *func;
while (index < point3_1->size()) {
if ((func = (*point3_1)[index]->getCalledFunction()) != NULL &&
!strcmp("overload_op_test::operator++", func->getName(fn3, 256)))
{
break;
}
index ++;
}
if(!func) {
logerror("**Failed** test #3 (overload operation)\n");
logerror(" Can't find the overload operator\n");
return FAILED;
}
if (0 != strcmp("overload_op_test::operator++", func->getName(fn3, 256))) {
logerror("**Failed** test #3 (overload operation)\n");
logerror(" Can't find the overloaded operator\n");
return FAILED;
}
// FIXME It caught fprintf...
BPatch_Vector<BPatch_point *> *point3_2 = func->findPoint(BPatch_exit);
assert(point3_2);
bpfv.clear();
const char *fn2 = "overload_op_test::call_cpp";
if (NULL == appImage->findFunction(fn2, bpfv) || !bpfv.size()
|| NULL == bpfv[0]){
logerror("**Failed** test #3 (overloaded operation)\n");
logerror(" Unable to find function %s\n", fn2);
return FAILED;
}
BPatch_function *call3_1 = bpfv[0];
BPatch_variableExpr *this2 = appImage->findVariable("test5_3_test3");
if (this2 == NULL) {
logerror( "**Failed** test #3 (overloaded operation)\n");
logerror( "Unable to find variable \"test5_3_test3\"\n");
return FAILED;
}
BPatch_Vector<BPatch_snippet *> opArgs;
BPatch_arithExpr expr2_0(BPatch_addr, *this2);
opArgs.push_back(&expr2_0);
opArgs.push_back(new BPatch_retExpr());
BPatch_funcCallExpr call3_1Expr(*call3_1, opArgs);
checkCost(call3_1Expr);
appAddrSpace->insertSnippet(call3_1Expr, *point3_2);
// int tag = 1;
// while (tag != 0) {}
return PASSED;
}
示例11: main
int main (int argc, char **argv)
{
if(!parseOptions(argc,argv)) {
return EXIT_FAILURE;
}
BPatch bpatch;
BPatch_binaryEdit *appBin = bpatch.openBinary (originalBinary, !instrumentLibraries.empty());
if (appBin == NULL) {
cerr << "Failed to open binary" << endl;
return EXIT_FAILURE;
}
if (!appBin->loadLibrary (instLibrary)) {
cerr << "Failed to open instrumentation library." << endl;
cerr << "It needs to be located in the current working directory." << endl;
return EXIT_FAILURE;
}
BPatch_image *appImage = appBin->getImage ();
/* Find code coverage functions in the instrumentation library */
BPatch_function *initAflForkServer =
findFuncByName (appImage, (char *) "initAflForkServer");
BPatch_function *bbCallback =
findFuncByName (appImage, (char *) "bbCallback");
if (!initAflForkServer || !bbCallback ) {
cerr << "Instrumentation library lacks callbacks!" << endl;
return EXIT_FAILURE;
}
//get and iterate over all modules, instrumenting only the default and manualy specified ones
vector < BPatch_module * >*modules = appImage->getModules ();
vector < BPatch_module * >::iterator moduleIter;
BPatch_module *defaultModule = NULL;
string defaultModuleName;
for (moduleIter = modules->begin (); moduleIter != modules->end (); ++moduleIter) {
//find default module name
char moduleName[1024];
(*moduleIter)->getName (moduleName, 1024);
if (string (moduleName).find ("DEFAULT_MODULE") != string::npos) {
defaultModuleName = "DEFAULT_MODULE";
}
}
if(defaultModuleName.empty())
defaultModuleName = string(originalBinary).substr(string(originalBinary).find_last_of("\\/")+1);
int bbIndex = 0;
for (moduleIter = modules->begin (); moduleIter != modules->end (); ++moduleIter) {
char moduleName[1024];
(*moduleIter)->getName (moduleName, 1024);
if ((*moduleIter)->isSharedLib ()) {
if (instrumentLibraries.find (moduleName) == instrumentLibraries.end ()) {
cout << "Skipping library: " << moduleName << endl;
continue;
}
}
if (string (moduleName).find (defaultModuleName) != string::npos) {
defaultModule = (*moduleIter);
if(skipMainModule) continue;
}
cout << "Instrumenting module: " << moduleName << endl;
vector < BPatch_function * >*allFunctions =
(*moduleIter)->getProcedures ();
vector < BPatch_function * >::iterator funcIter;
// iterate over all functions in the module
for (funcIter = allFunctions->begin (); funcIter != allFunctions->end ();
++funcIter) {
BPatch_function *curFunc = *funcIter;
char funcName[1024];
curFunc->getName (funcName, 1024);
if(string (funcName) == string("_start")) continue; // here's a bug on hlt
insertBBCallback (appBin, curFunc, funcName, bbCallback, &bbIndex);
}
}
//if entrypoint set ,find function , else find _init
BPatch_function *funcToPatch = NULL;
if(!entryPoint) {
BPatch_Vector<BPatch_function*> funcs;
defaultModule->findFunction("_init", funcs);
if(!funcs.size()) {
cerr << "Couldn't locate _init, specify entry point manualy. "<< endl;
return EXIT_FAILURE;
}
// there should really be only one
funcToPatch = funcs[0];
} else {
funcToPatch = defaultModule->findFunctionByEntry(entryPoint);
}
if(!funcToPatch) {
cerr << "Couldn't locate function at given entry point. "<< endl;
return EXIT_FAILURE;
}
if(!insertCallToInit (appBin, initAflForkServer,defaultModule,funcToPatch)){
//.........这里部分代码省略.........
示例12: functionCall
//.........这里部分代码省略.........
BPatch_Vector<BPatch_point *> * functionCallPoints = instrumentedFunctions[0]->findPoint( BPatch_subroutine );
if (functionCallPoints->size() != 1) {
logerror("**Failed** test_stack_3\n");
logerror(" Unable to find subroutine call points in '%s'\n", fName);
appProc->terminateExecution();
return FAILED;
}
appProc->insertSnippet( functionCall, functionCallPoints[0] );
BPatch_Vector<BPatch_point *> * functionExitPoints = instrumentedFunctions[0]->findPoint( BPatch_exit );
if (functionExitPoints->size() != 1) {
logerror("**Failed** test_stack_3\n");
logerror(" Unable to find exit points in '%s'\n", fName);
appProc->terminateExecution();
return FAILED;
}
appProc->insertSnippet( functionCall, functionExitPoints[0] );
#if defined( DEBUG )
for( int i = 0; i < 80; i++ ) { ptrace( PTRACE_SINGLESTEP, appThread->getPid(), NULL, NULL ); }
for( int i = 80; i < 120; i++ ) {
ptrace( PTRACE_SINGLESTEP, appThread->getPid(), NULL, NULL );
BPatch_Vector<BPatch_frame> stack;
appThread->getCallStack( stack );
dprintf("single-step stack walk, %d instructions after stop for instrumentation.\n", i );
for( unsigned i = 0; i < stack.size(); i++ ) {
char name[ 40 ];
BPatch_function * func = stack[i].findFunction();
if( func == NULL ) { strcpy( name, "[UNKNOWN]" ); }
else { func->getName( name, 40 ); }
dprintf(" %10p: %s, fp = %p\n", stack[i].getPC(), name, stack[i].getFP() );
} /* end stack walk dumper */
dprintf("end of stack walk.\n" );
} /* end single-step iterator */
#endif /* defined( DEBUG ) */
/* After inserting the instrumentation, let it be called. */
appProc->continueExecution();
/* Wait for the mutatee to stop because of the instrumentation we just inserted. */
if (waitUntilStopped( bpatch, appProc, 1, "getCallStack through instrumentation (entry)") < 0) {
appProc->terminateExecution();
return FAILED;
}
passedTest = true;
if( !checkStack( appThread, correct_frame_info,
sizeof(correct_frame_info)/sizeof(frameInfo_t),
3, "getCallStack through instrumentation (entry)" ) ) {
passedTest = false;
}
/* Repeat for other two types of instpoints. */
appProc->continueExecution();
/* Wait for the mutatee to stop because of the instrumentation we just inserted. */
if (waitUntilStopped( bpatch, appProc, 1, "getCallStack through instrumentation (call)") < 0) {
appProc->terminateExecution();
return FAILED;
}
示例13: seqExpr
test_results_t test1_36_Mutator::executeTest()
{
const char *funcName = "test1_36_func1";
BPatch_Vector<BPatch_function *> found_funcs;
if ((NULL == appImage->findFunction(funcName, found_funcs))
|| !found_funcs.size())
{
logerror(" Unable to find function %s\n", funcName);
return FAILED;
}
if (1 < found_funcs.size())
{
logerror("%s[%d]: WARNING : found %d functions named %s. Using the first.\n",
__FILE__, __LINE__, found_funcs.size(), funcName);
}
BPatch_Vector<BPatch_point *> *all_points36_1 =
found_funcs[0]->findPoint(BPatch_subroutine);
if (!all_points36_1 || (all_points36_1->size() < 1))
{
logerror("Unable to find point %s - subroutines.\n", funcName);
return FAILED;
}
const char *funcName2 = "test1_36_call1";
BPatch_point *point36_1 = NULL;
for (unsigned i=0; i<(*all_points36_1).size(); i++)
{
BPatch_point *cur_point = (*all_points36_1)[i];
if (cur_point == NULL)
continue;
BPatch_function *func = cur_point->getCalledFunction();
char funcname[100];
if (!func)
continue;
if (func->getName(funcname, 99))
{
if (strstr(funcname, funcName2))
point36_1 = cur_point;
}
}
if (point36_1 == NULL)
{
logerror("Unable to find callsite %s\n", funcName2);
return FAILED;
}
BPatch_variableExpr *expr36_1 = findVariable(appImage,
"test1_36_globalVariable1",
all_points36_1);
BPatch_variableExpr *expr36_2 = findVariable(appImage,
"test1_36_globalVariable2",
all_points36_1);
BPatch_variableExpr *expr36_3 = findVariable(appImage,
"test1_36_globalVariable3",
all_points36_1);
BPatch_variableExpr *expr36_4 = findVariable(appImage,
"test1_36_globalVariable4",
all_points36_1);
BPatch_variableExpr *expr36_5 = findVariable(appImage,
"test1_36_globalVariable5",
all_points36_1);
BPatch_variableExpr *expr36_6 = findVariable(appImage,
"test1_36_globalVariable6",
all_points36_1);
BPatch_variableExpr *expr36_7 = findVariable(appImage,
"test1_36_globalVariable7",
all_points36_1);
BPatch_variableExpr *expr36_8 = findVariable(appImage,
"test1_36_globalVariable8",
all_points36_1);
BPatch_variableExpr *expr36_9 = findVariable(appImage,
"test1_36_globalVariable9",
all_points36_1);
BPatch_variableExpr *expr36_10 = findVariable(appImage,
"test1_36_globalVariable10",
all_points36_1);
if (expr36_1 == NULL || expr36_2 == NULL || expr36_3 == NULL ||
expr36_4 == NULL || expr36_5 == NULL || expr36_6 == NULL ||
expr36_7 == NULL || expr36_8 == NULL || expr36_9 == NULL ||
expr36_10 == NULL)
{
logerror("**Failed** test #36 (callsite parameter referencing)\n");
logerror(" Unable to locate at least one of "
"test1_36_globalVariable{1...10}\n");
return FAILED;
}
BPatch_Vector<BPatch_snippet *> snippet_seq;
snippet_seq.push_back(makeTest36paramExpr(expr36_1, 0));
snippet_seq.push_back(makeTest36paramExpr(expr36_2, 1));
//.........这里部分代码省略.........
示例14: readTracePipe
void readTracePipe()
{
int read_len;
char buf[ STRING_MAX ] = { '\0' };
if (config.pipefd < 0) return;
do {
errno = 0;
sendMsg(config.outfd, ID_TRACE_READ, DEBUG);
read_len = read(config.pipefd, buf, trace_msglen);
buf[trace_msglen] = '\0';
if (read_len < trace_msglen) {
if (read_len == -1 && errno == EAGAIN) {
// No data on pipe. Break out of read loop
// and re-poll for status change.
sendMsg(config.outfd, ID_TRACE_READ, DEBUG, ID_PASS);
break;
} else if (read_len == 0 && errno == 0) {
// Read EOF from pipefd. Close pipe and break.
sendMsg(config.outfd, ID_TRACE_READ, DEBUG, ID_PASS);
close(config.pipefd);
config.pipefd = -1;
break;
} else if (read_len > 0) {
// Partial data written to trace pipe. Report to monitor.
sendMsg(config.outfd, ID_TRACE_READ, DEBUG, ID_FAIL,
sprintf_static("Read partial message from trace pipe. Discarding message '%s'.", buf));
break;
} else if (errno) {
// Send error message to monitor.
sendMsg(config.outfd, ID_TRACE_READ, DEBUG, ID_FAIL,
sprintf_static("Mutator encountered error on trace pipe read(): %s", strerror(errno)));
close(config.pipefd);
config.pipefd = -1;
break;
}
}
void *traceMsg = (void *)strtol(buf, NULL, 16);
map< void *, BPatch_function * >::iterator iter = trace_points.find(traceMsg);
if (iter == trace_points.end()) {
sendMsg(config.outfd, ID_TRACE_READ, DEBUG, ID_FAIL,
sprintf_static("Read invalid message from trace pipe. 0x%s does not refer to a valid BPatch_point.", buf));
break;
}
sendMsg(config.outfd, ID_TRACE_READ, DEBUG, ID_PASS);
BPatch_point *point = (BPatch_point *)traceMsg;
const char *pType = "Unknown ";
if (point->getPointType() == BPatch_entry) pType = "Entering ";
if (point->getPointType() == BPatch_exit) pType = "Exiting ";
const char *pName = "anonymous function";
BPatch_function *pFunc = (*iter).second;
if (pFunc) {
if (pFunc->getName(buf, sizeof(buf)))
pName = sprintf_static("function %s", buf);
else
pName = sprintf_static("anonymous function at 0x%0*lx", sizeof(void *), pFunc->getBaseAddr());
}
if (config.pipefd > 0) {
// Could have been interrupted by mutatee exit.
sendMsg(config.outfd, ID_TRACE_POINT, INFO, ID_INFO, strcat_static(pType, pName));
}
} while (errno == 0);
}
示例15: InstrumentCalls
static void InstrumentCalls (BPatch_image *appImage, BPatch_addressSpace *appProcess,
ApplicationType *appType, set<string> &OMPset, set<string> &USERset,
map<string, vector<string> > & LoopLevels,
bool instrumentMPI, bool instrumentOMP, bool instrumentUF)
{
unsigned i = 0;
unsigned OMPinsertion = 0;
unsigned OMPreplacement_intel_v11 = 0;
unsigned MPIinsertion = 0;
unsigned APIinsertion = 0;
unsigned UFinsertion = 0;
const char *PMPI_C_prefix = "PMPI_";
const char *PMPI_F_prefix = "pmpi_";
const char *MPI_C_prefix = "MPI_";
const char *MPI_F_prefix= "mpi_";
cout << PACKAGE_NAME << ": Obtaining functions from application image (this may take a while)..." << flush;
BPatch_Vector<BPatch_function *> *vfunctions = appImage->getProcedures (false);
cout << "Done" << endl;
set<string> CUDAkernels;
/* Look for CUDA kernels if the application is CUDA */
if (appType->get_isCUDA())
{
cout << PACKAGE_NAME << ": Looking for CUDA kernels inside binary (this may take a while)..." << endl;
i = 0;
while (i < vfunctions->size())
{
char name[1024];
BPatch_function *f = (*vfunctions)[i];
f->getName (name, sizeof(name));
BPatch_Vector<BPatch_point *> *vpoints = f->findPoint (BPatch_subroutine);
if (vpoints != NULL)
{
unsigned j = 0;
while (j < vpoints->size())
{
BPatch_function *called = ((*vpoints)[j])->getCalledFunction();
if (NULL != called)
{
char calledname[1024];
called->getName (calledname, 1024);
if (strncmp (calledname, "__device_stub__", strlen("__device_stub__")) == 0)
{
CUDAkernels.insert (name);
if (VerboseLevel)
cout << PACKAGE_NAME << ": Found kernel " << name << endl;
}
}
j++;
}
}
i++;
}
cout << PACKAGE_NAME << ": Finished looking for CUDA kernels" << endl;
}
cout << PACKAGE_NAME << ": Parsing executable looking for instrumentation points (" << vfunctions->size() << ") ";
if (VerboseLevel)
cout << endl;
else
cout << flush;
/*
The 1st step includes:
a) gather information of openmp outlined routines (original is added to USERset),
b) instrument openmp outlined routines
c) instrument mpi calls
d) instrument api calls
*/
i = 0;
while (i < vfunctions->size())
{
char name[1024], sharedlibname_c[1024];
BPatch_function *f = (*vfunctions)[i];
(f->getModule())->getFullName (sharedlibname_c, sizeof(sharedlibname_c));
f->getName (name, sizeof(name));
string sharedlibname = sharedlibname_c;
string sharedlibname_ext;
if (sharedlibname.rfind('.') != string::npos)
sharedlibname_ext = sharedlibname.substr (sharedlibname.rfind('.'));
else
sharedlibname_ext = "";
/* For OpenMP apps, if the application has been linked with Extrae, just need to
instrument the function calls that have #pragma omp in them. The outlined
routines will be instrumented by the library attached to the binary */
if (!BinaryLinkedWithInstrumentation &&
instrumentOMP && appType->get_isOpenMP() && loadedModule != sharedlibname)
{
/* OpenMP instrumentation (just for OpenMP apps) */
//.........这里部分代码省略.........