从 cscope 数据库生成调用树
我想从 Linux 中的 c 和 c++ 项目的 cscope 数据库生成完整和部分调用树。
该项目相当大,因此使用项目的完整调用树并不容易,因此我想使用类似于 grep 的函数名称过滤器来限制调用树的生成。
我还希望能够从任何点构建“被调用”和“被调用”子树。
因此工具必须是交互式的并且易于修补。
附: 我想使用cscope数据库,因为它已经在项目中使用并且生成速度相当快。我使用vim编辑器并且有X windows系统。
sourceforge 上有 cbrowser 程序,但其调用树(callgraph)功能已损坏。
I want to generate Full and Partially Call Trees from cscope database of c and c++ projects in Linux.
The project is rather large, so it can be not easy to work with the full call tree of project, so I want to limit call tree generation with grep-like filter of function names.
And also I want to be able to build "called by" and "called from" sub-trees from any point.
So tool must be interactive and easy to patch.
PS:
I want use cscope database, because it is already used in project and generating of it is rather fast. I use vim editor and have X windows system.
There is cbrowser program on sourceforge, but its call-tree (callgraph) functionality is broken.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果你想使用 vim 来做到这一点,这里有一种方法:
http://www .vim.org/scripts/script.php?script_id=2368
if you want to do it using vim here is a way:
http://www.vim.org/scripts/script.php?script_id=2368
我尝试“修复”cbrowser 中的调用树问题(请参阅 http://retprogbug.wordpress.com/2010/09/18/an-attempt-to-resuscitate-cbrowser-0-8/)虽然是一个完整的编程菜鸟我不做任何保证。
I've made an attempt to "fix" the call tree problem in cbrowser (see http://retprogbug.wordpress.com/2010/09/18/an-attempt-to-resuscitate-cbrowser-0-8/) though being a complete programming noob I make no guarantees.
kscope
可能是另一种选择。我不确定它是否会执行指定的所有操作,但它对于 GUI 应用程序来说相当通用。建议运行时遇到问题的 Ubuntu 用户遵循这些说明。
kscope
may be another option. I'm not sure if it will do everything specified, but it is fairly versatile for a GUI app.Ubuntu users having trouble getting it running are advised to follow these instructions.
我让这个基于 cscope 的 Bash 脚本可以在 Cygwin & 中工作。 Windows:http://toolchainguru.blogspot.com/2011 /03/c-calltrees-in-bash-revisited.html
请参阅示例调用“graph”(我一直将其称为调用“tree”,哎呀)。 查看 Linux 内核的示例。
它需要 cscope(当然)和 graphviz。它能够制作上游和下游图,以及组合图和组合图。下图(参见示例)。
我没有在这里演示它,但这种方法在大型项目中确实非常有效,因为在多个目录中可能定义相同的函数。只会为相同的函数名称绘制一个节点(因此,即使您的目录结构中定义了多个 main() ,也只有一个“主”节点)——并且您将拥有从这样一个节点发出的多个边,带有文件/行指示器。我发现这方面比 GNU cflow 更有用,GNU cflow 坚持只选择一个目录来查看。(Jason Nyberg Bash 脚本本身并不能很好地处理线程,而 GNU cflow 可以很好地处理线程;需要记住一些事情) .)
I got this cscope-based Bash script to work in Cygwin & Windows: http://toolchainguru.blogspot.com/2011/03/c-calltrees-in-bash-revisited.html
See example call "graph" (I've been calling it a call "tree", whoops). See example from the Linux kernel.
It requires cscope (of course) and graphviz. It is able to do upstream and downstream graphs, as well as combined up & down graphs (see example).
I haven't demonstrated it here but this method works really quite well on large projects where the same function might be defined in multiple directories. There will just be one node drawn for the same function name (so one "main" node even if you have multiple main()'s defined in your directory structure)---and you'll have multiple edges emanating from such a node, with file/line indicators. I found this aspect to be more useful than GNU cflow, which insisted on picking only one directory to look in. (The Jason Nyberg Bash script as is doesn't play well with threading, which GNU cflow handles nicely; something to keep in mind.)
除了 cscope 之外,我不知道有任何程序可以读取 cscope 数据库。即使 vim 的 cstag 功能也只是启动它查询的后台 cscope 进程。
至于调用图生成,如果您不介意走出 cscope,我更喜欢 doxygen 创建的内容。它们可能有点大,但它也从几乎所有点生成图表,并且直接在其中浏览源代码非常容易。
I'm not aware of any programs, other than cscope, that read cscope databases. Even vim's cstag functionality just starts a background cscope process which it queries.
As for call-graph generation, if you don't mind stepping outside cscope, I rather like what doxygen creates. They can be a little big, but it also generates the graph from almost all points, and it's incredibly easy to browse source directly in it.