Use Egypt To Create Call Graphs

Call graphs could give a big picture which makes you better and faster understanding of one project.
Egypt is a simple tool for creating call graphs of C programs. Egypt neither analyzes source code nor lays out graphs. Instead, it leaves the source code analysis to GCC and the graph layout to Graphviz, both of which are better at their respective jobs than egypt itself could ever hope to be. Egypt is simply a very small Perl script that glues these existing tools together.

Install Egypt

The most recent release of egypt is version 1.10, which can be downloaded here. Online documentation is here. You will also need gcc, Perl, and Graphviz.

To install, extract the compressed tar file, cd to the egypt directory, and type

perl Makefile.PL
make
make install

Generate Call Graph

First of all, one project is necessary. you can DOWNLOAD this project or select other one you prefered.
cd to summary-1.0.1, and type

./configure
make CFLAGS=-fdump-rtl-expand

Each .c in project will generate a corresponding .expand. Egypt uses these .expand files to generate the .dot file, and graphviz use .dot file to generate call graph. For example,

./src/person/main.c.144r.expand
./src/person/do.c.144r.expand
./src/lib/lib.c.144r.expand

will be generated in summary project.

Now type

1
egypt ./src/person/main.c.144r.expand ./src/person/do.c.144r.expand ./src/lib/lib.c.144r.expand | dot -Grankdir=LR -Tsvg -o summary.svg

then open summary.svg which is shown below.

Note that, the dash line represents function pointer (C language) calling, the picture makes you better and faster understanding of this project. The main() directly call analyzeperson(), and call do\*() by calling function pointer. The do_*() directly call lib_print().

You will happy to use egypt and graphviz to study a unfamiliar project. Enjoy it!

References