【发布时间】:2017-07-13 07:02:01
【问题描述】:
我正在尝试遍历 llvm 中的调用图。在调用图中获得节点后,我会尝试打印与该调用图节点对应的函数名称以及引用数。
结果: 1)函数名始终为空字符串。 2)引用的数量总是一个随机数。 3)同样被调用的函数名也是一个空字符串。
代码: bool 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";
}
}
}
}
}
}
【问题讨论】:
标签: llvm llvm-ir call-graph