| java.lang.Object | |
| ↳ | com.pnfsoftware.jeb.core.units.code.controlflow.CFG<InsnType extends com.pnfsoftware.jeb.core.units.code.ILocatedInstruction> |
This class represents a Control Flow Graph for a method, or more generally, any body of
code. The CFG can be typed to handle specific instructions.
This class provides basic Data Flow Analysis support. A client can request simple and full du- and ud-chains. Full chains contain more precise cross-block information.
There are two ways to build a CFG:
CFG() constructor, and then calling
#buildGraph(List, List) with a list of pre-basic blocks.CFG(List) or CFG(List, List) constructor and passing a flat
list of instructions.| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
CFG(List<BasicBlockBuilder<InsnType>> foetuses)
Create a CFG using a pre-computed list of partial basic block.
| |||||||||||
|
CFG(List<InsnType> insns, List<IrregularFlowData> irrdata)
Create a CFG by recursively parsing a list of instructions.
| |||||||||||
| Protected Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| CFG() | |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| boolean |
deleteEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y)
Delete a regular edge X->Y
Warning! The method throws if duplicate edges x->y are found. | ||||||||||
| void |
doDataFlowAnalysis()
Perform data flow analysis on the CFG. | ||||||||||
| void |
doDataFlowAnalysis(boolean redo)
Perform data flow analysis on the CFG. | ||||||||||
| String |
format(boolean format_addresses, int format_chains, Object context)
Format the CFG into a printable string.
| ||||||||||
| String | formatBlockInstruction(InsnType insn) | ||||||||||
| String | formatBlockInstructions(BasicBlock<InsnType> bb) | ||||||||||
| String | formatChains(InsnType insn, ChainType type) | ||||||||||
| String | formatFullChains(InsnType insn, ChainType type) | ||||||||||
| String | formatInstruction(InsnType insn) | ||||||||||
| String |
formatInstructions()
Format all the instructions (and their full chains) of a CFG into a printable string.
| ||||||||||
| String |
formatInstructions(Collection<InsnType> insns)
Format a list of instructions and their associated full chains.
| ||||||||||
| String | formatInstructions2() | ||||||||||
| static <InsnType extends ILocatedInstruction> String | formatRegisterToInsnCollection(Map<Integer, Set<InsnType>> m) | ||||||||||
| BasicBlock<InsnType> |
get(int index)
Retrieve a basic block.
| ||||||||||
| Map<Long, BasicBlock<InsnType>> |
getAddressBlockMap()
Get a complete map of the basic blocks and their addresses in the CFG.
| ||||||||||
| BasicBlock<InsnType> |
getBlockAt(int address)
Get the basic block that starts at the provided address/offset.
| ||||||||||
| BasicBlock<InsnType> | getBlockFor(InsnType insn) | ||||||||||
| List<BasicBlock<InsnType>> |
getBlocks()
Get a copy of the block list of the CFG.
| ||||||||||
| Map<InsnType, Map<Integer, List<Integer>>> |
getDefUseChains()
Retrieve the simple def-use chains.
| ||||||||||
| Map<InsnType, Map<Integer, List<InsnType>>> |
getFullDefUseChains()
Retrieve the full def-use chains.
| ||||||||||
| Map<InsnType, Map<Integer, List<InsnType>>> |
getFullUseDefChains()
Retrieve the full use-def chains.
| ||||||||||
| void |
getGraphRepresentation(List<int[]> edges, List<int[]> irregular_edges)
Get the edges of the CFG.
| ||||||||||
| InsnType | getInstructionAt(int offset) | ||||||||||
| List<InsnType> |
getInstructions()
Get the instruction list by aggregating each instruction of every block.
| ||||||||||
| Map<Integer, Set<InsnType>> | getReachMap(InsnType insn) | ||||||||||
| Map<InsnType, Map<Integer, List<Integer>>> |
getUseDefChains()
Retrieve the simple use-def chains.
| ||||||||||
| int |
reconnectEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, BasicBlock<InsnType> z)
This method regularly reconnects a block X from Y to Z.
| ||||||||||
| void |
removeBlock(BasicBlock<InsnType> b)
Remove a block, and update the fixtures. | ||||||||||
| void | resetDFA() | ||||||||||
| int |
simplify()
Merge the blocks that can be merged, without changing the flow of the graph.
| ||||||||||
| int |
simplifyIrregularFlows()
Merge blocks that can be merged, taking into accounts irregular flows.
| ||||||||||
| int |
size()
Get the number of blocks.
| ||||||||||
| String | toString() | ||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
Create a CFG using a pre-computed list of partial basic block.
Create a CFG by recursively parsing a list of instructions.
| insns | list of instructions to be processed |
|---|---|
| irrdata | (optional) irregular flow information, used for exception support |
Delete a regular edge X->Y
Warning! The method throws if duplicate edges x->y are found.
| x | source block |
|---|---|
| y | destination block |
Perform data flow analysis on the CFG.
Do NOT force a new analysis: Same as doDataFlowAnalysis(false).
Perform data flow analysis on the CFG.
| redo | force a new analysis |
|---|
Format the CFG into a printable string.
| format_chains | 0=no, 1=simple chains, 2=full chains |
|---|
Format all the instructions (and their full chains) of a CFG into a printable string.
Format a list of instructions and their associated full chains.
Get a complete map of the basic blocks and their addresses in the CFG. This method is
recommended for use when multiple, repeated invocations of getBlockAt(int) are to be
made.
Get the basic block that starts at the provided address/offset.
| address | the block address or offset |
|---|
Get a copy of the block list of the CFG. The list is ordered by ascending offset.
Retrieve the simple def-use chains.
Retrieve the full def-use chains.
This chain is the only one to have an extra key, set to null, which lists the registers
defined 'outside' the routine and used throughout the routine, ie those which should be
passed as parameters to the routine.
It is the caller's responsibility to check that these registers are indeed provided as
parameters.
Retrieve the full use-def chains.
Get the edges of the CFG. The nodes are numbered from 1 to n.
| edges | (output) array of regular edges, eg: {{1,2},{1,3},{2,3}} |
|---|---|
| irregular_edges | (output) array of irregular edges |
Get the instruction list by aggregating each instruction of every block. The list is ordered by ascending offset.
Retrieve the simple use-def chains.
This method regularly reconnects a block X from Y to Z. (x->y becomes x->z)
Warning! The method throws if duplicate edges x->y are found.
| x | the original source block |
|---|---|
| y | the original destination block |
| z | the new destination block |
Remove a block, and update the fixtures. This method is content-agnostic.
A CFG should never contain empty blocks. However, when the CFG is optimized, instructions are removed, and some nodes might end up empty. This transient, stale state is fine AS LONG AS the client knows what it is doing and removes the empty block as soon as they're done, before passing it down the processing chain. This method removes empty blocks and updates the edges of connected and connecting blocks.
1st caveat: the empty block's out-degree or in-degree MUST be one. (Otherwise, stiching up the edges would not be possible.)
2nd caveat: duplicate edges can be introduced. The client should remove them if it doesn't like that.
3rd caveat: the fixtures update is instruction-agnostic. This means that the client is solely responsible regarding the decision to remove an empty block. For instance, the last instruction of the predecessor block should be checked and the client should make sure that removing the block and updating the fixtures is an operation compatible with the semantics of that last instruction.
| b | block to be removed |
|---|
Merge the blocks that can be merged, without changing the flow of the graph.
Necessary conditions include: adjacent blocks, first block falls thru the second one, no
block shall have irregular outputs, and only the first block may have irregular inputs. or
contents of the nodes.
Merge blocks that can be merged, taking into accounts irregular flows.
A follow through may be merged with a block inside a try (with irregular outedges) if no
instruction within the block can raise.
Get the number of blocks.