ROSE 0.11.145.147
ControlFlowGraph.h
1#ifndef ROSE_BinaryAnalysis_Partitioner2_ControlFlowGraph_H
2#define ROSE_BinaryAnalysis_Partitioner2_ControlFlowGraph_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
6
7#include <Rose/BinaryAnalysis/Partitioner2/Utility.h>
8
9#include <Sawyer/BiMap.h>
10#include <Sawyer/Graph.h>
11#include <Sawyer/GraphIteratorSet.h>
12#include <Sawyer/GraphIteratorBiMap.h>
13#include <Sawyer/HashMap.h>
14#include <Sawyer/Map.h>
15#include <Sawyer/Optional.h>
16
17#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
18#include <boost/serialization/access.hpp>
19#endif
20
21#include <list>
22#include <ostream>
23
24namespace Rose {
25namespace BinaryAnalysis {
26namespace Partitioner2 {
27
29class CfgVertex {
30 VertexType type_; // type of vertex, special or not
31 rose_addr_t startVa_; // address of start of basic block
32 BasicBlockPtr bblock_; // basic block, or null if only a place holder
33 FunctionSet owningFunctions_; // functions to which vertex belongs
34
35#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
36private:
37 friend class boost::serialization::access;
38 template<class S> void serialize(S&, unsigned version);
39#endif
40
41public:
42 // intentionally undocumented. Necessary for serialization of Sawyer::Container::Graph
43 CfgVertex();
44 ~CfgVertex();
45
47 explicit CfgVertex(rose_addr_t startVa);
48
50 explicit CfgVertex(const BasicBlockPtr &bb);
51
53 /*implicit*/ CfgVertex(VertexType type);
54
57
66 rose_addr_t address() const;
67 void address(rose_addr_t);
74
80
89
97 const BasicBlockPtr& bblock() const;
98 void bblock(const BasicBlockPtr&);
105
111
115 bool isOwningFunction(const FunctionPtr&) const;
116
118 size_t nOwningFunctions() const;
119
135
139 void nullify();
140};
141
143class CfgEdge {
144private:
145 EdgeType type_;
146 Confidence confidence_;
147
148#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
149private:
150 friend class boost::serialization::access;
151 template<class S> void serialize(S&, unsigned version);
152#endif
153
154public:
155 ~CfgEdge();
156
159
162
164 EdgeType type() const;
165
174};
175
177bool sortEdgesBySrc(const ControlFlowGraph::ConstEdgeIterator&, const ControlFlowGraph::ConstEdgeIterator&);
178
180bool sortEdgesByDst(const ControlFlowGraph::ConstEdgeIterator&, const ControlFlowGraph::ConstEdgeIterator&);
181
183bool sortEdgesById(const ControlFlowGraph::ConstEdgeIterator&, const ControlFlowGraph::ConstEdgeIterator&);
184
186bool sortVerticesByAddress(const ControlFlowGraph::ConstVertexIterator&, const ControlFlowGraph::ConstVertexIterator&);
187
189bool sortVerticesById(const ControlFlowGraph::ConstVertexIterator&, const ControlFlowGraph::ConstVertexIterator&);
190
192std::ostream& operator<<(std::ostream&, const ControlFlowGraph::Vertex&);
193
195std::ostream& operator<<(std::ostream&, const ControlFlowGraph::Edge&);
196
199
203typedef std::list<ControlFlowGraph::VertexIterator> CfgVertexList;
204typedef std::list<ControlFlowGraph::ConstVertexIterator> CfgConstVertexList;
210typedef std::list<ControlFlowGraph::EdgeIterator> CfgEdgeList;
211typedef std::list<ControlFlowGraph::ConstEdgeIterator> CfgConstEdgeList;
229typedef Sawyer::Container::GraphIteratorBiMap<ControlFlowGraph::ConstVertexIterator,
230 ControlFlowGraph::ConstVertexIterator> CfgVertexMap;
231
280
282// Control flow graph utility functions
284
289void insertCfg(ControlFlowGraph &dst, const ControlFlowGraph &src, CfgVertexMap &vmap /*out*/);
290
295CfgConstEdgeSet findBackEdges(const ControlFlowGraph &cfg, const ControlFlowGraph::ConstVertexIterator &begin);
296
300CfgConstEdgeSet findCallEdges(const ControlFlowGraph::ConstVertexIterator &callSite);
301
305CfgConstVertexSet findCalledFunctions(const ControlFlowGraph &cfg, const ControlFlowGraph::ConstVertexIterator &callSite);
306
317CfgConstEdgeSet findCallReturnEdges(const ControlFlowGraph::ConstVertexIterator &callSite);
323CfgConstVertexSet findFunctionReturns(const ControlFlowGraph &cfg, const ControlFlowGraph::ConstVertexIterator &beginVertex);
324
343
346
362
368
376
392 ControlFlowGraph::VertexIterator &entry/*out*/);
393
409 const ControlFlowGraph::ConstVertexIterator &gcfgEntry);
410
411} // namespace
412} // namespace
413} // namespace
414
415#endif
416#endif
Sawyer::SharedPointer< CfgAdjustmentCallback > Ptr
Shared ownership pointer.
virtual bool operator()(bool chain, const DetachedBasicBlock &)=0
Called when basic block is detached or placeholder erased.
virtual bool operator()(bool chain, const AttachedBasicBlock &)=0
Called when basic block is attached or placeholder inserted.
CfgEdge(EdgeType type, Confidence confidence=ASSUMED)
Construct an edge with a specified type and confidence.
CfgEdge()
Construct a new normal edge.
Confidence confidence() const
Property: Confidence.
void confidence(Confidence)
Property: Confidence.
EdgeType type() const
Return edge type.
const FunctionSet & owningFunctions() const
Property: Owning functions.
FunctionSet & owningFunctions()
Property: Owning functions.
const BasicBlockPtr & bblock() const
Property: basic block.
bool insertOwningFunction(const FunctionPtr &)
Add a function to the list of functions that own this vertex.
rose_addr_t address() const
Property: starting address.
FunctionPtr isEntryBlock() const
Is block a function entry block?
CfgVertex(const BasicBlockPtr &bb)
Construct a basic block vertex.
Sawyer::Optional< rose_addr_t > optionalAddress() const
Safe version of starting address.
AddressIntervalSet addresses() const
Compute entire address set.
Sawyer::Optional< rose_addr_t > optionalLastAddress() const
Address of last item in the vertex.
void eraseOwningFunction(const FunctionPtr &)
Remove a function from the list of functions that own this vertex.
void bblock(const BasicBlockPtr &)
Property: basic block.
CfgVertex(VertexType type)
Construct a special vertex.
bool isOwningFunction(const FunctionPtr &) const
Determines if a function owns this vertex.
void address(rose_addr_t)
Property: starting address.
CfgVertex(rose_addr_t startVa)
Construct a basic block placeholder vertex.
VertexType type() const
Returns the vertex type.
size_t nOwningFunctions() const
Number of functions that own this vertex.
void nullify()
Turns a basic block vertex into a placeholder.
Bidirectional map of graph edge or vertex pointers.
Set of graph edge or vertex pointers (iterators).
Container associating values with keys.
Definition HashMap.h:30
Container associating values with keys.
Definition Sawyer/Map.h:72
Holds a value or nothing.
Definition Optional.h:56
Base class for reference counted objects.
CfgConstVertexSet forwardMapped(const CfgConstVertexSet &, const CfgVertexMap &)
Return corresponding iterators.
void insertCfg(ControlFlowGraph &dst, const ControlFlowGraph &src, CfgVertexMap &vmap)
Insert one control flow graph into another.
std::list< ControlFlowGraph::ConstVertexIterator > CfgConstVertexList
List of CFG vertex pointers.
CfgConstVertexSet findIncidentVertices(const CfgConstEdgeSet &)
Vertices that are incident to specified edges.
std::list< ControlFlowGraph::EdgeIterator > CfgEdgeList
List of CFG edge pointers.
CfgConstVertexSet findFunctionReturns(const ControlFlowGraph &cfg, const ControlFlowGraph::ConstVertexIterator &beginVertex)
Find all function return vertices.
Sawyer::Container::Map< FunctionPtr, CfgConstEdgeSet > findFunctionReturnEdges(const PartitionerConstPtr &)
Find function return edges organized by function.
CfgConstEdgeSet findCallReturnEdges(const PartitionerConstPtr &, const ControlFlowGraph &)
Return outgoing call-return edges.
ControlFlowGraph functionCfgByReachability(const ControlFlowGraph &gcfg, const FunctionPtr &function, const ControlFlowGraph::ConstVertexIterator &gcfgEntry)
Generate a function control flow graph.
void expandFunctionReturnEdges(const PartitionerConstPtr &, ControlFlowGraph &cfg)
Rewrite function return edges.
bool sortEdgesByDst(const ControlFlowGraph::ConstEdgeIterator &, const ControlFlowGraph::ConstEdgeIterator &)
Sort edges by target vertex address.
bool sortEdgesBySrc(const ControlFlowGraph::ConstEdgeIterator &, const ControlFlowGraph::ConstEdgeIterator &)
Sort edges by source vertex address.
bool sortVerticesByAddress(const ControlFlowGraph::ConstVertexIterator &, const ControlFlowGraph::ConstVertexIterator &)
Sort vertices by address.
CfgConstEdgeSet findCallEdges(const ControlFlowGraph::ConstVertexIterator &callSite)
Find function call edges.
Sawyer::Container::GraphIteratorBiMap< ControlFlowGraph::ConstVertexIterator, ControlFlowGraph::ConstVertexIterator > CfgVertexMap
Map vertices from one CFG to another CFG and vice versa.
bool sortVerticesById(const ControlFlowGraph::ConstVertexIterator &, const ControlFlowGraph::ConstVertexIterator &)
Sort vertices by vertex ID number.
@ ASSUMED
The value is an assumption without any proof.
Sawyer::Container::GraphIteratorSet< ControlFlowGraph::ConstEdgeIterator > CfgConstEdgeSet
Set of CFG edge pointers.
Sawyer::Container::HashMap< rose_addr_t, ControlFlowGraph::VertexIterator > CfgVertexIndex
Mapping from basic block starting address to CFG vertex.
std::list< ControlFlowGraph::VertexIterator > CfgVertexList
List of CFG vertex pointers.
std::list< ControlFlowGraph::ConstEdgeIterator > CfgConstEdgeList
List of CFG edge pointers.
CfgConstVertexSet reverseMapped(const CfgConstVertexSet &, const CfgVertexMap &)
Return corresponding iterators.
Sawyer::Container::GraphIteratorSet< ControlFlowGraph::ConstVertexIterator > CfgConstVertexSet
Set of CFG vertex pointers.
Sawyer::Container::GraphIteratorSet< ControlFlowGraph::EdgeIterator > CfgEdgeSet
Set of CFG edge pointers.
CfgConstVertexSet findDetachedVertices(const ControlFlowGraph &)
Find vertices that have zero degree.
Sawyer::Container::GraphIteratorSet< ControlFlowGraph::VertexIterator > CfgVertexSet
Set of CFG vertex pointers.
void eraseEdges(ControlFlowGraph &, const CfgConstEdgeSet &toErase)
Erase multiple edges.
bool sortEdgesById(const ControlFlowGraph::ConstEdgeIterator &, const ControlFlowGraph::ConstEdgeIterator &)
Sort edges by edge ID number.
CfgConstEdgeSet findBackEdges(const ControlFlowGraph &cfg, const ControlFlowGraph::ConstVertexIterator &begin)
Find back edges.
ControlFlowGraph functionCfgByErasure(const ControlFlowGraph &gcfg, const FunctionPtr &function, ControlFlowGraph::VertexIterator &entry)
Generate a function control flow graph.
CfgConstVertexSet findCalledFunctions(const ControlFlowGraph &cfg, const ControlFlowGraph::ConstVertexIterator &callSite)
Find called functions.
The ROSE library.
const PartitionerPtr partitioner
Partitioner in which change occurred.
rose_addr_t startVa
Starting address for basic block or placeholder.
BasicBlockPtr bblock
Optional basic block; otherwise a placeholder operation.
PartitionerConstPtr partitioner
Partitioner in which change occurred.
BasicBlockPtr bblock
Optional basic block; otherwise a placeholder operation.
rose_addr_t startVa
Starting address for basic block or placeholder.