1. cview
https://gitee.com/wuu1010/cview
1.1. 介绍
Python3.x + Graphviz自动化绘制C语言 函数调用关系图、结构体关系图
已使用Cython将Python代码转化为c,可以自行编译安装
1.2. 软件架构
软件架构说明
1.3. 安装教程
- sudo -H pip3 install filetype pygraphviz
- sudo -H pip3 install Cython setuptools
- sudo apt install graphviz
- cd cview
- make all
- sudo -H make install
1.4. 使用说明
- 生成源文件
- 函数调用关系图
只支持ARM
对编译生成的文件进行反汇编
aarch64-linux-gnu-objdump -d vmlinux > vmlinux.dis
- 结构体关系图
在编译Makefile中,CFLAGS选项中添加-save-temps=obj,再进行编译
KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
-fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
-Werror=implicit-function-declaration -Werror=implicit-int \
-Wno-format-security \
-std=gnu89 -save-temps=obj
- 解析文件
解析文件实例
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import os
import sys
import cview
import time
def main(argv):
db_path = '../../test.db'
t_start = time.time()
# step1: init
test = cview.CView()
os.remove(db_path)
test.load_db(db_path)
# step2: parser file
test.parse_file('Func', 'function', '../../vmlinux.dis')
test.parse_file('Data', 'struct', '../../exit.i')
test.db.table_info()
t_end = time.time()
print('use {t_use:.2f}s'.format(t_use=(t_end - t_start)))
if __name__ == '__main__':
main(sys.argv[0:])
- 生成关系图
关系图实例
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import os
import sys
import cview
import time
def main(argv):
db_path = '../../test.db'
t_start = time.time()
# step1: init and load database
test = cview.CView()
test.load_db(db_path)
test.db.table_info()
# step2: the first table
test.db.set_table('function')
node_list = {
'start_kernel',
'kernel_init',
}
test.add_nodes_from(node_list)
test.tree('kernel_init', 1, 2)
test.build(random=False)
# step3: the second table
test.db.set_table('struct')
node_list = {
'struct zone',
}
test.add_nodes_from(node_list)
test.tree('struct page', 1, 3)
test.build(random=False)
# step4: the end
test.write('./test.gv')
t_end = time.time()
print('use {t_use:.2f}s'.format(t_use=(t_end - t_start)))
if __name__ == '__main__':
main(sys.argv[0:])
1.5. pygraphviz文档
http://pygraphviz.github.io/documentation/pygraphviz-1.5/
转载:https://blog.csdn.net/wuu1010/article/details/102489078
查看评论