静态分析C语言生成函数调用关系的利器——cflow
除了《静态分析C语言生成函数调用关系的利器——calltree》一文中介绍的calltree,我们还可以借助cflow辅助我们阅读理解代码。(转载请指明出于breaksoftware的csdn博客)
cflow的说明和安装
cflow是一款静态分析C语言代码的工具,通过它可以生成函数的调用关系。和calltree不一样,cflow有独立的网页介绍它(https://www.gnu.org/software/cflow/#TOCdocumentation)。而且在Ubuntu系统上,我们可以不用去编译cflow的源码,而直接使用下面命令获取
apt-get install cflow
cflow的使用
安装完毕,我们可以使用下面指令看到cflow的参数说明
cflow --help
我们可以得到如下提示
Usage: cflow [OPTION...] [FILE]...
generate a program flowgraphGeneral options:-d, --depth=NUMBER Set the depth at which the flowgraph is cut off-f, --format=NAME Use given output format NAME. Valid names are`gnu' (default) and `posix'-i, --include=CLASSES Include specified classes of symbols (see below).Prepend CLASSES with ^ or - to exclude them fromthe output-o, --output=FILE Set output file name (default -, meaning stdout)-r, --reverse * Print reverse call tree-x, --xref Produce cross-reference listing onlySymbols classes for --include argument_ symbols whose names begin with an underscores static symbolst typedefs (for cross-references only)x all data symbols, both external and staticParser control:-a, --ansi * Accept only sources in ANSI C-D, --define=NAME[=DEFN] Predefine NAME as a macro-I, --include-dir=DIR Add the directory DIR to the list of directoriesto be searched for header files.-m, --main=NAME Assume main function to be called NAME-p, --pushdown=NUMBER Set initial token stack size to NUMBER--preprocess[=COMMAND], --cpp[=COMMAND]* Run the specified preprocessor command-s, --symbol=SYMBOL:[=]TYPE Register SYMBOL with given TYPE, or define analias (if := is used). Valid types are: keyword(or kw), modifier, qualifier, identifier, type,wrapper. Any unambiguous abbreviation of the aboveis also accepted-S, --use-indentation * Rely on indentation-U, --undefine=NAME Cancel any previous definition of NAMEOutput control:-b, --brief * Brief output--emacs * Additionally format output for use with GNUEmacs-l, --print-level * Print nesting level along with the call tree--level-indent=ELEMENT Control graph appearance-n, --number * Print line numbers--omit-arguments * Do not print argument lists in functiondeclarations--omit-symbol-names * Do not print symbol names in declaration strings-T, --tree * Draw ASCII art treeInformational options:--debug[=NUMBER] Set debugging level-v, --verbose * Verbose error diagnostics-?, --help give this help list--usage give a short usage message-V, --version print program versionMandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.* The effect of each option marked with an asterisk is reversed if the option's
long name is prefixed with `no-'. For example, --no-cpp cancels --cpp.Report bugs to <bug-cflow@gnu.org>.
我只列出我觉得有意思的几个参数:
-T输出函数调用树状图
-m指定需要分析的函数名
-n输出函数所在行号
-r输出调用的反向关系图
--cpp预处理,这个还是很重要的
文本输出
最简单的使用方法是以ASCII文本的方式输出结果,比如
cflow -T -m main -n timer.c
其结果是一个包含文件名和函数所在代码行号的调用关系图
+-main() <int main (void) at timer.c:13>+-ev_timer_init()+-timeout_cb() <void timeout_cb (EV_P_ ev_timer *w, int revents) at timer.c:7>| +-puts()| \-ev_break()+-ev_timer_start()\-ev_run()
然而,对于有一定代码量的项目,我们不会使用ASCII文本的方式去查看函数调用关系,因为调用是相当复杂的,而文本图并不适合人去理解。于是我们希望能cflow能产出一个可供其他软件转换成图片的格式的文件。可惜cflow并不支持,好在网上有开发者做了一个工具,可将其结果转换成dot格式。
转成dot文件
wget -c https://github.com/tinyclub/linux-0.11-lab/raw/master/tools/tree2dotx
下载完tree2dotx后,可对其做个软链便于使用
cd /usr/bin
ln -s 【Your Path】/tree2dotx tree2dotx
具体的转换方法是
cflow -T -m main -n timer.c > main.txt
cat main.txt | tree2dotx > main.dot
dot文件生成图片
我们需要借助graphviz(没有安装的可以使用apt-get install graphviz先安装)生成图片,指令是
dot -Tgif main.dot -o main.gif
静态分析C语言生成函数调用关系的利器——cflow相关推荐
- [授权发表]源码分析:静态分析 C 程序函数调用关系
故事缘由 工欲善其事,必先利其器.今天我们来玩转一个小工具,叫 Callgraph,它可以把 C 语言的函数调用树(或者说流程图)画出来. 传统的命令行工具 Cscope,Ctags 可以结合vim ...
- c语言调用graphviz_c语言分析函数调用关系图(call graph)的几种方法
一.基于 Doxygen或 lxr 的API形式的文档系统. 二.基于CodeViz, CodeViz是<Understanding The Linux Virtual Memory Manag ...
- 函数调用关系/结构图Callgraph
文章目录 代码结构图 Callgraph安装 使用方法简介 运行结果 代码结构图 源码分析是程序员离不开的话题,无论是研究开源项目,还是平时做各类移植.开发,都避免不了对源码的深入解读.对于一个功 ...
- insight切换窗口 source_Source Insight函数调用关系显示设置
当我们需要设置source Insight的项目代码中函数调用关系时,可通过如下的设置来实现: 1.显示函数调用关系窗口 Source Insight工具栏中"View"-> ...
- 输出nginx执行过程中函数调用关系
添加源文件 首先在src/core/目录下添加两个文件,分别是my_debug.h和my_debug.c. #ifndef MY_DEBUG_LENKY_H #define MY_DEBUG_LENK ...
- insight切换窗口 source_Source Insight函数调用关系显示设置(示例代码)
当我们需要设置source Insight的项目代码中函数调用关系时,可通过如下的设置来实现: 1.显示函数调用关系窗口 Source Insight工具栏中"View"-> ...
- source insight怎么生成函数调用关系图?
点击relation window 参考文章:Source Insight怎么生成函数调用关系图?
- Apache Spark源码走读之3 -- Task运行期之函数调用关系分析
概要 本篇主要阐述在TaskRunner中执行的task其业务逻辑是如何被调用到的,另外试图讲清楚运行着的task其输入的数据从哪获取,处理的结果返回到哪里,如何返回. 准备 spark已经安装完毕 ...
- x264函数调用关系图
1 encoder 2 slice write 3 analyse FFMPEG中MPEG-2编解码函数调用关系图 1 Encoder (函数调用从左到右,下同:图片显示不全时,请下载显示) 2 P帧 ...
最新文章
- HAproxy七层负载均衡——环境搭建及实现过程详解
- 详解wait和waitpid函数
- [转载]dynamic的小坑--RuntimeBinderException:“object”未包含“xxx”的定义
- python为什么closed_为什么Python无法解析此JSON数据? [关闭] - Why can't Python parse this JSON data? [closed]...
- 最大流问题 Edmonds-Karp算法
- php在页面中实现累加,小白问个php累加问题
- 数据结构 (二) ----- 单向链表双向链表
- 理想的低通滤波器、巴特沃斯滤波器、高斯滤波器
- MapReduce实现kmeans算法
- android长截图工具下载,手机长截图怎么截?超方便的长截图App
- excel 某个单元格不是等于空值_EXCEL中IF函数中怎么表达某一个单元格不等于空白则返回值1.4...
- 支持APP的打印服务器,TP-LINK双频无线路由器打印服务器客户端软件
- 微信小程序-灰度发布
- OGG12.1(LINUX) for 11G R2 RAC classical install 经典抽取模式单项同步配置OGG12.1
- 【Java八股文之进阶篇(三)】多线程编程核心之锁框架(一)
- MicrosoftExcel函数
- 中英文论文写作指导第二部分(前言)
- centos7上安装kerberos附java使用kerberos案例
- extjs6 异步树
- 为什么光域服务器维护中,网络服务器系统和新型光突发交换网络解决方案
热门文章
- symfony 2 app.php,php / symfony2从URL隐藏app.php
- 深蓝学院的三维点云课程:第一章
- 【机器学习入门】(8) 线性回归算法:正则化、岭回归、实例应用(房价预测)附python完整代码和数据集
- OpenCV中minAreaRect()最小外接矩形 cvBoxPoints()计算矩形顶点 RotatedRect和CvBox2D详解
- des vue 双倍长 解密_3DES双倍长加密 - osc_ojx9hm4t的个人空间 - OSCHINA - 中文开源技术交流社区...
- hp惠普笔记本电脑黑屏大小写锁定键闪烁报错无法开机怎么办?
- js 与或运算符 || 妙用
- Melkman's Algorithm
- await使用中的阻塞和并发(一)
- 安装需要的第三方库时,命令行输入pip提示不是内部或外部命令