egypt + graphviz生成C/C++源代码调用图(一)

一.安装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.效果

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章