Skip to content

Commit

Permalink
Remove BPatch_addressSpace::findFunctionByAddr (#837)
Browse files Browse the repository at this point in the history
This was deprecated by 7f20129 in 2010. Users should instead use either
BPatch_addressSpace::findFunctionByEntry or
BPatch_addressSpace::findFunctionsByAddr.
  • Loading branch information
hainest committed Oct 16, 2020
1 parent e172b7a commit 3122580
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 49 deletions.
7 changes: 0 additions & 7 deletions dyninstAPI/h/BPatch_addressSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,6 @@ class BPATCH_DLL_EXPORT BPatch_addressSpace {
statement_iter getAddressRanges_begin(const char* file, unsigned long line);
statement_iter getAddressRanges_end(const char* file, unsigned long line);

// DEPRECATED:
// BPatch_addressSpace::findFunctionByAddr
//
// Returns the function containing an address

BPatch_function * findFunctionByAddr(void *addr);

// BPatch_addressSpace::findFunctionByEntry
//
// Returns the function starting at the given address
Expand Down
38 changes: 0 additions & 38 deletions dyninstAPI/src/BPatch_addressSpace.C
Original file line number Diff line number Diff line change
Expand Up @@ -681,44 +681,6 @@ BPatch_variableExpr *BPatch_addressSpace::createVariable(std::string name,
return varExpr;
}

/*
* BPatch_addressSpace::findFunctionByAddr
*
* Returns the function that contains the specified address, or NULL if the
* address is not within a function.
*
* addr The address to use for the lookup.
*/
BPatch_function *BPatch_addressSpace::findFunctionByAddr(void *addr)
{
std::vector<AddressSpace *> as;

getAS(as);
assert(as.size());
std::set<func_instance *> funcs;
if (!as[0]->findFuncsByAddr((Address) addr, funcs)) {
// if it's a mapped_object that has yet to be analyzed,
// trigger analysis and re-invoke this function
mapped_object *obj = as[0]->findObject((Address) addr);
if (obj &&
!obj->isAnalyzed()) {
obj->analyze();
return findFunctionByAddr(addr);
}
return NULL;
}
if (funcs.empty()) return NULL;

if (funcs.size() > 1) {
bpwarn("Warning: deprecated function findFunctionByAddr found "
"multiple functions sharing address 0x%lx, picking one at "
"random. Use findFunctionByEntry or findFunctionsByAddr\n",
addr);
}

return findOrCreateBPFunc((*(funcs.begin())), NULL);
}

/*
* BPatch_addressSpace::findFunctionByEntry
*
Expand Down
8 changes: 4 additions & 4 deletions dyninstAPI/src/BPatch_frame.C
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ BPatch_function *BPatch_frame::findFunction()
/*
* When we generate a BPatch_frame, we store the return address for the call
* as the PC. When we try to get the function associated with the frame, we
* use the PC to identify the function (via findFunctionByAddr). However, if
* use the PC to identify the function (via findFunctionByEntry). However, if
* the function made a non-returning call, the corresponding return address
* is never parsed, since it is unreachable code. This means that
* findFunctionByAddr will return NULL.
* findFunctionByEntry will return NULL.
*
* To compensate, we'll instead look up the function by the address of the
* callsite itself, which is the instruction prior to the return address.
* Because we do not know the length of the call instruction, we'll simply
* use PC-1, which is within the call instruction.
*/

void * callSite = (void*)((Address)(getPC()) - 1);
return thread->getProcess()->findFunctionByAddr(callSite);
Address callSite = reinterpret_cast<Address>(getPC()) - 1;
return thread->getProcess()->findFunctionByEntry(callSite);
}

BPatch_frame::BPatch_frame() :
Expand Down

0 comments on commit 3122580

Please sign in to comment.