Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 want to do static analysis.

Thanks!

like image 521
Karl von Moor Avatar asked Jan 08 '10 12:01

Karl von Moor


2 Answers

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);
like image 139
holmes Avatar answered Oct 03 '22 07:10

holmes


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++.

like image 45
Dan Avatar answered Oct 03 '22 07:10

Dan