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

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/