我试图遍历llvm中的调用图。一旦我在调用图中得到一个节点,我就会尝试打印对应于该调用图节点的函数名以及引用数。
1) 函数名始终为空字符串。
2) 引用的数量始终是一个随机数。
3) 此外,被调用的函数名也是一个空字符串。
代码:
布尔runOnModule(llvm::Module&M)覆盖
CallGraph cg = CallGraph(M);
cg.dump();// this is correct. It is printing the expected the call graph
for ( CallGraph::const_iterator itr = cg.begin(), ie = cg.end() ; itr != ie; itr++)
{
if (itr->second != nullptr)
{
itr->second->dump();
errs()<<"-----------CGN---------\n";
CallGraphNode *cgn = itr->second.get();
if(const Function* fptr = cgn->getFunction())
{
errs()<<"Number of references are"<<cgn->getNumReferences()<<"\n";
errs()<<fptr->getName()<<"\n";
if(cgn->operator[](0) != nullptr)
{
if(cgn->operator[](0)->getFunction() != nullptr)
{
errs()<<cgn->operator[](0)->getFunction()->getName()<<"\n";
}
}
}
}
}