Skip to content

SVF CPP API

Yulei Sui edited this page Mar 22, 2021 · 37 revisions
Members Meanings
SVF::SVFUtil::outs output stream similar to std::outs
SVF::SVFUtil::isa instance of a class
SVF::SVFUtil::cast casting from a parent class to a child class
SVF::SVFUtil::dyn_cast dynamic casting from a parent class to a child class, return null if not successful
SVF::SVFUtil::getSourceLoc give an LLVM value and return the source code line number & file name of a C/CPP file
SVF::SVFUtil::isCallSite return true if an LLVM instruction is a call instruction
SVF::SVFUtil::isIRFile return true if the file is a LLVM IR file
Members Meanings
ICFGNode::toString return the content of this ICFGNode in the form of a string consisting of the nodeID, llvm instructions ...
SVF::ICFGNode::getPAGEdges return the PAGEdges residing in this ICFGNode
SVF::CallBlockNode::getCallSite return the LLVM callsite
SVF::RetBlockNode::getCallSite return the LLVM callsite
Members Meanings
SVF::ICFGEdge::isIntraCFGEdge return true if it is an intra-procedural edge
SVF::ICFGEdge::isCallCFGEdge return true if it is a call edge
SVF::ICFGEdge::isRetCFGEdge return true if it is a return edge
SVF::CallCFGEdge::getCallSite return its corresponding llvm call instruction
SVF::RetCFGEdge::getCallSite return its corresponding llvm call instruction

SVF::SVFUtil::outs()

  • Output the content of a node on ICFG

    For example,

     ICFGNode *inode = ...;  // subclass object CallBlockNode : %call = call i32 (...) @source(),
     SVFUtil::outs() << *inode << "\n"
     SVFUtil::outs() << inode->toString() << "\n"
    

    The output is IntraBlockNode 21 : %call = call i32 (...) @source() using one of the following two:


SVF::SVFUtil::isa<>()

  • The isa<> operator works similar to Java's “instanceof” operator. It returns true or false depending on whether a reference or pointer points to an instance of the specified class.

    For example,

    ICFGNode* inode subclass object is CallBlockNode so that we can use the following to check whether inode is of typeCallBlockNode:

    if (SVFUtil::isa<CallBlockNode>(inode)) { ... }
    

SVFUtil::cast<>()

  • Casting a pointer or reference to an instance of a specified class. This casting fails and abort the program if the object or reference is not the specified class at runtime.

    For example,

    cast<CallBlockNode>(inode)->getParent()
    

SVFUtil::dyn_cast<>()

  • The dyn_cast<> operator is a "checking cast" operation. It checks to see if the operand is of the specified type, and if so, returns a pointer to it (this operator does not work with references). If the operand is not of the correct type, a null pointer is returned. Thus, this works very much like the dynamic_cast<> operator in C++, and should be used in the same circumstances.

    For example,

    if (RetCFGEdge* retEdge = SVFUtil::dyn_cast<RetCFGEdge>(edge)) {
    // ...
    }
    

    This form of the if statement effectively combines isa<> and cast<>, which is more compact.


std::string SVFUtil::getSourceLoc(const Value* val)

  • return line number & file name of the original C/CPP source code

    For example,

    Assuming an Instruction val is %call = call i32 (...) @sink() in line 6, and you can use SVFUtil::getSourceLoc(val) to navigate the instruction v's location in the source code


bool SVF::SVFUtil::isIRFile(const std::string &filename)

  • return true if a file is a LLVM IR file

inline const PAGEdgeList& getPAGEdges() const

  • return this ICFGNode corresponding PAGEdgeList,

    typedef std::list<const PAGEdge*> PAGEdgeList;

    For example,

    ICFGNode v %0 = load i32, i32* %a, align 4 for collecting all it PAGEdges, PAGEdgeList paglist = v.getPAGEdges()


ICFGNode::toString()

  • return the content of this ICFGNode in the form of a string consisting of the nodeID, llvm instructions and its containing function

    Output Sample: NodeID: 15\nIntraBlockNode ID: 15 store i32 1, i32* %a, align 4 \{fun: main\}}


inline const Instruction* CallBlockNode::getCallSite() const

  • return the LLVM call instruction

    For example,

    Assuming that CallBlockNode* v is %call = call i32 (...) @sink(), you can use v->getCallSite() to fetch its LLVM call instruction.

inline const Instruction* RetBlockNode::getCallSite() const

  • return the LLVM call instruction, similar as that of CallBlockNode.

inline const Instruction* RetCFGEdge::getCallSite

  • return its corresponding llvm call instruction

Clone this wiki locally