How to Generate a Calling Graph For C++ Code

Tools to get a pictorial function call graph of code

  • Egypt (free software)

  • ncc

  • KcacheGrind (GPL)

  • Graphviz (CPL)

  • CodeViz (GPL)

Static analysis for call-graph generation in C programs

For malloc related bugs, the valgrind tool is very useful (at runtime, when testing).

Your quest cannot be satisfied by purely textual inspection of source code (e.g. because malloc might be called from many inlined functions or macros, and because it even could be #define-d to something else, or called thru function pointers, or in functions from external libraries: even fopen or fprintf may call malloc). Actually it can be proven equivalent to the halting problem.

Also, the call stack is only known at runtime, and it is dynamically changing. It has no sense at compile time. The compiler only organize call frames.

You need a tool which works inside the compiler, on internal representations of the compiler, so you need some more sophisticated static program analyzer, and even that will give you approximate results.

You could use MELT (a plugin and domain specific language to customize the GCC compiler, that I am developing as free software) since it works on GCC internal representations. The example of findgimple mode in the tutorial about using MELT is quite close to your question, but you could customize GCC with your own MELT extension (or ask someone to do that).

PS. valgrind & MELT are mostly available on Linux and POSIX systems. You might try hard to find costly equivalents in the Microsoft ecosystem.

Generating dynamic call graph of c/c++ programs on the run

I've used etrace to trace executions of programs.

Egypt does the same thing, but only has a limited support for C++.

Both requires the program to be instrumented with gcc.

Generating Function Call-Graph Doxygen+Graphviz

By rebooting and removing the DOT_PATH specification, it solved the problem.



Related Topics



Leave a reply



Submit