SVF
Public Member Functions | List of all members
SVF::ICFGPrinter Class Reference

#include <Graph2Json.h>

Inheritance diagram for SVF::ICFGPrinter:
SVF::ICFG SVF::GenericGraph< NodeTy, EdgeTy >

Public Member Functions

 ICFGPrinter ()
 
void printICFGToJson (const std::string &filename)
 
std::string getPAGNodeKindValue (int kind)
 
std::string getPAGEdgeKindValue (int kind)
 
std::string getICFGKind (const int kind)
 
- Public Member Functions inherited from SVF::ICFG
 ICFG ()
 Constructor. More...
 
virtual ~ICFG ()
 Destructor. More...
 
ICFGNodegetICFGNode (NodeID id) const
 Get a ICFG node. More...
 
bool hasICFGNode (NodeID id) const
 Whether has the ICFGNode. More...
 
ICFGEdgegetICFGEdge (const ICFGNode *src, const ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
 Get a SVFG edge according to src and dst. More...
 
void dump (const std::string &file, bool simple=false)
 Dump graph into dot file. More...
 
void view ()
 View graph from the debugger. More...
 
void updateCallGraph (PTACallGraph *callgraph)
 update ICFG for indirect calls More...
 
void removeICFGEdge (ICFGEdge *edge)
 Remove a SVFG edge. More...
 
void removeICFGNode (ICFGNode *node)
 Remove a ICFGNode. More...
 
void checkIntraEdgeParents (const ICFGNode *srcNode, const ICFGNode *dstNode)
 sanitize Intra edges, verify that both nodes belong to the same function. More...
 
bool addICFGEdge (ICFGEdge *edge)
 Add ICFG edge. More...
 
virtual void addICFGNode (ICFGNode *node)
 Add a ICFG node. More...
 
ICFGEdgehasIntraICFGEdge (ICFGNode *src, ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
 Whether we has a SVFG edge. More...
 
ICFGEdgehasInterICFGEdge (ICFGNode *src, ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
 
ICFGEdgehasThreadICFGEdge (ICFGNode *src, ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
 
ICFGEdgeaddIntraEdge (ICFGNode *srcNode, ICFGNode *dstNode)
 Add control-flow edges for top level pointers. More...
 
ICFGEdgeaddConditionalIntraEdge (ICFGNode *srcNode, ICFGNode *dstNode, const Value *condition, NodeID branchID)
 
ICFGEdgeaddCallEdge (ICFGNode *srcNode, ICFGNode *dstNode, const Instruction *cs)
 
ICFGEdgeaddRetEdge (ICFGNode *srcNode, ICFGNode *dstNode, const Instruction *cs)
 
ICFGNodegetBlockICFGNode (const Instruction *inst)
 Get a basic block ICFGNode. More...
 
CallBlockNodegetCallBlockNode (const Instruction *inst)
 
RetBlockNodegetRetBlockNode (const Instruction *inst)
 
IntraBlockNodegetIntraBlockNode (const Instruction *inst)
 
FunEntryBlockNodegetFunEntryBlockNode (const SVFFunction *fun)
 Add a function entry node. More...
 
FunExitBlockNodegetFunExitBlockNode (const SVFFunction *fun)
 Add a function exit node. More...
 
GlobalBlockNodegetGlobalBlockNode () const
 
- Public Member Functions inherited from SVF::GenericGraph< NodeTy, EdgeTy >
 GenericGraph ()
 Constructor. More...
 
virtual ~GenericGraph ()
 Destructor. More...
 
void destroy ()
 Release memory. More...
 
iterator begin ()
 Iterators. More...
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
void addGNode (NodeID id, NodeType *node)
 Add a Node. More...
 
NodeTypegetGNode (NodeID id) const
 Get a node. More...
 
bool hasGNode (NodeID id) const
 Has a node. More...
 
void removeGNode (NodeType *node)
 Delete a node. More...
 
u32_t getTotalNodeNum () const
 Get total number of node/edge. More...
 
u32_t getTotalEdgeNum () const
 
void incNodeNum ()
 Increase number of node/edge. More...
 
void incEdgeNum ()
 

Additional Inherited Members

- Public Types inherited from SVF::ICFG
typedef Map< NodeID, ICFGNode * > ICFGNodeIDToNodeMapTy
 
typedef ICFGEdge::ICFGEdgeSetTy ICFGEdgeSetTy
 
typedef ICFGNodeIDToNodeMapTy::iterator iterator
 
typedef ICFGNodeIDToNodeMapTy::const_iterator const_iterator
 
typedef Map< const SVFFunction *, FunEntryBlockNode * > FunToFunEntryNodeMapTy
 
typedef Map< const SVFFunction *, FunExitBlockNode * > FunToFunExitNodeMapTy
 
typedef Map< const Instruction *, CallBlockNode * > CSToCallNodeMapTy
 
typedef Map< const Instruction *, RetBlockNode * > CSToRetNodeMapTy
 
typedef Map< const Instruction *, IntraBlockNode * > InstToBlockNodeMapTy
 
- Public Types inherited from SVF::GenericGraph< NodeTy, EdgeTy >
typedef NodeTy NodeType
 
typedef EdgeTy EdgeType
 
typedef Map< NodeID, NodeType * > IDToNodeMapTy
 NodeID to GenericNode map. More...
 
typedef IDToNodeMapTy::iterator iterator
 Node Iterators. More...
 
typedef IDToNodeMapTy::const_iterator const_iterator
 
- Public Attributes inherited from SVF::ICFG
NodeID totalICFGNode
 
- Public Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
u32_t edgeNum
 total num of node More...
 
u32_t nodeNum
 total num of edge More...
 
- Protected Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
IDToNodeMapTy IDToNodeMap
 node map More...
 

Detailed Description

Definition at line 16 of file Graph2Json.h.

Constructor & Destructor Documentation

◆ ICFGPrinter()

ICFGPrinter::ICFGPrinter ( )

Definition at line 10 of file Graph2Json.cpp.

10 {}

Member Function Documentation

◆ getICFGKind()

std::string ICFGPrinter::getICFGKind ( const int  kind)

Definition at line 140 of file Graph2Json.cpp.

141 {
142  switch(kind)
143  {
145  return "IntraBlock";
146  break;
148  return "FunEntryBlock";
149  break;
151  return "FunExitBlock";
152  break;
154  return "FunCallBlock";
155  break;
157  return "FunRetBlock";
158  break;
159  default:
160  return "";
161  }
162  return "";
163 }

◆ getPAGEdgeKindValue()

std::string ICFGPrinter::getPAGEdgeKindValue ( int  kind)

Definition at line 200 of file Graph2Json.cpp.

201 {
202  switch(kind)
203  {
204  case (PAGEdge::Addr):
205  return "Addr";
206  break;
207  case (PAGEdge::Copy):
208  return "Copy";
209  break;
210  case (PAGEdge::Store):
211  return "Store";
212  break;
213  case (PAGEdge::Load):
214  return "Load";
215  break;
216  case (PAGEdge::Call):
217  return "Call";
218  break;
219  case (PAGEdge::Ret):
220  return "Ret";
221  break;
222  case (PAGEdge::NormalGep):
223  return "NormalGep";
224  break;
225  case (PAGEdge::VariantGep):
226  return "VariantGep";
227  break;
228  case (PAGEdge::ThreadFork):
229  return "ThreadFork";
230  break;
231  case (PAGEdge::ThreadJoin):
232  return "ThreadJoin";
233  break;
234  case (PAGEdge::Cmp):
235  return "Cmp";
236  break;
237  case (PAGEdge::BinaryOp):
238  return "BinaryOp";
239  break;
240  case (PAGEdge::UnaryOp):
241  return "UnaryOp";
242  break;
243  }
244  return "";
245 }

◆ getPAGNodeKindValue()

std::string ICFGPrinter::getPAGNodeKindValue ( int  kind)

Definition at line 165 of file Graph2Json.cpp.

166 {
167  switch (kind)
168  {
169  case (PAGNode::ValNode):
170  return "ValNode";
171  break;
172  case PAGNode::ObjNode:
173  return "ObjNode";
174  break;
175  case PAGNode::RetNode:
176  return "RetNode";
177  break;
178  case PAGNode::VarargNode:
179  return "VarargNode";
180  break;
181  case PAGNode::GepValNode:
182  return "GepValNode";
183  break;
184  case PAGNode::GepObjNode:
185  return "GepObjNode";
186  break;
187  case PAGNode::FIObjNode:
188  return "FIObjNode";
189  break;
191  return "DummyValNode";
192  break;
194  return "DummyObjNode";
195  break;
196  }
197  return "";
198 }

◆ printICFGToJson()

void ICFGPrinter::printICFGToJson ( const std::string &  filename)

Definition at line 11 of file Graph2Json.cpp.

12 {
13  outs() << "write symbols to '" << filename << "'...";
14  std::error_code err;
15  ToolOutputFile F(filename.c_str(), err, llvm::sys::fs::F_None);
16  if (err)
17  {
18  outs() << " error opening file for writing!\n";
19  F.os().clear_error();
20  return;
21  }
22 
23  llvm::json::Array root_array;
24  for(ICFG::iterator it = begin(), eit = end(); it!=eit; ++it)
25  {
26  ICFGNode* node = it->second;
27  NodeID id = node->getId();
28  llvm::json::Object ICFGNode_Obj;
29  ICFGNode_Obj["ICFG_ID"] = id;
30  ICFGNode_Obj["Node Type"] = getICFGKind(node->getNodeKind());
31  if(IntraBlockNode* bNode = SVFUtil::dyn_cast<IntraBlockNode>(node))
32  {
33  ICFGNode_Obj["Source Location"] = getSourceLoc(bNode->getInst());
35  llvm::json::Array PAGEdge_array;
36 
37  //dump pag edges
38  for (PAG::PAGEdgeList::iterator it = edges.begin(),
39  eit = edges.end(); it != eit; ++it)
40  {
41  const PAGEdge* edge = *it;
42  llvm::json::Object edge_obj;
43  edge_obj["Source Node"] = edge->getSrcID();
44  edge_obj["Destination Node"] = edge->getDstID();
45  edge_obj["Source Type"] = getPAGNodeKindValue(edge->getSrcNode()->getNodeKind());
46  edge_obj["Destination Type"] = getPAGNodeKindValue(edge->getDstNode()->getNodeKind());
47  edge_obj["Edge Type"] = getPAGEdgeKindValue(edge->getEdgeKind());
48  edge_obj["srcValueName"] = edge->getSrcNode()->getValueName();
49  edge_obj["dstValueName"] = edge->getDstNode()->getValueName();
50  if(edge->getEdgeKind()==PAGEdge::NormalGep)
51  {
52  const NormalGepPE* gepEdge = SVFUtil::cast<NormalGepPE>(edge);
53  edge_obj["offset"] = gepEdge->getOffset();
54  }
55  llvm::json::Value edge_value = llvm::json::Object{edge_obj};
56  PAGEdge_array.push_back(edge_value);
57  }
58  llvm::json::Value PagEdge_value = llvm::json::Array{PAGEdge_array};
59  ICFGNode_Obj["PAG Edges"] = PagEdge_value;
60  }
61  else if(FunEntryBlockNode* entry = SVFUtil::dyn_cast<FunEntryBlockNode>(node))
62  {
63  if (isExtCall(entry->getFun()))
64  ICFGNode_Obj["isExtCall"] = true;
65  else
66  {
67  ICFGNode_Obj["isExtCall"] = false;
68  ICFGNode_Obj["Source Location"] = getSourceLoc(entry->getFun()->getLLVMFun());
69  }
70  ICFGNode_Obj["Function Name"] = entry->getFun()->getName();
71  }
72  else if (FunExitBlockNode* exit = SVFUtil::dyn_cast<FunExitBlockNode>(node))
73  {
74  if (isExtCall(exit->getFun()))
75  ICFGNode_Obj["isExtCall"] = true;
76  else
77  {
78  ICFGNode_Obj["isExtCall"] = false;
79  ICFGNode_Obj["Source Location"] = getSourceLoc(&(exit->getFun()->getLLVMFun()->back()));
80  }
81  ICFGNode_Obj["Function Name"] = exit->getFun()->getName();
82  }
83  else if (CallBlockNode* call = SVFUtil::dyn_cast<CallBlockNode>(node))
84  {
85  ICFGNode_Obj["Source Location"] = getSourceLoc(call->getCallSite());
86  }
87  else if (RetBlockNode* ret = SVFUtil::dyn_cast<RetBlockNode>(node))
88  {
89  ICFGNode_Obj["Source Location"] = getSourceLoc(ret->getCallSite());
90  }
91  else
92  assert(false && "what else kinds of nodes do we have??");
93 
94  llvm::json::Array ICFGEdges_array;
95  for(ICFGNode::iterator sit = node->OutEdgeBegin(), esit = node->OutEdgeEnd(); sit!=esit; ++sit)
96  {
97  ICFGEdge* edge = *sit;
98  llvm::json::Object ICFGEdge_obj;
99  if (SVFUtil::isa<CallCFGEdge>(edge))
100  {
102  ICFGEdge_obj["ICFG Edge Type"] = "CallCFGEdge";
103  ICFGEdge_obj["ICFGEdgeSrcID"] = call->getSrcID();
104  ICFGEdge_obj["ICFGEdgeDstID"] = call->getDstID();
105  }
106  else if (SVFUtil::isa<RetCFGEdge>(edge))
107  {
108  RetCFGEdge* call = SVFUtil::dyn_cast<RetCFGEdge>(edge);
109  ICFGEdge_obj["ICFG Edge Type"] = "RetCFGEdge";
110  ICFGEdge_obj["ICFGEdgeSrcID"] = call->getSrcID();
111  ICFGEdge_obj["ICFGEdgeDstID"] = call->getDstID();
112  }
113  else if(SVFUtil::isa<IntraCFGEdge>(edge))
114  {
115  IntraCFGEdge* intraCFGEdge = SVFUtil::dyn_cast<IntraCFGEdge>(edge);
116  ICFGEdge_obj["ICFG Edge Type"] = "IntraCFGEdge";
117  ICFGEdge_obj["ICFGEdgeSrcID"] = intraCFGEdge->getSrcID();
118  ICFGEdge_obj["ICFGEdgeDstID"] = intraCFGEdge->getDstID();
119  }
120  llvm::json::Value ICFGEdge_Val = llvm::json::Object{ICFGEdge_obj};
121  ICFGEdges_array.push_back(ICFGEdge_Val);
122  }
123  llvm::json::Value ICFGEdges_val = llvm::json::Array{ICFGEdges_array};
124  ICFGNode_Obj["ICFGEdges"] = ICFGEdges_val;
125  llvm::json::Value ICFGNode_val = llvm::json::Object{ICFGNode_Obj};
126  root_array.push_back(ICFGNode_val);
127  }
128  llvm::json::Value root_value = llvm::json::Array{root_array};
129  llvm::json::operator<<(F.os(),root_value);
130 
131  F.os().close();
132  if (!F.os().has_error())
133  {
134  outs() << "\n";
135  F.keep();
136  return;
137  }
138 }
iterator begin()
Iterators.
Definition: GenericGraph.h:365
GEdgeKind getEdgeKind() const
Definition: GenericGraph.h:81
VOID_OR_INT exit()
NodeID getDstID() const
Definition: GenericGraph.h:77
u32_t NodeID
Definition: SVFBasicTypes.h:80
iterator OutEdgeBegin()
iterators
Definition: GenericGraph.h:201
#define assert(ex)
Definition: util.h:141
NodeID getSrcID() const
get methods of the components
Definition: GenericGraph.h:73
std::string getSourceLoc(const Value *val)
Return source code including line number and file name from debug information.
Definition: SVFUtil.cpp:259
GNodeK getNodeKind() const
Get node kind.
Definition: GenericGraph.h:170
static int * entry
Definition: cuddGroup.c:119
static PAG * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis. ...
Definition: PAG.h:160
NodeType * getDstNode() const
Definition: GenericGraph.h:89
std::vector< const PAGEdge * > PAGEdgeList
Definition: PAG.h:56
PAGEdgeList & getInstPTAPAGEdgeList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
Definition: PAG.h:232
llvm::ToolOutputFile ToolOutputFile
Definition: BasicTypes.h:103
NodeType * getSrcNode() const
Definition: GenericGraph.h:85
ICFGNodeIDToNodeMapTy::iterator iterator
Definition: ICFG.h:53
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
ICFGEdge::ICFGEdgeSetTy::iterator iterator
Definition: ICFGNode.h:65
raw_ostream & operator<<(raw_ostream &o, const std::pair< F, S > &var)
Definition: BasicTypes.h:341
NodeID getId() const
Get ID.
Definition: GenericGraph.h:164
std::string getICFGKind(const int kind)
Definition: Graph2Json.cpp:140
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:343
iterator OutEdgeEnd()
Definition: GenericGraph.h:205
u32_t getOffset() const
offset of the gep edge
Definition: PAGEdge.h:507
std::string getPAGNodeKindValue(int kind)
Definition: Graph2Json.cpp:165
std::string getPAGEdgeKindValue(int kind)
Definition: Graph2Json.cpp:200
llvm::Value Value
Definition: BasicTypes.h:78
bool isExtCall(const SVFFunction *fun)
Definition: LLVMUtil.h:64

The documentation for this class was generated from the following files: