一.安裝egypt
1.下載egypt
http://www.gson.org/egypt/download/egypt-1.10.tar.gz
2.解壓
tar -zvxf egypt-1.10.tar.gz
3.編譯安裝
cd egypt-1.10
perl Makefile.PL
make
make install
二.使用
1.編寫test.c
test.c文件如下
#include <stdio.h>
void test1();
void test2();
void test3();
void test4();
int main()
{
test1();
test4();
for (int i = 0; i < 10; i++)
{
test2();
printf("main\n");
}
return 0;
}
void test1()
{
printf("1\n");
}
void test2()
{
printf("2\n");
}
void test3()
{
printf("3\n");
}
void test4()
{
printf("4\n");
test3();
}
2.編譯
gcc -fdump-rtl-expand test.c -o test
會生成相應的文件,我測試時生產如下文件
test.c.229r.expand
3.生成dot文件
使用egypt就可以生產dot文件,命令如下
egypt test.c.229r.expand > test.dot
4.生成調用圖
需要先安裝graphviz,命令如下
apt install graphviz
運行下面的命令生成調用圖
dot test.dot -Tpng -o test.png
5.效果