Static Value-Flow Analysis
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Static Private Attributes | Friends | List of all members
SVF::CallGraph Class Reference

#include <CallGraph.h>

Inheritance diagram for SVF::CallGraph:
SVF::GenericGraph< NodeTy, EdgeTy > SVF::ThreadCallGraph

Public Types

enum  CGEK { NormCallGraph , ThdCallGraph }
 
typedef CallGraphEdge::CallGraphEdgeSet CallGraphEdgeSet
 
typedef Map< const FunObjVar *, CallGraphNode * > FunToCallGraphNodeMap
 
typedef Map< const CallICFGNode *, CallGraphEdgeSetCallInstToCallGraphEdgesMap
 
typedef std::pair< const CallICFGNode *, const FunObjVar * > CallSitePair
 
typedef Map< CallSitePair, CallSiteIDCallSiteToIdMap
 
typedef Map< CallSiteID, CallSitePairIdToCallSiteMap
 
typedef Set< const FunObjVar * > FunctionSet
 
typedef OrderedMap< const CallICFGNode *, FunctionSetCallEdgeMap
 
typedef CallGraphEdgeSet::iterator CallGraphEdgeIter
 
typedef CallGraphEdgeSet::const_iterator CallGraphEdgeConstIter
 
- Public Types inherited from SVF::GenericGraph< NodeTy, EdgeTy >
typedef NodeTy NodeType
 
typedef EdgeTy EdgeType
 
typedef OrderedMap< NodeID, NodeType * > IDToNodeMapTy
 NodeID to GenericNode map.
 
typedef IDToNodeMapTy::iterator iterator
 Node Iterators.
 
typedef IDToNodeMapTy::const_iterator const_iterator
 

Public Member Functions

 CallGraph (CGEK k=NormCallGraph)
 Constructor.
 
 CallGraph (const CallGraph &other)
 Copy constructor.
 
virtual ~CallGraph ()
 Destructor.
 
CGEK getKind () const
 Return type of this callgraph.
 
CallEdgeMapgetIndCallMap ()
 Get callees from an indirect callsite.
 
bool hasIndCSCallees (const CallICFGNode *cs) const
 
const FunctionSetgetIndCSCallees (const CallICFGNode *cs) const
 
u32_t getTotalCallSiteNumber () const
 
u32_t getNumOfResolvedIndCallEdge () const
 
const CallInstToCallGraphEdgesMapgetCallInstToCallGraphEdgesMap () const
 
void verifyCallGraph ()
 Issue a warning if the function which has indirect call sites can not be reached from program entry.
 
void addDirectCallGraphEdge (const CallICFGNode *call, const FunObjVar *callerFun, const FunObjVar *calleeFun)
 Add direct call edges.
 
void addCallGraphNode (const FunObjVar *fun)
 
const CallGraphNodegetCallGraphNode (const std::string &name) const
 Get call graph node.
 
CallGraphNodegetCallGraphNode (NodeID id) const
 
CallGraphNodegetCallGraphNode (const FunObjVar *fun) const
 
CallSiteID getCallSiteID (const CallICFGNode *cs, const FunObjVar *callee) const
 Get CallSiteID.
 
bool hasCallSiteID (const CallICFGNode *cs, const FunObjVar *callee) const
 
const CallSitePairgetCallSitePair (CallSiteID id) const
 
const CallICFGNodegetCallSite (CallSiteID id) const
 
const FunObjVargetCallerOfCallSite (CallSiteID id) const
 
const FunObjVargetCalleeOfCallSite (CallSiteID id) const
 
CallGraphEdgehasGraphEdge (CallGraphNode *src, CallGraphNode *dst, CallGraphEdge::CEDGEK kind, CallSiteID csId) const
 Whether we have already created this call graph edge.
 
CallGraphEdgegetGraphEdge (CallGraphNode *src, CallGraphNode *dst, CallGraphEdge::CEDGEK kind, CallSiteID csId)
 Get call graph edge via nodes.
 
void getCallees (const CallICFGNode *cs, FunctionSet &callees)
 Get all callees for a callsite.
 
bool hasCallGraphEdge (const CallICFGNode *inst) const
 Get call graph edge via call instruction.
 
CallGraphEdgeSet::const_iterator getCallEdgeBegin (const CallICFGNode *inst) const
 
CallGraphEdgeSet::const_iterator getCallEdgeEnd (const CallICFGNode *inst) const
 
void addIndirectCallGraphEdge (const CallICFGNode *cs, const FunObjVar *callerFun, const FunObjVar *calleeFun)
 Add indirect call edges.
 
void getAllCallSitesInvokingCallee (const FunObjVar *callee, CallGraphEdge::CallInstSet &csSet)
 Get callsites invoking the callee.
 
void getDirCallSitesInvokingCallee (const FunObjVar *callee, CallGraphEdge::CallInstSet &csSet)
 
void getIndCallSitesInvokingCallee (const FunObjVar *callee, CallGraphEdge::CallInstSet &csSet)
 
bool isReachableBetweenFunctions (const FunObjVar *srcFn, const FunObjVar *dstFn) const
 Whether its reachable between two functions.
 
void dump (const std::string &filename)
 Dump the graph.
 
void view ()
 View the graph from the debugger.
 
- Public Member Functions inherited from SVF::GenericGraph< NodeTy, EdgeTy >
 GenericGraph ()
 Constructor.
 
virtual ~GenericGraph ()
 Destructor.
 
void destroy ()
 Release memory.
 
iterator begin ()
 Iterators.
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
void addGNode (NodeID id, NodeType *node)
 Add a Node.
 
NodeTypegetGNode (NodeID id) const
 Get a node.
 
bool hasGNode (NodeID id) const
 Has a node.
 
void removeGNode (NodeType *node)
 Delete a node.
 
u32_t getTotalNodeNum () const
 Get total number of node/edge.
 
u32_t getTotalEdgeNum () const
 
void incNodeNum ()
 Increase number of node/edge.
 
void incEdgeNum ()
 

Protected Member Functions

void destroy ()
 Clean up memory.
 
CallSiteID addCallSite (const CallICFGNode *cs, const FunObjVar *callee)
 Add CallSiteID.
 
CallSiteID addCallSite (const CallICFGNode *cs, const FunObjVar *callee, const CallSiteID csid, std::pair< const CallICFGNode *, const FunObjVar * > newCS)
 
void addEdge (CallGraphEdge *edge)
 Add call graph edge.
 
void addDirectCallGraphEdge (CallGraphEdge *cgEdge)
 add direct call graph edge from database [only used this function when loading cgEdges from db results]
 
void addCallGraphNode (CallGraphNode *cgNode)
 add call graph node from database [only used this function when loading cgNodes from db results]
 
CallGraphEdgehasGraphEdge (CallGraphEdge *cgEdge) const
 Whether we have already created this call graph edge.
 

Protected Attributes

FunToCallGraphNodeMap funToCallGraphNodeMap
 Call Graph node map.
 
CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap
 Map a call instruction to its corresponding call edges.
 
NodeID callGraphNodeNum
 
u32_t numOfResolvedIndCallEdge
 
CGEK kind
 
- Protected Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
IDToNodeMapTy IDToNodeMap
 node map
 

Private Attributes

CallEdgeMap indirectCallMap
 Indirect call map.
 

Static Private Attributes

static CallSiteToIdMap csToIdMap
 Call site information.
 
static IdToCallSiteMap idToCSMap
 Map a callsite ID to a pair of call instruction and callee.
 
static CallSiteID totalCallSiteNum =1
 CallSiteIDs, start from 1;.
 

Friends

class GraphDBClient
 

Additional Inherited Members

- Public Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
u32_t edgeNum
 total num of node
 
u32_t nodeNum
 total num of edge
 

Detailed Description

Definition at line 235 of file CallGraph.h.

Member Typedef Documentation

◆ CallEdgeMap

Definition at line 248 of file CallGraph.h.

◆ CallGraphEdgeConstIter

typedef CallGraphEdgeSet::const_iterator SVF::CallGraph::CallGraphEdgeConstIter

Definition at line 250 of file CallGraph.h.

◆ CallGraphEdgeIter

typedef CallGraphEdgeSet::iterator SVF::CallGraph::CallGraphEdgeIter

Definition at line 249 of file CallGraph.h.

◆ CallGraphEdgeSet

Definition at line 241 of file CallGraph.h.

◆ CallInstToCallGraphEdgesMap

Definition at line 243 of file CallGraph.h.

◆ CallSitePair

Definition at line 244 of file CallGraph.h.

◆ CallSiteToIdMap

Definition at line 245 of file CallGraph.h.

◆ FunctionSet

Definition at line 247 of file CallGraph.h.

◆ FunToCallGraphNodeMap

Definition at line 242 of file CallGraph.h.

◆ IdToCallSiteMap

Definition at line 246 of file CallGraph.h.

Member Enumeration Documentation

◆ CGEK

Enumerator
NormCallGraph 
ThdCallGraph 

Definition at line 252 of file CallGraph.h.

Constructor & Destructor Documentation

◆ CallGraph() [1/2]

CallGraph::CallGraph ( CGEK  k = NormCallGraph)

Constructor.

Definition at line 122 of file CallGraph.cpp.

122 : kind(k)
123{
126}
NodeID callGraphNodeNum
Definition CallGraph.h:270
u32_t numOfResolvedIndCallEdge
Definition CallGraph.h:271
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74

◆ CallGraph() [2/2]

CallGraph::CallGraph ( const CallGraph other)

Copy constructor.

copy call graph nodes

copy edges

Definition at line 129 of file CallGraph.cpp.

130{
131 callGraphNodeNum = other.getTotalNodeNum();
134
136 for (const auto& item : other)
137 {
138 const CallGraphNode* cgn = item.second;
139 CallGraphNode* callGraphNode = new CallGraphNode(cgn->getId(), cgn->getFunction());
140 addGNode(cgn->getId(),callGraphNode);
141 funToCallGraphNodeMap[cgn->getFunction()] = callGraphNode;
142 }
143
145 for (const auto& item : other.callinstToCallGraphEdgesMap)
146 {
147 const CallICFGNode* cs = item.first;
148 for (const CallGraphEdge* edge : item.second)
149 {
150 CallGraphNode* src = getCallGraphNode(edge->getSrcID());
151 CallGraphNode* dst = getCallGraphNode(edge->getDstID());
152 CallSiteID csId = addCallSite(cs, dst->getFunction());
153
155 newEdge->addDirectCallSite(cs);
158 }
159 }
160
161}
cJSON * item
Definition cJSON.h:222
const FunObjVar * getFunction() const
Get function of this call node.
Definition CallGraph.h:191
CallInstToCallGraphEdgesMap callinstToCallGraphEdgesMap
Map a call instruction to its corresponding call edges.
Definition CallGraph.h:268
void addEdge(CallGraphEdge *edge)
Add call graph edge.
Definition CallGraph.h:296
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
CallSiteID addCallSite(const CallICFGNode *cs, const FunObjVar *callee)
Add CallSiteID.
Definition CallGraph.h:279
FunToCallGraphNodeMap funToCallGraphNodeMap
Call Graph node map.
Definition CallGraph.h:267
void addGNode(NodeID id, NodeType *node)
Add a Node.
unsigned CallSiteID
Definition GeneralType.h:58

◆ ~CallGraph()

virtual SVF::CallGraph::~CallGraph ( )
inlinevirtual

Destructor.

Definition at line 318 of file CallGraph.h.

319 {
320 destroy();
321 }
void destroy()
Clean up memory.

Member Function Documentation

◆ addCallGraphNode() [1/2]

void CallGraph::addCallGraphNode ( CallGraphNode cgNode)
protected

add call graph node from database [only used this function when loading cgNodes from db results]

Definition at line 378 of file CallGraph.cpp.

379{
380 addGNode(cgNode->getId(), cgNode);
381 funToCallGraphNodeMap[cgNode->getFunction()] = cgNode;
383}
NodeID getId() const
Get ID.
Definition SVFValue.h:160

◆ addCallGraphNode() [2/2]

void CallGraph::addCallGraphNode ( const FunObjVar fun)

Add call graph node

Definition at line 371 of file CallGraph.cpp.

372{
374 CallGraphNode*callGraphNode = new CallGraphNode(id, fun);
375 addCallGraphNode(callGraphNode);
376}
void addCallGraphNode(CallGraphNode *cgNode)
add call graph node from database [only used this function when loading cgNodes from db results]
u32_t NodeID
Definition GeneralType.h:56

◆ addCallSite() [1/2]

CallSiteID SVF::CallGraph::addCallSite ( const CallICFGNode cs,
const FunObjVar callee 
)
inlineprotected

Add CallSiteID.

Definition at line 279 of file CallGraph.h.

280 {
281 std::pair<const CallICFGNode*, const FunObjVar*> newCS(std::make_pair(cs, callee));
282 CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS);
283 //assert(it == csToIdMap.end() && "cannot add a callsite twice");
284 if(it == csToIdMap.end())
285 {
287 addCallSite(cs,callee,id, newCS);
288 return id;
289 }
290 return it->second;
291 }
static CallSiteID totalCallSiteNum
CallSiteIDs, start from 1;.
Definition CallGraph.h:264
static CallSiteToIdMap csToIdMap
Call site information.
Definition CallGraph.h:262

◆ addCallSite() [2/2]

CallSiteID CallGraph::addCallSite ( const CallICFGNode cs,
const FunObjVar callee,
const CallSiteID  csid,
std::pair< const CallICFGNode *, const FunObjVar * >  newCS 
)
protected

Definition at line 163 of file CallGraph.cpp.

164{
165 csToIdMap.insert(std::make_pair(newCS, csid));
166 idToCSMap.insert(std::make_pair(csid, newCS));
167 return csid;
168}
static IdToCallSiteMap idToCSMap
Map a callsite ID to a pair of call instruction and callee.
Definition CallGraph.h:263

◆ addDirectCallGraphEdge() [1/2]

void CallGraph::addDirectCallGraphEdge ( CallGraphEdge cgEdge)
protected

add direct call graph edge from database [only used this function when loading cgEdges from db results]

Definition at line 414 of file CallGraph.cpp.

415{
417}

◆ addDirectCallGraphEdge() [2/2]

void CallGraph::addDirectCallGraphEdge ( const CallICFGNode cs,
const FunObjVar callerFun,
const FunObjVar calleeFun 
)

Add direct call edges.

Add direct call edges

Definition at line 398 of file CallGraph.cpp.

399{
400
403 CallSiteID csId = addCallSite(cs, calleeFun);
404
406 {
408 edge->addDirectCallSite(cs);
411 }
412}
CallGraphEdge * hasGraphEdge(CallGraphEdge *cgEdge) const
Whether we have already created this call graph edge.
void addDirectCallGraphEdge(CallGraphEdge *cgEdge)
add direct call graph edge from database [only used this function when loading cgEdges from db result...

◆ addEdge()

void SVF::CallGraph::addEdge ( CallGraphEdge edge)
inlineprotected

Add call graph edge.

Definition at line 296 of file CallGraph.h.

297 {
298 edge->getDstNode()->addIncomingEdge(edge);
299 edge->getSrcNode()->addOutgoingEdge(edge);
300 }

◆ addIndirectCallGraphEdge()

void CallGraph::addIndirectCallGraphEdge ( const CallICFGNode cs,
const FunObjVar callerFun,
const FunObjVar calleeFun 
)

Add indirect call edges.

Add indirect call edge to update call graph

Definition at line 222 of file CallGraph.cpp.

223{
224
227
229
230 CallSiteID csId = addCallSite(cs, callee->getFunction());
231
233 {
235 edge->addInDirectCallSite(cs);
236 addEdge(edge);
238 }
239}

◆ destroy()

void CallGraph::destroy ( )
protected

Clean up memory.

Memory has been cleaned up at GenericGraph

Definition at line 173 of file CallGraph.cpp.

174{
175}

◆ dump()

void CallGraph::dump ( const std::string &  filename)

Dump the graph.

Dump call graph into dot file

Definition at line 357 of file CallGraph.cpp.

358{
360}
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52

◆ getAllCallSitesInvokingCallee()

void CallGraph::getAllCallSitesInvokingCallee ( const FunObjVar callee,
CallGraphEdge::CallInstSet csSet 
)

Get callsites invoking the callee.

Get all callsite invoking this callee

Definition at line 244 of file CallGraph.cpp.

245{
246 CallGraphNode* callGraphNode = getCallGraphNode(callee);
247 for(CallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd();
248 it!=eit; ++it)
249 {
250 for(CallGraphEdge::CallInstSet::const_iterator cit = (*it)->directCallsBegin(),
251 ecit = (*it)->directCallsEnd(); cit!=ecit; ++cit)
252 {
253 csSet.insert((*cit));
254 }
255 for(CallGraphEdge::CallInstSet::const_iterator cit = (*it)->indirectCallsBegin(),
256 ecit = (*it)->indirectCallsEnd(); cit!=ecit; ++cit)
257 {
258 csSet.insert((*cit));
259 }
260 }
261}
GEdgeSetTy::iterator iterator
iterator InEdgeBegin()
iterator InEdgeEnd()

◆ getCallEdgeBegin()

CallGraphEdgeSet::const_iterator SVF::CallGraph::getCallEdgeBegin ( const CallICFGNode inst) const
inline

Definition at line 445 of file CallGraph.h.

446 {
447 CallInstToCallGraphEdgesMap::const_iterator it = callinstToCallGraphEdgesMap.find(inst);
449 && "call instruction does not have a valid callee");
450 return it->second.begin();
451 }

◆ getCallEdgeEnd()

CallGraphEdgeSet::const_iterator SVF::CallGraph::getCallEdgeEnd ( const CallICFGNode inst) const
inline

Definition at line 452 of file CallGraph.h.

453 {
454 CallInstToCallGraphEdgesMap::const_iterator it = callinstToCallGraphEdgesMap.find(inst);
456 && "call instruction does not have a valid callee");
457 return it->second.end();
458 }

◆ getCalleeOfCallSite()

const FunObjVar * SVF::CallGraph::getCalleeOfCallSite ( CallSiteID  id) const
inline

Definition at line 413 of file CallGraph.h.

414 {
415 return getCallSitePair(id).second;
416 }
const CallSitePair & getCallSitePair(CallSiteID id) const
Definition CallGraph.h:402

◆ getCallees()

void SVF::CallGraph::getCallees ( const CallICFGNode cs,
FunctionSet callees 
)
inline

Get all callees for a callsite.

Definition at line 426 of file CallGraph.h.

427 {
428 if(hasCallGraphEdge(cs))
429 {
430 for (CallGraphEdgeSet::const_iterator it = getCallEdgeBegin(cs), eit =
431 getCallEdgeEnd(cs); it != eit; ++it)
432 {
433 callees.insert((*it)->getDstNode()->getFunction());
434 }
435 }
436 }
CallGraphEdgeSet::const_iterator getCallEdgeBegin(const CallICFGNode *inst) const
Definition CallGraph.h:445
bool hasCallGraphEdge(const CallICFGNode *inst) const
Get call graph edge via call instruction.
Definition CallGraph.h:441
CallGraphEdgeSet::const_iterator getCallEdgeEnd(const CallICFGNode *inst) const
Definition CallGraph.h:452

◆ getCallerOfCallSite()

const FunObjVar * CallGraph::getCallerOfCallSite ( CallSiteID  id) const

Definition at line 89 of file CallGraph.cpp.

90{
91 return getCallSite(id)->getCaller();
92}
const CallICFGNode * getCallSite(CallSiteID id) const
Definition CallGraph.h:408
const FunObjVar * getCaller() const
Return callsite.
Definition ICFGNode.h:452

◆ getCallGraphNode() [1/3]

CallGraphNode * SVF::CallGraph::getCallGraphNode ( const FunObjVar fun) const
inline

Definition at line 378 of file CallGraph.h.

379 {
380 FunToCallGraphNodeMap::const_iterator it = funToCallGraphNodeMap.find(fun);
381 assert(it!=funToCallGraphNodeMap.end() && "call graph node not found!!");
382 return it->second;
383 }

◆ getCallGraphNode() [2/3]

const CallGraphNode * CallGraph::getCallGraphNode ( const std::string &  name) const

Get call graph node.

Definition at line 385 of file CallGraph.cpp.

386{
387 for (const auto& item : *this)
388 {
389 if (item.second->getName() == name)
390 return item.second;
391 }
392 return nullptr;
393}
const char *const name
Definition cJSON.h:264

◆ getCallGraphNode() [3/3]

CallGraphNode * SVF::CallGraph::getCallGraphNode ( NodeID  id) const
inline

Definition at line 374 of file CallGraph.h.

375 {
376 return getGNode(id);
377 }
NodeType * getGNode(NodeID id) const
Get a node.

◆ getCallInstToCallGraphEdgesMap()

const CallInstToCallGraphEdgesMap & SVF::CallGraph::getCallInstToCallGraphEdgesMap ( ) const
inline

Definition at line 356 of file CallGraph.h.

357 {
359 }

◆ getCallSite()

const CallICFGNode * SVF::CallGraph::getCallSite ( CallSiteID  id) const
inline

Definition at line 408 of file CallGraph.h.

409 {
410 return getCallSitePair(id).first;
411 }

◆ getCallSiteID()

CallSiteID SVF::CallGraph::getCallSiteID ( const CallICFGNode cs,
const FunObjVar callee 
) const
inline

Get CallSiteID.

Definition at line 389 of file CallGraph.h.

390 {
391 CallSitePair newCS(std::make_pair(cs, callee));
392 CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS);
393 assert(it != csToIdMap.end() && "callsite id not found! This maybe a partially resolved callgraph, please check the indCallEdge limit");
394 return it->second;
395 }
std::pair< const CallICFGNode *, const FunObjVar * > CallSitePair
Definition CallGraph.h:244

◆ getCallSitePair()

const CallSitePair & SVF::CallGraph::getCallSitePair ( CallSiteID  id) const
inline

Definition at line 402 of file CallGraph.h.

403 {
404 IdToCallSiteMap::const_iterator it = idToCSMap.find(id);
405 assert(it != idToCSMap.end() && "cannot find call site for this CallSiteID");
406 return (it->second);
407 }

◆ getDirCallSitesInvokingCallee()

void CallGraph::getDirCallSitesInvokingCallee ( const FunObjVar callee,
CallGraphEdge::CallInstSet csSet 
)

Get direct callsite invoking this callee

Definition at line 266 of file CallGraph.cpp.

267{
268 CallGraphNode* callGraphNode = getCallGraphNode(callee);
269 for(CallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd();
270 it!=eit; ++it)
271 {
272 for(CallGraphEdge::CallInstSet::const_iterator cit = (*it)->directCallsBegin(),
273 ecit = (*it)->directCallsEnd(); cit!=ecit; ++cit)
274 {
275 csSet.insert((*cit));
276 }
277 }
278}

◆ getGraphEdge()

CallGraphEdge * CallGraph::getGraphEdge ( CallGraphNode src,
CallGraphNode dst,
CallGraphEdge::CEDGEK  kind,
CallSiteID  csId 
)

Get call graph edge via nodes.

get PTACallGraph edge via nodes

Definition at line 204 of file CallGraph.cpp.

207{
208 for (CallGraphEdge::CallGraphEdgeSet::iterator iter = src->OutEdgeBegin();
209 iter != src->OutEdgeEnd(); ++iter)
210 {
211 CallGraphEdge* edge = (*iter);
212 if (edge->getEdgeKind() == kind && edge->getDstID() == dst->getId())
213 return edge;
214 }
215 return nullptr;
216}
iterator OutEdgeEnd()
iterator OutEdgeBegin()
iterators

◆ getIndCallMap()

CallEdgeMap & SVF::CallGraph::getIndCallMap ( )
inline

Get callees from an indirect callsite.

Definition at line 331 of file CallGraph.h.

332 {
333 return indirectCallMap;
334 }
CallEdgeMap indirectCallMap
Indirect call map.
Definition CallGraph.h:259

◆ getIndCallSitesInvokingCallee()

void CallGraph::getIndCallSitesInvokingCallee ( const FunObjVar callee,
CallGraphEdge::CallInstSet csSet 
)

Get indirect callsite invoking this callee

Definition at line 283 of file CallGraph.cpp.

284{
285 CallGraphNode* callGraphNode = getCallGraphNode(callee);
286 for(CallGraphNode::iterator it = callGraphNode->InEdgeBegin(), eit = callGraphNode->InEdgeEnd();
287 it!=eit; ++it)
288 {
289 for(CallGraphEdge::CallInstSet::const_iterator cit = (*it)->indirectCallsBegin(),
290 ecit = (*it)->indirectCallsEnd(); cit!=ecit; ++cit)
291 {
292 csSet.insert((*cit));
293 }
294 }
295}

◆ getIndCSCallees()

const FunctionSet & SVF::CallGraph::getIndCSCallees ( const CallICFGNode cs) const
inline

Definition at line 339 of file CallGraph.h.

340 {
341 CallEdgeMap::const_iterator it = indirectCallMap.find(cs);
342 assert(it!=indirectCallMap.end() && "not an indirect callsite!");
343 return it->second;
344 }

◆ getKind()

CGEK SVF::CallGraph::getKind ( ) const
inline

Return type of this callgraph.

Definition at line 324 of file CallGraph.h.

325 {
326 return kind;
327 }

◆ getNumOfResolvedIndCallEdge()

u32_t SVF::CallGraph::getNumOfResolvedIndCallEdge ( ) const
inline

Definition at line 351 of file CallGraph.h.

352 {
354 }

◆ getTotalCallSiteNumber()

u32_t SVF::CallGraph::getTotalCallSiteNumber ( ) const
inline

Definition at line 346 of file CallGraph.h.

347 {
348 return totalCallSiteNum;
349 }

◆ hasCallGraphEdge()

bool SVF::CallGraph::hasCallGraphEdge ( const CallICFGNode inst) const
inline

Get call graph edge via call instruction.

whether this call instruction has a valid call graph edge

Definition at line 441 of file CallGraph.h.

442 {
444 }

◆ hasCallSiteID()

bool SVF::CallGraph::hasCallSiteID ( const CallICFGNode cs,
const FunObjVar callee 
) const
inline

Definition at line 396 of file CallGraph.h.

397 {
398 CallSitePair newCS(std::make_pair(cs, callee));
399 CallSiteToIdMap::const_iterator it = csToIdMap.find(newCS);
400 return it != csToIdMap.end();
401 }

◆ hasGraphEdge() [1/2]

CallGraphEdge * CallGraph::hasGraphEdge ( CallGraphEdge cgEdge) const
protected

Whether we have already created this call graph edge.

Definition at line 188 of file CallGraph.cpp.

189{
190 CallGraphEdge* outEdge = cgEdge->getSrcNode()->hasOutgoingEdge(cgEdge);
191 CallGraphEdge* inEdge = cgEdge->getDstNode()->hasIncomingEdge(cgEdge);
192 if (outEdge && inEdge)
193 {
194 assert(outEdge == inEdge && "edges not match");
195 return outEdge;
196 }
197 else
198 return nullptr;
199}
NodeType * getSrcNode() const
NodeType * getDstNode() const

◆ hasGraphEdge() [2/2]

CallGraphEdge * CallGraph::hasGraphEdge ( CallGraphNode src,
CallGraphNode dst,
CallGraphEdge::CEDGEK  kind,
CallSiteID  csId 
) const

Whether we have already created this call graph edge.

Whether we have already created this call graph edge

Definition at line 180 of file CallGraph.cpp.

183{
184 CallGraphEdge edge(src,dst,kind,csId);
185 return hasGraphEdge(&edge);
186}

◆ hasIndCSCallees()

bool SVF::CallGraph::hasIndCSCallees ( const CallICFGNode cs) const
inline

Definition at line 335 of file CallGraph.h.

336 {
337 return (indirectCallMap.find(cs) != indirectCallMap.end());
338 }

◆ isReachableBetweenFunctions()

bool CallGraph::isReachableBetweenFunctions ( const FunObjVar srcFn,
const FunObjVar dstFn 
) const

Whether its reachable between two functions.

Whether its reachable between two functions

Definition at line 326 of file CallGraph.cpp.

327{
329
330 std::stack<const CallGraphNode*> nodeStack;
332 nodeStack.push(dstNode);
333 visitedNodes.set(dstNode->getId());
334
335 while (nodeStack.empty() == false)
336 {
337 CallGraphNode* node = const_cast<CallGraphNode*>(nodeStack.top());
338 nodeStack.pop();
339
340 if (node->getFunction() == srcFn)
341 return true;
342
343 for (CallGraphEdgeConstIter it = node->InEdgeBegin(), eit = node->InEdgeEnd(); it != eit; ++it)
344 {
346 if (visitedNodes.test_and_set(edge->getSrcID()))
347 nodeStack.push(edge->getSrcNode());
348 }
349 }
350
351 return false;
352}
CallGraphEdgeSet::const_iterator CallGraphEdgeConstIter
Definition CallGraph.h:250
void set(unsigned Idx)

◆ verifyCallGraph()

void CallGraph::verifyCallGraph ( )

Issue a warning if the function which has indirect call sites can not be reached from program entry.

Issue a warning if the function which has indirect call sites can not be reached from program entry.

Definition at line 300 of file CallGraph.cpp.

301{
303 return;
304
307 CallEdgeMap::const_iterator it = indirectCallMap.begin();
308 CallEdgeMap::const_iterator eit = indirectCallMap.end();
309 for (; it != eit; ++it)
310 {
311 const FunctionSet& targets = it->second;
312 if (targets.empty() == false)
313 {
314 const CallICFGNode* cs = it->first;
315 const FunObjVar* func = cs->getCaller();
317 isReachableFromProgEntry(reachableFromEntry, visitedNodes) == false)
318 writeWrnMsg(func->getName() + " has indirect call site but not reachable from main");
319 }
320 }
321}
Set< const FunObjVar * > FunctionSet
Definition CallGraph.h:247
static const Option< bool > DisableWarn
Definition Options.h:202
iterator begin() const
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition SVFUtil.cpp:68

◆ view()

void CallGraph::view ( )

View the graph from the debugger.

Definition at line 362 of file CallGraph.cpp.

363{
364 SVF::ViewGraph(this, "Call Graph");
365}
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)

Friends And Related Symbol Documentation

◆ GraphDBClient

friend class GraphDBClient
friend

Definition at line 237 of file CallGraph.h.

Member Data Documentation

◆ callGraphNodeNum

NodeID SVF::CallGraph::callGraphNodeNum
protected

Definition at line 270 of file CallGraph.h.

◆ callinstToCallGraphEdgesMap

CallInstToCallGraphEdgesMap SVF::CallGraph::callinstToCallGraphEdgesMap
protected

Map a call instruction to its corresponding call edges.

Definition at line 268 of file CallGraph.h.

◆ csToIdMap

CallGraph::CallSiteToIdMap CallGraph::csToIdMap
staticprivate

Call site information.

Map a pair of call instruction and callee to a callsite ID

Definition at line 262 of file CallGraph.h.

◆ funToCallGraphNodeMap

FunToCallGraphNodeMap SVF::CallGraph::funToCallGraphNodeMap
protected

Call Graph node map.

Definition at line 267 of file CallGraph.h.

◆ idToCSMap

CallGraph::IdToCallSiteMap CallGraph::idToCSMap
staticprivate

Map a callsite ID to a pair of call instruction and callee.

Definition at line 263 of file CallGraph.h.

◆ indirectCallMap

CallEdgeMap SVF::CallGraph::indirectCallMap
private

Indirect call map.

Definition at line 259 of file CallGraph.h.

◆ kind

CGEK SVF::CallGraph::kind
protected

Definition at line 272 of file CallGraph.h.

◆ numOfResolvedIndCallEdge

u32_t SVF::CallGraph::numOfResolvedIndCallEdge
protected

Definition at line 271 of file CallGraph.h.

◆ totalCallSiteNum

CallSiteID CallGraph::totalCallSiteNum =1
staticprivate

CallSiteIDs, start from 1;.

Definition at line 264 of file CallGraph.h.


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