• 微软原版系统

  • 一键重装系统

  • 纯净系统

  • 在线技术客服

魔法猪系统重装大师 一键在线制作启动 U 盘 PE 系统 用一键重装的魔法拯救失去灵魂的系统
当前位置:首页 > 教程 > 电脑教程

Emacs&cflow生成函数调用树(callgraph)

时间:2015年04月02日 15:40:35    来源:魔法猪系统重装大师官网    人气:15319

介绍了 Emacs 配合 cflow 制作函数的调用树 (call graph)Table of Contents

1、Introduction to cflow

GNU cflow analyzes a collection of C source files and prints a graph, charting control flow within the program.

GNU cflow is able to produce both direct and inverted flowgraphs for C sources. Optionally a cross-reference listing can be generated. Two output formats are implemented: POSIX and GNU (extended).

Input files can optionally be preprocessed before analyzing.

The package also provides Emacs major mode for examining the produced flowcharts in Emacs.

以上内容取自 cflow 的网站: http://www.gnu.org/software/cflow/manual/html_node/Intro.html#Intro。

2、Emacs & cflow

cflow 的代码包中提供了cflow-mode.el, 该文件提供了 emacs 的 cflow-mode, 用于显示 cflow 输出的内容,但该文件中并未提供自动生成指定函数的 call tree 的功能,用起来多少有点不方便。

下面是一个简单的 elisp 函数,通过该函数可以为指定的函数生成调用树。

(defvar cmd nil nil)
(defvar cflow-buf nil nil)
(defvar cflow-buf-name nil nil)

(defun yyc/cflow-function (function-name)
"Get call graph of inputed function. "
;(interactive "sFunction name:\n")
(interactive (list (car (senator-jump-interactive "Function name: "
nil nil nil))))
(setq cmd (format "cflow -b --main=%s %s" function-name buffer-file-name))
(setq cflow-buf-name (format "**cflow-%s:%s**"
(file-name-nondirectory buffer-file-name)
function-name))
(setq cflow-buf (get-buffer-create cflow-buf-name))
(set-buffer cflow-buf)
(setq buffer-read-only nil)
(erase-buffer)
(insert (shell-command-to-string cmd))
(pop-to-buffer cflow-buf)
(goto-char (point-min))
(cflow-mode)
)

函数中使用了 CEDET 提供的 senator-jump-interactive 用于实现函数名的自动补全, 如果你的机器上没有 CEDET, 那么就把 (interactive "sFunction name:\n") 的注释去掉, 而将后面的那句话注释掉即可。
用法很简单,将上面的代码添加到 ~/.emacs 中后,重新载入配置文件,然后打开一个 C 文件, M-x, 输入: yyc/cflow-function , 随后在 Mini-buffer 中输入函数名字, 回车,即可生成一个新的 buffer, 并在其中填写了生成的调用树。

如下图所示:

在调用树中,还可以通过键盘从调用树中跳转到相应的源代码中。

这样, cflow 配置 GNU Global 和 cedet , 代码的阅读和理解效率会大大提高。

Emacs,amp,cflow,生成,函数,调用,树,cal
栏目:电脑教程 阅读:1000 2023/12/27
Win7教程 更多>>
U盘教程 更多>>
Win10教程 更多>>
魔法猪学院 更多>>

Copyright © 2015-2023 魔法猪 魔法猪系统重装大师

本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版软件。

在线客服 查看微信 返回顶部