Small gcc compiler plugin to generate a function callgraph of the compiled source code and works with gcc-8.3 ... gcc-11.1

mooigraph 8d6bb58ba0 doc update 3 lat temu
.gitignore b0f70366b4 Initial commit 3 lat temu
AUTHORS 711d9cd85e initial 3 lat temu
COPYING 711d9cd85e initial 3 lat temu
ChangeLog 711d9cd85e initial 3 lat temu
INSTALL 711d9cd85e initial 3 lat temu
LICENSE b0f70366b4 Initial commit 3 lat temu
Makefile.am 711d9cd85e initial 3 lat temu
NEWS 8eea2dfafe updated output filename 3 lat temu
README 61824f3887 updated readme 3 lat temu
README.md 8d6bb58ba0 doc update 3 lat temu
autogen.sh 711d9cd85e initial 3 lat temu
config.h 711d9cd85e initial 3 lat temu
configure.ac 711d9cd85e initial 3 lat temu
rungcc.sh 7d81d422e6 update 3 lat temu
scallgraph.cpp 7d81d422e6 update 3 lat temu
test.c 711d9cd85e initial 3 lat temu
test.c.scallgraph.gv f4419c3d3e update 3 lat temu

README

# gcc-plugin-scallgraph

Small gcc compiler plugin to generate a function callgraph of the compiled source code and works with gcc-8.3 ... gcc-11.1

This is a very small gcc compiler plugin to generate a function callgraph of the compiled sourcecode.

Because it is so small it should be easy to understand or customize to your own whishes.

To compile this it needs on debian Linux the package gcc-plugin-dev installed for the used gcc version.

To compile:
./autogen.sh
./configure
make

In directectory .libs ahould be a scallgraph_plugin.so.0.0.0 file created

To use this plugin the path to the plugin so file must be specified like this
gcc -c -fplugin=.libs/scallgraph_plugin.so test.c

This generates a scallgraph.gv dot graph file with the callgraph of the routines.

This dot file can be used with gml4gtk graph viewer or dot program.

Other use:
make CFLAGS="-fplugin=.libs/scallgraph_plugin.so"

Or with own customized gcc compiler
./configure CC=$HOME/mygcc/bin/gcc

And indirect function calls are not in the graph

This is tested and works with gcc-8 and gcc-11.1 on debian Linux 2021 see the rungcc.sh script

Also:
make clean
make distclean

This is example graph output in test.c.scallgraph.gv

// function callgraph generated with gcc scallgraph plugin running with gcc version 11.1.0
digraph scallgraph {
"f" -> "h";
"f" -> "g";
"g" -> "h";
"main" -> "f";
}


Now a better callgraph plugin for gcc will follow

Other way to generate callgraph using gcc:
gcc -fcallgraph-info text.c

The generated *.ci file is a vcg graph file usable with gml4gtk graph viewer

Or another way to generate callgraph is using the egypt script and generate gfcc rtl data

The Linux kernel source has maintained gcc plugins in directory linux/scripts/gcc-plugins/