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/