http://code.google.com/p/gcc-vcg-plugin/
简介
GCC VCG Plugin是一个GCC插件,可以将GCC在编译程序的过程中,产生的内部
数据结构图形化;从而,方便分析应用程序和GCC本身。目前,可以初步图形化
➔ 控制流图
➔ 函数调用图
➔ 支配图
➔ Tree结构相关
➔ Gimple结构相关
➔ RTX结构相关
➔ Pass列表
参考链接
➔ http://gcc.gnu.org/wiki/plugins
➔ http://code.google.com/p/vcgviewer
➔ http://code.google.com/p/gcc-vcg-plugin
源码结构
gcc-vcg-plugin/
|-------- example(例子:文件,图片)
|-------- libgdl(GDL库,对VCG的基本支持)
|-------- vcg-plugin(插件,将GCC数据结构图形化)
$ ls libgdl/
gdl-attr.c gdl.c gdl.h Makefile.am Makefile.in
$ ls vcg-plugin/
gcc-bb.c gcc-passes.c Makefile.am
gcc-cfg.c gcc-plugin-api.c Makefile.in
gcc-cgraph.c gcc-rtx.c vcg-plugin.c
gcc-dominance.c gcc-tree-4.6.c vcg_plugin.gdbinit
gcc-gimple-hierarchy.c gcc-tree-4.7.c vcg-plugin.h
gcc-loop.c gcc-tree-hierarchy.c
使用方法
➔ 通过gcc命令行使用(-fplugin-arg-vcg_plugin-option)
➔ cgraph ---- dump the call graph before IPA passes.
➔ cgraph-callee ---- dump the callee graph for each function.
➔ cgraph-caller ---- dump the caller graph for each function.
➔ gimple-hierarchy ---- dump the gimple hierarchy graph.
➔ help ---- show this help.
➔ passes ---- dump the passes graph.
➔ pass-lists ---- dump the pass lists graph.
➔ tree-hierarchy ---- dump the tree hierarchy graph.
➔ tree-hierarchy-4-6 ---- dump the tree hierarchy graph for gcc 4.6.
➔ tree-hierarchy-4-7 ---- dump the tree hierarchy graph for gcc 4.7.
➔ viewer=name ---- set the vcg viewer, default is vcgview.
使用方法
➔ 通过gdb自定义命令使用(view-option或者dump-option)
➔ view-bb ---- show the basic block
➔ view-bbs ---- show the basic blocks
● view-cfg ---- show the current control flow graph in tree-level
➔ view-cgraph ---- show the current call graph
➔ view-dominance ---- show the current dominance graph
➔ view-gimple-hierarchy ---- show gimple statement structure hierarchy
➔ view-loop ---- show the loop
➔ view-pass-lists ---- show pass lists
➔ view-rtx ---- show a specified rtx
➔ view-tree ---- show a specified tree
➔ view-tree-hierarchy ---- show tree structure hierarchy
➔ view-tree-hierarchy-4-6 ---- show tree structure hierarchy for gcc 4.6
➔ view-tree-hierarchy-4-7 ---- show tree structure hierarchy for gcc 4.7
例子
➔ 控制流图、支配图
$ gdb -q -args /path/to/cc1 -O3 -fplugin=/path/to/vcg-plugin.so foo.c
(gdb) so /path/to/vcg-plugin.gdbinit
(gdb) b execute_build_cfg
(gdb) r
(gdb) finish
(gdb) view-cfg
(gdb) view-dominance
(gdb) view-bb 5
(gdb) view-bbs “3:8”
(gdb) view-loop 1
控制流图 支配图
例子
➔ 函数调用图
(gdb) view-cgraph
(gdb) view-cgraph-callee
(gdb) view-cgraph-caller
或者
$ export VCGPLUGIN=/path/to/vcg-plugin.so
$ gcc -fplugin=$VCGPLUGIN -fplugin-arg-vcg_plugin-cgraph -c foo.c
$ gcc -fplugin=$VCGPLUGIN -fplugin-arg-vcg_plugin-cgraph-callee -c foo.c
$ gcc -fplugin=$VCGPLUGIN -fplugin-arg-vcg_plugin-cgraph-caller -c foo.c
$ make CFLAGS="-O0 -fplugin=$VCGPLUGIN -fplugin-arg-vcg_plugin-cgraph -fplugin-arg-
vcg_plugin-cgraph-callee -fplugin-arg-vcg_plugin-cgraph-caller"
$ for i in `ls *.vcg`; do vcgview $i ${i%vcg}png; done
函数调用图
callee调用图
caller调用图
例子
➔ Tree、Gimple的层次结构
(gdb) dump-gimple-hierarchy
(gdb) dump-tree-hierarchy
(gdb) dump-tree-hierarchy-4-6
(gdb) dump-tree-hierarchy-4-7
或者
$ gcc -fplugin=$VCGPLUGIN -fplugin-arg-vcg_plugin-gimple-hierarchy -c foo.c
$ gcc -fplugin=$VCGPLUGIN -fplugin-arg-vcg_plugin-tree-hierarchy -c foo.c
$ gcc -fplugin=$VCGPLUGIN -fplugin-arg-vcg_plugin-tree-hierarchy-4-6 -c foo.c
$ gcc -fplugin=$VCGPLUGIN -fplugin-arg-vcg_plugin-tree-hierarchy-4-7 -c foo.c Gimple层次结构
gcc 4.6 tree 层次结构
gcc 4.7 tree 层次结构
例子
➔ Tree结构
(gdb) view-tree current_function_decl
(gdb) view-tree-node current_function_decl
(gdb) view-tree 0xb7da2980
tree结构
例子
➔ RTX结构
(gdb) view-rtx get_insns ()
RTX
例子
➔ Pass列表
(gdb) view-pass-lists
或者
$ gcc -fplugin=$VCGPLUGIN -fplugin-arg-vcg_plugin-passes -c foo.c
$ gcc -fplugin=$VCGPLUGIN -fplugin-arg-vcg_plugin-pass-lists -c foo.c
pass列表
passes列表
下一步工作
➔ 完善现有的功能实现
➔ tree
➔ rtx
➔ loop
➔ 支持更多的图形化功能
➔ 数据流图?
➔ 自动机?
➔ ...