可以clang生成一个Xcode项目的调用图(在Objective-C? [英] Can clang generate a call graph for an Xcode project (in Objective-C?
问题描述
我发现此示例看起来像它输出了我想要的C ++。如何在Xcode项目中为Objective-C代码做?
I found this example that looks like it outputs what I want for C++. How can it be done for the Objective-C code in an Xcode project?
我看到提到的Doxygen能够创建一个调用图,但我找不到一个例子。
I see mentions of Doxygen being able to create a call graph, but I can't find an example.
(我想更好地了解clang,但很难开始...)
(I want to get to know clang better, but it's hard to get started...)
推荐答案
首先,您需要一个兼容的版本 opt
First, you need a compatible version of opt
, since it doesn't come with the LLVM Apple ships. I got mine from macports:
port install llvm-3.0
然后你需要编译你的文件。制定参数有时可能有点痛苦。最简单的方法是让Xcode构建它,然后去日志,剪切和粘贴出巨大的构建线。我以前能够手动攻击这些,但我已经太懒了。
Then you need to compile your file. Working out the parameters can sometimes be a bit of a pain. The easiest way is to let Xcode build it, then go to the logs and cut and paste out the giant build line. I used to be able to hand-hack these, but I've gotten too lazy....
取出最后一个 -o
参数(方便地在编译行的结尾),并替换:
Take out the last -o
parameter (conveniently at the end of the compile line), and substitute:
-S -emit-llvm -o - | opt-mp-3.0 -analyze -dot-callgraph
p>
Then, as in the other example:
$ dot -Tpng -ocallgraph.png callgraph.dot
请记住,有几个函数在ObjC中被称为很多,几乎从不关心。特别是,几乎任何以 objc _
开头的。幸运的是,DOT格式是一个非常简单的文本文件,很容易编写后处理脚本去除你不想要的东西。
Keep in mind that there are a few functions that get called a lot in ObjC that you almost never care about. In particular, almost anything that starts with objc_
. Luckily the DOT format is a very simple text file, and it's pretty easy to write post-processing scripts to strip out what you don't want.
还有一个 -print-callgraph
参数,如果您想要进一步处理,将以略有不同的格式显示此信息。
There's also a -print-callgraph
parameter that will out put this information in a slightly different format if you want to do further processing.
这篇关于可以clang生成一个Xcode项目的调用图(在Objective-C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!