Skip to content

Commit

Permalink
Add parseAPI/CFGModifier.h
Browse files Browse the repository at this point in the history
  • Loading branch information
hainest committed Apr 3, 2024
1 parent 389e949 commit 9d4c1c6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 28 deletions.
2 changes: 2 additions & 0 deletions docs/parseAPI/developer/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ParseAPI
BoundFactCalculator.h
BoundFactData.h
CFG.h
CFGFactory.h
CFGModifier.h
debug_parse.h
dominator.h
IA_aarch64.h
Expand Down
69 changes: 69 additions & 0 deletions docs/parseAPI/developer/CFGModifier.h.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
.. _`sec:CFGModifier.h`:

CFGModifier.h
#############

.. cpp:namespace:: Dyninst::ParseAPI

A collection of methods for user-triggered modification of a ParseAPI CFG.
Implemented here so that we can make it a friend class of the CFG it also
needs internal information about CFG objects.

.. cpp:class:: CFGModifier
These are all static methods as this class has no state so really, it's just a namespace.

.. cpp:function:: static bool redirect(Edge *edge, Block *target)

Redirect the target of an existing edge.

.. cpp:function:: static Block *split(Block *, Address, bool trust = false, Address newlast = -1)

Split a block at a provided point. we double-check whether the address
is a valid instruction boundary unless trust is true.
Newlast is the new "last insn" of the original block provide it if
you don't want to waste time disassembling to figure it out.

.. cpp:function:: static InsertedRegion *insert(CodeObject *obj, Address base, void *data, unsigned size)

Parse and add a new region of code to a CodeObject
The void * becomes "owned" by the CodeObject, as it's used
as a backing store it cannot be ephemeral.
Returns the new entry block.

.. cpp:function:: static bool remove(std::vector<Block *> &, bool force = false)

Remove blocks from the CFG the block must be unreachable
(that is, have no in-edges) unless force is true.

.. cpp:function:: static bool remove(Function *)

As the above, but for functions.

.. cpp:function:: static Function *makeEntry(Block *)

Label a block as the entry of a new function. If the block is already an
entry that function is returned otherwise we create a new function and
return it.

.. cpp:class:: InsertedRegion : public CodeRegion

.. cpp:function:: InsertedRegion(Address base, void *data, unsigned size, Architecture arch)

.. cpp:function:: Address low() const
.. cpp:function:: Address high() const

Addresses are provided by the user, as Dyninst etc. have well-known ways of allocating
additional code by extending the binary or allocating memory, etc.

.. cpp:function:: bool isValidAddress(const Address a) const
.. cpp:function:: void* getPtrToInstruction(const Address a) const
.. cpp:function:: void* getPtrToData(const Address) const
.. cpp:function:: bool isCode(const Address a) const
.. cpp:function:: bool isData(const Address) const
.. cpp:function:: bool isReadOnly(const Address) const
.. cpp:function:: Address offset() const
.. cpp:function:: Address length() const
.. cpp:function:: unsigned int getAddressWidth() const
.. cpp:function:: Architecture getArch() const
.. cpp:function:: bool wasUserAdded() const
2 changes: 0 additions & 2 deletions docs/parseAPI/public/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ ParseAPI
:hidden:
:maxdepth: 1

CFGFactory.h
CFG.h
CFGModifier.h
CodeObject.h
CodeSource.h
GraphAdapter.h
Expand Down
5 changes: 0 additions & 5 deletions docs/parseAPI/public/CFGModifier.h.rst

This file was deleted.

21 changes: 0 additions & 21 deletions parseAPI/h/CFGModifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
#include <vector>
#include "dyntypes.h"

// A collection of methods for user-triggered modification of a ParseAPI CFG.
// Implemented here so that we can make it a friend class of the CFG; it also
// needs internal information about CFG objects.

#include "CodeSource.h"


Expand All @@ -52,36 +48,19 @@ namespace ParseAPI {

class CFGModifier {
public:
// These are all static methods as this class has no state; so really,
// it's just a namespace.

// Redirect the target of an existing edge.
PARSER_EXPORT static bool redirect(Edge *edge, Block *target);

// Split a block at a provided point.; we double-check whether the address
// is a valid instruction boundary unless trust is true.
// Newlast is the new "last insn" of the original block; provide it if
// you don't want to waste time disassembling to figure it out.
PARSER_EXPORT static Block *split(Block *, Address, bool trust = false, Address newlast = -1);

// Parse and add a new region of code to a CodeObject
// The void * becomes "owned" by the CodeObject, as it's used
// as a backing store; it cannot be ephemeral.
// Returns the new entry block.
PARSER_EXPORT static InsertedRegion *insert(CodeObject *obj,
Address base, void *data,
unsigned size);

// Remove blocks from the CFG; the block must be unreachable
// (that is, have no in-edges) unless force is true.
PARSER_EXPORT static bool remove(std::vector<Block *> &, bool force = false);

// As the above, but for functions.
PARSER_EXPORT static bool remove(Function *);

// Label a block as the entry of a new function. If the block is already an
// entry that function is returned; otherwise we create a new function and
// return it.
PARSER_EXPORT static Function *makeEntry(Block *);
};

Expand Down

0 comments on commit 9d4c1c6

Please sign in to comment.