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?
I see mentions of Doxygen being able to create a call graph, but I can't find an example.
(I want to get to know clang better, but it's hard to get started...)
Absolutely. There are a couple of tricks that you need to understand, but it's not too bad.
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
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....
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
Then, as in the other example:
$ dot -Tpng -ocallgraph.png callgraph.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.
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.
来源:https://stackoverflow.com/questions/9082687/can-clang-generate-a-call-graph-for-an-xcode-project-in-objective-c