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 години
.gitignore b0f70366b4 Initial commit преди 3 години
AUTHORS 711d9cd85e initial преди 3 години
COPYING 711d9cd85e initial преди 3 години
ChangeLog 711d9cd85e initial преди 3 години
INSTALL 711d9cd85e initial преди 3 години
LICENSE b0f70366b4 Initial commit преди 3 години
Makefile.am 711d9cd85e initial преди 3 години
NEWS 8eea2dfafe updated output filename преди 3 години
README 61824f3887 updated readme преди 3 години
README.md 8d6bb58ba0 doc update преди 3 години
autogen.sh 711d9cd85e initial преди 3 години
config.h 711d9cd85e initial преди 3 години
configure.ac 711d9cd85e initial преди 3 години
rungcc.sh 7d81d422e6 update преди 3 години
scallgraph.cpp 7d81d422e6 update преди 3 години
test.c 711d9cd85e initial преди 3 години
test.c.scallgraph.gv f4419c3d3e update преди 3 години

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/