铛libtooling生成的调用图(.dot)没有节点标签

问题描述:

我是clang libtooling的初学者。 我正在尝试使用clang :: CallGraph viewGraph生成我的调用图的.dot文件。 这里是代码:铛libtooling生成的调用图(.dot)没有节点标签

clang::CallGraph mCG; 

for (unsigned i = 0 ; i < DeclsSize ; ++i) { 
    clang::FunctionDecl *FnDecl = (clang::FunctionDecl *) (Decls[i]); 
    mCG.addToCallGraph(FnDecl); 
} 

mCG.viewGraph(); 

有趣的是,生成调用图文件(.DOT)没有节点的标签,但我可以正确打印我的所有节点的名称调用图。

这里是生成的PIC: enter image description here

我很好奇为什么会出现这样的。我的代码中哪部分是错误的?

在此先感谢!

我解决了这个问题,但我不确定它是否是一个正确的方法。 而不是调用函数 - “viewGraph()”,我使用“llvm :: WriteGraph”。

下面是代码:

string outputPath = "./"; 
outputPath.append("CallGraph"); 
outputPath.append(".dot"); 

// Write .dot 
std::error_code EC; 
raw_fd_ostream O(outputPath, EC, sys::fs::F_RW); 

if (EC) { 
    llvm::errs() << "Error: " << EC.message() << "\n"; 
    return; 
} 

llvm::WriteGraph(O, &mCG); 

同时,我改变了LLVM源代码文件 - GraphWriter.h

void writeNode(NodeRef Node) { 

std::string NodeAttributes = DTraits.getNodeAttributes(Node, G); 

O << "\tNode" << static_cast<const void*>(Node) << " [shape=record,"; 
if (!NodeAttributes.empty()) O << NodeAttributes << ","; 
O << "label=\"{"; 

if (!DTraits.renderGraphFromBottomUp()) { 

    // I add here: for show the node's label value (otherwise the label will be empty) 
    std::string nodeLable ; 
    if(Node == G->getRoot()){ 
    nodeLable = "root"; 
    } 
    else{ 
    const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(Node->getDecl()); 
    nodeLable = ND->getNameAsString(); 
    } 

// O << DOT::EscapeString(DTraits.getNodeLabel(Node, G)); 
    O << nodeLable; 
... 

不管怎么说,现在工作为我的代码。不确定是否还有其他好的方法。