Skip to content

Commit

Permalink
Add dyninstAPI/src/BPatch_point.C
Browse files Browse the repository at this point in the history
  • Loading branch information
hainest committed Apr 3, 2024
1 parent ad4d447 commit a974546
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 122 deletions.
50 changes: 45 additions & 5 deletions docs/dyninstAPI/developer/BPatch_point.h.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ BPatch_point.h
how the internals represent a point (e.g., pre-instruction). We handle this here with
a secondary instPoint that is defined to be the "after" equivalent.

.. cpp:function:: private void overrideType(BPatch_procedureLocation loc)

We often create a point with the arbitrary point type, and later need to override
it to a specific type (e.g., loop entry)

.. cpp:member:: private Dyninst::PatchAPI::InstancePtr dynamic_point_monitor_func

a snippet used in monitoring of dynamic calls maybe we want BPatchSnippetHandle here

.. cpp:member:: private BPatch_addressSpace *addSpace
.. cpp:member:: private AddressSpace *lladdSpace
.. cpp:member:: private BPatch_function *func
.. cpp:member:: private BPatch_basicBlockLoop *loop
.. cpp:member:: private instPoint *secondaryPoint
.. cpp:member:: private BPatch_procedureLocation pointType
.. cpp:member:: private BPatch_memoryAccess *memacc
.. cpp:member:: private BPatch_edge *edge_
.. cpp:member:: private BPatch_Vector<BPatchSnippetHandle *> preSnippets
.. cpp:member:: private BPatch_Vector<BPatchSnippetHandle *> postSnippets
.. cpp:member:: private BPatch_Vector<BPatchSnippetHandle *> allSnippets

.. cpp:function:: BPatch_edge *edge() const

Hack to get edge information. DO NOT USE.
Expand All @@ -35,3 +42,36 @@ BPatch_point.h
.. cpp:function:: BPatch_addressSpace * getAddressSpace()

Added for DynC...

.. cpp:function:: int getDisplacedInstructions(int maxSize, void *insns)

Does nothing.

.. cpp:function:: private BPatch_point(BPatch_addressSpace *_addSpace, BPatch_function *_func, instPoint *_point, instPoint *_secondary, BPatch_procedureLocation _pointType, AddressSpace *as)
.. cpp:function:: private BPatch_point(BPatch_addressSpace *_addSpace, BPatch_function *_func, BPatch_edge *_edge, instPoint *_point, AddressSpace *as)

.. cpp:function:: private void setLoop(BPatch_basicBlockLoop *l)

For a ``BPatch_point`` representing a loop instrumentation site, set the loop that it represents.

We currently can use a single BPatch_point to represent multiple loops. This is a problem, since we
would really like the points to label a unique loop. On the other hand, then multiple points would
share the same physical address.. not good.

.. cpp:function:: private void overrideType(BPatch_procedureLocation loc)

We often create a point with the arbitrary point type, and later need to override
it to a specific type (e.g., loop entry)


.. cpp:function:: private instPoint *getPoint() const
.. cpp:function:: private instPoint *getPoint(BPatch_callWhen when) const
.. cpp:function:: private void recordSnippet(BPatch_callWhen, BPatch_snippetOrder, BPatchSnippetHandle *)
.. cpp:function:: private void attachMemAcc(BPatch_memoryAccess *memacc)
.. cpp:function:: private AddressSpace *getAS()

.. cpp:function:: private bool removeSnippet(BPatchSnippetHandle *handle)

Removes snippet from data structures, doesn't remove the instrumentation.

It is invoked by :cpp:func:`BPatch_addressSpace::deleteSnippet`.
38 changes: 22 additions & 16 deletions docs/dyninstAPI/public/BPatch_point.h.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BPatch_point.h

.. cpp:function:: BPatch_procedureLocation getPointType()

Return the type of the point.
Returns the type of the point.

.. cpp:function:: BPatch_function* getFunction()

Expand All @@ -27,7 +27,7 @@ BPatch_point.h

.. cpp:function:: BPatch_function* getCalledFunction()

Return a BPatch_function representing the function that is called at the
Returns a BPatch_function representing the function that is called at the
point. If the point is not a function call site or the target of the
call cannot be determined, then this function returns NULL.

Expand All @@ -43,11 +43,13 @@ BPatch_point.h

.. cpp:function:: BPatch_basicBlock* getBlock()

BPatch_point::getBlock Returns block to which this point belongs if such a block exists For example, function entry points do not have blocks associated with them.
Returns the block to which this point belongs, if it exists.

For example, function entry points do not have blocks associated with them.

.. cpp:function:: void* getAddress()

Return the address of the first instruction at this point.
Returns the address of the first instruction at this point.

.. cpp:function:: const BPatch_memoryAccess* getMemoryAccess()

Expand All @@ -63,7 +65,7 @@ BPatch_point.h

.. cpp:function:: const BPatch_Vector<BPatchSnippetHandle*> getCurrentSnippets(BPatch_callWhen when)

Return the BPatchSnippetHandles for the BPatch_snippets that are associated with the point.
Returns the BPatchSnippetHandles for the BPatch_snippets that are associated with the point.

If argument when is BPatch_callBefore, then
BPatchSnippetHandles for snippets installed immediately before this
Expand All @@ -84,28 +86,27 @@ BPatch_point.h

.. cpp:function:: void* monitorCalls(BPatch_function *f = NULL)

Inserts a call to the user-defined callback ``f`` at a dynamic call site.

For a dynamic call site, this call instruments the call site represented
by this instrumentation point with a function call. If input parameter
func is not NULL, func is called at the call site as the
instrumentation. If func is NULL, the callback function registered with
BPatch::registerDynamicCallCallback is used for instrumentation. Under
both cases, this call returns a pointer to the called function. If the
instrumentation point does not represent a dynamic call site, this call
returns NULL.
func is not NULL, func is called at the call site as the instrumentation.

If ``f`` is ``NULL``, the callback function registered with
:cpp:func:`BPatch::registerDynamicCallCallback` is used for instrumentation.

Returns ``NULL`` if the instrumentation point does not represent a dynamic call site.

.. cpp:function:: bool stopMonitoring()

This call returns true if this instrumentation point is a dynamic call
site and its instrumentation is successfully removed. Otherwise, it
returns false.

.. cpp:function:: int getDisplacedInstructions(int maxSize, void *insns)

BPatch_point::getDisplacedInstructions Returns the instructions to be relocated when instrumentation is inserted at this point. Returns the number of bytes taken up by these instructions.

.. cpp:function:: bool usesTrap_NP()

Checks if inserting instrumentation at this point requires using a trap.
Checks if inserting instrumentation at this point requires using a trap rather
than a jump to the base tramp.

On the x86 architecture, because instructions are of variable
size, the instruction at a point may be too small for Dyninst to replace
Expand All @@ -117,6 +118,11 @@ BPatch_point.h
appropriate instrumentation code. Since this technique is used only on
some platforms, on other platforms this function always returns false.

.. cpp:function:: bool BPatchToInternalArgs(BPatch_point *point, BPatch_callWhen when, BPatch_snippetOrder order,\
callWhen &ipWhen, callOrder &ipOrder)

This isn't a point member because it relies on instPoint.h, which we don't want to include in BPatch_point.h.
If we had a public "enumerated types" header file this could move.


Notes
Expand Down
101 changes: 0 additions & 101 deletions dyninstAPI/src/BPatch_point.C
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
#include "mapped_object.h"
#include "Snippet.h"

/*
* Private constructor, insn
*/
BPatch_point::BPatch_point(BPatch_addressSpace *_addSpace,
BPatch_function *_func, instPoint *_point,
instPoint *_secondary,
Expand Down Expand Up @@ -97,9 +94,6 @@ BPatch_point::BPatch_point(BPatch_addressSpace *_addSpace,
}
}

/*
* Private constructor, edge
*/
BPatch_point::BPatch_point(BPatch_addressSpace *_addSpace,
BPatch_function *_func,
BPatch_edge *_edge, instPoint *_point,
Expand All @@ -124,21 +118,7 @@ BPatch_point::BPatch_point(BPatch_addressSpace *_addSpace,
}
}

/*
* BPatch_point::setLoop
*
* For a BPatch_point representing a loop instrumentation site,
* set the loop that it represents.
*/

void BPatch_point::setLoop(BPatch_basicBlockLoop *l) {
// We currently can use a single BPatch_point to represent
// multiple loops. This is a problem, since we would really
// like the points to label a unique loop. On the other hand,
// then multiple points would share the same physical address..
// not good.


// Point must be for a loop.
assert(pointType == BPatch_locLoopEntry ||
pointType == BPatch_locLoopExit ||
Expand All @@ -148,57 +128,26 @@ void BPatch_point::setLoop(BPatch_basicBlockLoop *l) {
loop = l;
}

/*
* BPatch_point::getPointType
*
* Returns type of BPatch_point
*/

BPatch_procedureLocation BPatch_point::getPointType()
{
return pointType;
}

/*
* BPatch_point::getLoop
*
* Returns loop if of appropriate type
*/

BPatch_basicBlockLoop *BPatch_point::getLoop()
{
return loop;
}

/*
* BPatch_point::getAddressSpace
*
* Returns the point's address space
*/

BPatch_addressSpace *BPatch_point::getAddressSpace()
{
return addSpace;
}

/*
* BPatch_point::getFunction
*
* Returns function to which this BPatch_point belongs
*/

BPatch_function *BPatch_point::getFunction()
{
return func;
}

/*
* BPatch_point::getCalledFunction
*
* For a BPatch_point representing a call site, returns a pointer to a
* BPatch_function that represents the function being called. If the point
* isn't a call site, returns NULL.
*/
BPatch_function *BPatch_point::getCalledFunction()
{
assert(point);
Expand Down Expand Up @@ -238,12 +187,6 @@ std::string BPatch_point::getCalledFunctionName() {
return point->block()->obj()->getCalleeName(point->block());
}

/*
* BPatch_point::getBlock
*
* Returns block to which this BPatch_point belongs
*/

BPatch_basicBlock *BPatch_point::getBlock()
{
if (!point) return NULL;
Expand Down Expand Up @@ -342,38 +285,18 @@ bool BPatch_point::getLiveRegisters(std::vector<BPatch_register> &liveRegs)

}

/*
* BPatch_point::getAddress
*
* Returns the original address of the first instruction at this point.
*/
void *BPatch_point::getAddress()
{
return (void *)point->addr_compat();
}


/*
* BPatch_point::usesTrap_NP
*
* Returns true if this point is or would be instrumented with a trap, rather
* than a jump to the base tramp, false otherwise. On platforms that do not
* use traps (everything other than x86), it always returns false;
*
*/
bool BPatch_point::usesTrap_NP()
{
assert(point);
return false;
//return point->usesTrap();
}

/*
* BPatch_point::isDynamic
*
* Returns true if this point is a dynamic control transfer site.
*
*/
bool BPatch_point::isDynamic()
{
if (!point) return false;
Expand Down Expand Up @@ -415,15 +338,6 @@ bool BPatch_point::isDynamic()
}
}

/*
* BPatch_point::monitorCalls(BPatch_function *userCBFunc)
*
* Insert function call to user-defined callback function
* at dynamic call site.
*
* Returns false if BPatch_point is not a dynamic call site.
*
*/
void *BPatch_point::monitorCalls( BPatch_function * user_cb )
{
BPatch_function *func_to_use = user_cb;
Expand Down Expand Up @@ -510,24 +424,11 @@ bool BPatch_point::stopMonitoring()
return ret;
}

/*
* BPatch_point::getDisplacedInstructions
*
* Returns the instructions to be relocated when instrumentation is inserted
* at this point. Returns the number of bytes taken up by these instructions.
*
* maxSize The maximum number of bytes of instructions to return.
* insns A pointer to a buffer in which to return the instructions.
*/

int BPatch_point::getDisplacedInstructions(int /*maxSize*/, void* /*insns*/)
{
return 0;
}

// This isn't a point member because it relies on instPoint.h, which
// we don't want to include in BPatch_point.h. If we had a public "enumerated types"
// header file this could move.
bool BPatchToInternalArgs(BPatch_point *point,
BPatch_callWhen when,
BPatch_snippetOrder order,
Expand Down Expand Up @@ -650,8 +551,6 @@ void BPatch_point::recordSnippet(BPatch_callWhen when,

}

// Removes snippet from datastructures, doesn't actually remove the
// instrumentation. Is invoked by BPatch_addressSpace::deleteSnippet
bool BPatch_point::removeSnippet(BPatchSnippetHandle *handle)
{
bool foundHandle = false;
Expand Down

0 comments on commit a974546

Please sign in to comment.