Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I encountered a segmentation fault. #1416

Open
yxscc opened this issue Mar 25, 2024 · 0 comments
Open

I encountered a segmentation fault. #1416

yxscc opened this issue Mar 25, 2024 · 0 comments

Comments

@yxscc
Copy link

yxscc commented Mar 25, 2024

Hello, I encountered a segmentation fault while using SVFG. I implemented a class to manage SVF-related tools, as follows:

// SVFManager.h
#ifndef SVFMANAGER_H
#define SVFMANAGER_H

#include <set>
#include <vector>

#include "SVF-LLVM/LLVMUtil.h"
#include "SVF-LLVM/SVFIRBuilder.h"
#include "WPA/Andersen.h"
#include "MTA/MTA.h"
#include "MemoryModel/PointerAnalysisImpl.h"
#include "SVFIR/SVFValue.h"
#include "CPG/Node.h"
#include "Graphs/SVFG.h"
#include "Graphs/SVFGStat.h"
#include "Graphs/PTACallGraph.h"

namespace SVF
{

class PointerAnalysis;
class AndersenWaveDiff;
class ThreadCallGraph;
class MTAStat;
class TCT;
class MHP;
class LockAnalysis;
class SVFModule;
class SVFG;
class Andersen;
class PTACallGraph;
class ICFG;
class VFG;

class SVFManager{
public:
    SVFModule* svfModule;
    SVFIR* pag;
    PointerAnalysis* pta;
    Andersen* ander;
    MTA* mta;
    SVFG* svfg;
    PTACallGraph* callgraph;
    ICFG* icfg;
    VFG* vfg;


    explicit SVFManager(const std::string& bcFile)
        : svfModule(nullptr), pag(nullptr), pta(nullptr),
          ander(nullptr), mta(new MTA()), svfg(nullptr),
          callgraph(nullptr), icfg(nullptr), vfg(nullptr) {

        std::vector<std::string> moduleNameVec;
        moduleNameVec.push_back(bcFile);
        svfModule = LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec);
        SVFIRBuilder builder(svfModule);
        pag = builder.build();
        ander = AndersenWaveDiff::createAndersenWaveDiff(pag);
        callgraph = ander->getPTACallGraph();
        icfg = pag->getICFG();
        vfg = new VFG(callgraph);
        SVFGBuilder svfBuilder(true);
        svfg = svfBuilder.buildFullSVFG(ander);
        svfg->dump("svfg");
        LLVMModuleSet* moduleSet = LLVMModuleSet::getLLVMModuleSet();
        for (auto it = svfg->begin(); it != svfg->end(); ++it)
        {
          if(svfg == nullptr){
              continue;
          }
          const SVF::SVFGNode* svfNode = it->second;
          if(svfNode == nullptr){
              continue;
          }

          SVFUtil::outs() << "==============\n\t" << svfNode->toString() << "\n==============\n";

          const SVFValue *svfValue = svfNode->getValue();
          if(svfValue == nullptr){
              continue;
          }

          // 获取Value*的名字
          std::string valueName = svfValue->getName();
          // 获取Value*的sourceLoc
          std::string sourceLoc = svfValue->getSourceLoc();
          // 获取llvmValue
          const llvm::Value* llvmValue = moduleSet->getLLVMValue(svfValue);
          SVFUtil::outs() << "Node: " << svfNode->getId() << "\n";
          SVFUtil::outs() << "==============\n\t" << svfNode->toString() << "\n==============\n";
          SVFUtil::outs() << "\t|| SVF-Name:\t" << svfValue->getName() << "\n";
          SVFUtil::outs() << "\t|| LLVM-Name:\t" << llvmValue->getName().data() << "\n";
          SVFUtil::outs() << "\t|| LLVM-Val:\t" << svfValue->toString() << "\n";
          SVFUtil::outs() << "\t|| SVF-Type:\t" << svfValue->getType()->toString() << "\n";
          SVFUtil::outs() << "\t|| Source-Loc:\t" << svfValue->getSourceLoc() << "\n";
          SVFUtil::outs() << "\n";
          // 提取sourceLoc中的ln和cl属性并转换成int
          
      }

    }
    ~SVFManager(){

    };
    
    // 指针别名分析
    //bool alias();

    // 获取SVFValue
    SVFValue* getSVFValue(IdentifierNode* node);

    // 获取SVFG
    SVFG* getSVFG(){
        return svfg;
    }

};

} // End of SVF namespace

#endif // SVFMANAGER_H

In the constructor of SVFManager, I successfully built svfg and was able to iterate through all of its nodes. However, after constructing SVFManager using the method below, obtaining svfg and then accessing its nodes leads to a segmentation fault. In fact, I can avoid this construction method because I can directly construct svfg in the main function and access it successfully. But I am puzzled about why this issue occurs. I apologize for bothering you.

SVFManager* svfManager = new SVFManager(bcFile);
    SVFG* svfg = svfManager->getSVFG();
    for (auto it = svfg->begin(); it != svfg->end(); ++it)
        {
          if(svfg == nullptr){
              continue;
          }
          const SVF::SVFGNode* svfNode = it->second;
          if(svfNode == nullptr){
              continue;
          }

          SVFUtil::outs() << "==============\n\t" << svfNode->toString() << "\n==============\n";

          const SVFValue *svfValue = svfNode->getValue();  ------------>segfault
          if(svfValue == nullptr){
              continue;
          }

          // 获取Value*的名字
          std::string valueName = svfValue->getName();
          // 获取Value*的sourceLoc
          std::string sourceLoc = svfValue->getSourceLoc();
          // 获取llvmValue
          const llvm::Value* llvmValue = moduleSet->getLLVMValue(svfValue);
          SVFUtil::outs() << "Node: " << svfNode->getId() << "\n";
          SVFUtil::outs() << "==============\n\t" << svfNode->toString() << "\n==============\n";
          SVFUtil::outs() << "\t|| SVF-Name:\t" << svfValue->getName() << "\n";
          SVFUtil::outs() << "\t|| LLVM-Name:\t" << llvmValue->getName().data() << "\n";
          SVFUtil::outs() << "\t|| LLVM-Val:\t" << svfValue->toString() << "\n";
          SVFUtil::outs() << "\t|| SVF-Type:\t" << svfValue->getType()->toString() << "\n";
          SVFUtil::outs() << "\t|| Source-Loc:\t" << svfValue->getSourceLoc() << "\n";
          SVFUtil::outs() << "\n";
          // 提取sourceLoc中的ln和cl属性并转换成int
          
      }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant