Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::FunptrDDAClient Class Reference

#include <DDAClient.h>

Inheritance diagram for SVF::FunptrDDAClient:
SVF::DDAClient

Public Member Functions

 FunptrDDAClient ()
 ~FunptrDDAClient ()
virtual OrderedNodeSet & collectCandidateQueries (SVFIR *p)
 Only collect function pointers as query candidates.
virtual void performStat (PointerAnalysis *pta)
Public Member Functions inherited from SVF::DDAClient
 DDAClient ()
virtual ~DDAClient ()
virtual void initialise ()
const OrderedNodeSet & getCandidateQueries () const
 Get candidate queries.
virtual void handleStatement (const SVFGNode *, NodeID)
 Call back used by DDAVFSolver.
void setPAG (SVFIR *g)
 Set SVFIR graph.
void setCurrentQueryPtr (NodeID ptr)
 Set the pointer being queried.
void setQuery (NodeID ptr)
 Set pointer to be queried by DDA analysis.
virtual void answerQueries (PointerAnalysis *pta)
virtual void collectWPANum ()

Private Types

typedef OrderedMap< NodeID, const CallICFGNode * > VTablePtrToCallSiteMap

Private Attributes

VTablePtrToCallSiteMap vtableToCallSiteMap

Additional Inherited Members

Protected Member Functions inherited from SVF::DDAClient
void addCandidate (NodeID id)
Protected Attributes inherited from SVF::DDAClient
SVFIR * pag
 SVFIR graph used by current DDA analysis.
NodeID curPtr
 current pointer being queried
OrderedNodeSet candidateQueries
 store all candidate pointers to be queried

Detailed Description

DDA client with function pointers as query candidates.

Definition at line 120 of file DDAClient.h.

Member Typedef Documentation

◆ VTablePtrToCallSiteMap

Definition at line 123 of file DDAClient.h.

Constructor & Destructor Documentation

◆ FunptrDDAClient()

SVF::FunptrDDAClient::FunptrDDAClient ( )
inline

Definition at line 126 of file DDAClient.h.

126: DDAClient() {}

◆ ~FunptrDDAClient()

SVF::FunptrDDAClient::~FunptrDDAClient ( )
inline

Definition at line 127 of file DDAClient.h.

127{}

Member Function Documentation

◆ collectCandidateQueries()

OrderedNodeSet & FunptrDDAClient::collectCandidateQueries ( SVFIR * p)
virtual

Only collect function pointers as query candidates.

Reimplemented from SVF::DDAClient.

Definition at line 80 of file DDAClient.cpp.

81{
82 setPAG(p);
83 for(SVFIR::CallSiteToFunPtrMap::const_iterator it = pag->getIndirectCallsites().begin(),
84 eit = pag->getIndirectCallsites().end(); it!=eit; ++it)
85 {
86 if (it->first->isVirtualCall())
87 {
88 const SVFVar* vtblPtr = it->first->getVtablePtr();
89 assert(vtblPtr != nullptr && "not a vtable pointer?");
90 NodeID vtblId = vtblPtr->getId();
91 addCandidate(vtblId);
92 vtableToCallSiteMap[vtblId] = it->first;
93 }
94 else
95 {
96 addCandidate(it->second);
97 }
98 }
99 return candidateQueries;
100}
cJSON * p
Definition cJSON.cpp:2559
void setPAG(SVFIR *g)
Set SVFIR graph.
Definition DDAClient.h:79
SVFIR * pag
SVFIR graph used by current DDA analysis.
Definition DDAClient.h:107
void addCandidate(NodeID id)
Definition DDAClient.h:101
OrderedNodeSet candidateQueries
store all candidate pointers to be queried
Definition DDAClient.h:109
VTablePtrToCallSiteMap vtableToCallSiteMap
Definition DDAClient.h:124
NodeID getId() const
Get ID.
Definition SVFValue.h:158
u32_t NodeID
Definition GeneralType.h:76

◆ performStat()

void FunptrDDAClient::performStat ( PointerAnalysis * pta)
virtual

Reimplemented from SVF::DDAClient.

Definition at line 102 of file DDAClient.cpp.

103{
104
105 AndersenWaveDiff* ander = AndersenWaveDiff::createAndersenWaveDiff(pta->getPAG());
106 u32_t totalCallsites = 0;
107 u32_t morePreciseCallsites = 0;
108 u32_t zeroTargetCallsites = 0;
109 u32_t oneTargetCallsites = 0;
110 u32_t twoTargetCallsites = 0;
111 u32_t moreThanTwoCallsites = 0;
112
113 for (VTablePtrToCallSiteMap::iterator nIter = vtableToCallSiteMap.begin();
114 nIter != vtableToCallSiteMap.end(); ++nIter)
115 {
116 NodeID vtptr = nIter->first;
117 const PointsTo& ddaPts = pta->getPts(vtptr);
118 const PointsTo& anderPts = ander->getPts(vtptr);
119
120 CallGraph* callgraph = ander->getCallGraph();
121 const CallICFGNode* cbn = nIter->second;
122
123 if(!callgraph->hasIndCSCallees(cbn))
124 {
125 //outs() << "virtual callsite has no callee" << *(nIter->second.getInstruction()) << "\n";
126 continue;
127 }
128
129 const CallGraph::FunctionSet& callees = callgraph->getIndCSCallees(cbn);
130 totalCallsites++;
131 if(callees.size() == 0)
132 zeroTargetCallsites++;
133 else if(callees.size() == 1)
134 oneTargetCallsites++;
135 else if(callees.size() == 2)
136 twoTargetCallsites++;
137 else
138 moreThanTwoCallsites++;
139
140 if(ddaPts.count() >= anderPts.count() || ddaPts.empty())
141 continue;
142
143 Set<const FunObjVar*> ander_vfns;
144 Set<const FunObjVar*> dda_vfns;
145 ander->getVFnsFromPts(cbn,anderPts, ander_vfns);
146 pta->getVFnsFromPts(cbn,ddaPts, dda_vfns);
147
148 ++morePreciseCallsites;
149 outs() << "============more precise callsite =================\n";
150 outs() << (nIter->second)->toString() << "\n";
151 outs() << (nIter->second)->getSourceLoc() << "\n";
152 outs() << "\n";
153 outs() << "------ander pts or vtable num---(" << anderPts.count() << ")--\n";
154 outs() << "------DDA vfn num---(" << ander_vfns.size() << ")--\n";
155 //ander->dumpPts(vtptr, anderPts);
156 outs() << "------DDA pts or vtable num---(" << ddaPts.count() << ")--\n";
157 outs() << "------DDA vfn num---(" << dda_vfns.size() << ")--\n";
158 //pta->dumpPts(vtptr, ddaPts);
159 outs() << "-------------------------\n";
160 outs() << "\n";
161 outs() << "=================================================\n";
162 }
163
164 outs() << "=================================================\n";
165 outs() << "Total virtual callsites: " << vtableToCallSiteMap.size() << "\n";
166 outs() << "Total analyzed virtual callsites: " << totalCallsites << "\n";
167 outs() << "Indirect call map size: " << ander->getCallGraph()->getIndCallMap().size() << "\n";
168 outs() << "Precise callsites: " << morePreciseCallsites << "\n";
169 outs() << "Zero target callsites: " << zeroTargetCallsites << "\n";
170 outs() << "One target callsites: " << oneTargetCallsites << "\n";
171 outs() << "Two target callsites: " << twoTargetCallsites << "\n";
172 outs() << "More than two target callsites: " << moreThanTwoCallsites << "\n";
173 outs() << "=================================================\n";
174}
static AndersenWaveDiff * createAndersenWaveDiff(SVFIR *_pag)
Create an singleton instance directly instead of invoking llvm pass manager.
Definition Andersen.h:430
virtual const PointsTo & getPts(NodeID id)
Operation of points-to set.
Definition Andersen.h:242
bool hasIndCSCallees(const CallICFGNode *cs) const
Definition CallGraph.h:335
const FunctionSet & getIndCSCallees(const CallICFGNode *cs) const
Definition CallGraph.h:339
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
Definition CallGraph.h:331
Set< const FunObjVar * > FunctionSet
Definition CallGraph.h:247
void getVFnsFromPts(const CallICFGNode *cs, const PointsTo &target, VFunSet &vfns)
virtual const PointsTo & getPts(NodeID ptr)=0
Get points-to targets of a pointer. It needs to be implemented in child class.
SVFIR * getPAG() const
CallGraph * getCallGraph() const
Return call graph.
bool empty() const
Returns true if set is empty.
Definition PointsTo.cpp:110
u32_t count() const
Returns number of elements.
Definition PointsTo.cpp:123
const std::string getSourceLoc(const Value *val)
Definition LLVMUtil.cpp:454
std::ostream & outs()
Overwrite llvm::outs().
Definition SVFUtil.h:58
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition GeneralType.h:51
unsigned u32_t
Definition GeneralType.h:67

Member Data Documentation

◆ vtableToCallSiteMap

VTablePtrToCallSiteMap SVF::FunptrDDAClient::vtableToCallSiteMap
private

Definition at line 124 of file DDAClient.h.


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