Simple tool for callgraph in C++
Is there are simple tool, which can be used to determine from where a function is called, which other function the function calls ...?
Edit: I'm using Mac OS X (10.6) and just wan开发者_C百科t to do static analysis.
Thanks!
gtags is a tool you can use for doing tagging, but for call tracing as well.
http://www.gnu.org/software/global/
This supports C, C++, Yacc, Java and PHP4. But it can't handle C++ templates or other complex stuffs properly.
Using this tagging parser, I've made a script to get a call tree from
user's selection through bash completion like the following,
which is displaying a calltree in google profiler code:
% global-calltree -x prof_handler Add Evict ProfileData Stop DisableHandler RAW_CHECK WRITE_TO_STDERR
prof_handler:414 => Add:441 |profiler.cc |instance_.collector_.Add(depth, stack);
Add:241 => Evict:290 |profiledata.cc |Evict(*e);
Evict:61 => ProfileData:75 |profiledata.cc |ProfileData::ProfileData()
ProfileData:124 => Stop:125 |profiledata.cc |Stop();
Stop:261 => DisableHandler:273 |profiler.cc |DisableHandler();
DisableHandler:400 => RAW_CHECK:405 |profiler.cc |RAW_CHECK(sigaction(SIGPROF, &sa, NULL) == 0, "sigaction failed");
RAW_CHECK:83 => WRITE_TO_STDERR:86 |base/logging.h |WRITE_TO_STDERR("Check failed: " #condition ": " message "\n", \
WRITE_TO_STDERR:59 => DECLARE_int32:65 |base/logging.h |DECLARE_int32(verbose);
How about cscope? Check out 3rd & 4th bullet items on the page:
- functions called by a function
- functions calling a function
It's been a while since I used cscope on C++, I seem to remember it being rock-solid on C code, but not as strong with C++.
Don't know about simple tools, but for free, there's codeviz (you can read the raw dumps rather than generate graphs if you prefer that). Caveat: all static analysis tools have some problems with virtual calls, and even worse with templates.
Since you use mac os, clang is a new compiler with static analysis feature.
An example on youtube: Finding bugs with clang
精彩评论