列出 C 函数调用者的工具?
背景:
在一个特定的项目中,数百个文件中约有数千个函数。这些函数被划分为驻留在两个代码存储器组中——fast_mem 和slow_mem。但现在,由于 fast_mem 区域有限,它的空间不足以容纳任何新的代码更改。
作为代码审查的一部分,发现 fast_mem 中的某些函数没有调用者。但函数列表太大,无法手动一一检查。
问题:
那么问题来了,有没有一个工具可以列出项目中所有函数的调用者呢?有了这个,我可以继续删除 fast_mem 中没有任何调用者的函数。
我使用 cscope 和 ctags 进行代码浏览。但这需要手动输入函数名称。这可以自动化一些如何获取完整列表吗?
我还尝试了 Doxygen 的来电图功能。结果使用起来不太舒服。
Background:
In a particular project there are about couple of thousand functions in more than hundred files. The functions are divided to reside in two banks of code memory - fast_mem and slow_mem. But now, since the fast_mem area is limited, its running out of space to accommodate any new code changes.
As part of code review, its been found that some functions in fast_mem have no callers. But the list of functions is too huge to check them one by one manually.
Question:
So, coming to the question, is there a tool that can list the callers of all the functions in the project? With this, I can go ahead and remove functions in fast_mem that don't have any callers.
I use cscope for code browsing along with ctags. But this requires one to input the function name manually. Can this be automated some how to get the complete list?
I also tried Doxygen with its caller graph feature. The result is not so comfortable to use though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我使用 Scientific Toolworks 了解
I use Scientific Toolworks Understand
如果您的编译器是最新的 GCC(或者如果您可以切换到 GCC 4.6,可能作为交叉编译器),您可能会开发一个 GCC 插件或 MELT 扩展来找出答案。
当然,如果您正在使用函数指针进行技巧(例如函数指针上的不可移植指针算术),则原始问题是无法确定的。
实际上,如果您使用函数指针,通常唯一合理的说法是它们只能访问具有相同签名的函数。
也许该项目足够重要,因此可以自定义编译器以在
fast_mem
和 fast_mem 之间做出更好的(自动或半自动)权衡。slow_mem
是值得的。对于 GCC 插件或 MELT 扩展来说,这通常是一个很好的案例(但这需要一些工作时间——几天或几周,而不是几个小时——因为您需要了解内部 GCC 表示来自定义 GCC),并且您可能是唯一一个可以做到这一点的人。这样做(因为你的问题对于某些奇怪的系统来说非常特殊)。If your compiler is a recent GCC (or if you can switch to GCC 4.6, possibly as a cross-compiler) you might develop a GCC plugin or a MELT extension to find out.
Of course, if you are e.g. doing tricks with function pointers (e.g. unportable pointer arithmetic on function pointers) the original question is undecidable.
Actually, if you are using function pointers, often the only reasonable thing to say is that they can reach only functions of the same signature.
And perhaps the project is important enough so that customizing the compiler to make a better (automatic or semi-automatic) trade-off between
fast_mem
&slow_mem
is worthwhile. This is typically an excellent case for GCC plugins or MELT extensions (but that take some work -days or weeks, not hours-, because you need to understand the internal GCC representations to customize GCC), and you are probably the only one who could do it (because your question is very peculiar to some strange systems).我们假设没有发生任何奇怪的函数指针游戏。然后你可以打破未充分使用的cflow:
http://www.gnu.org/software/cflow /
使用 -r 标志生成“反向索引”。您将获得每个函数的列表,后面是调用它的位置。您可以为其提供多个文件。
Let's assume there aren't any odd function pointer games going on. Then you can break out the under-used cflow:
http://www.gnu.org/software/cflow/
Generate a "reverse index" with the -r flag. you'll get a list of every function, followed by where it's called. You can feed it multiple files.
您可以使用静态代码分析工具,例如 cppcheck。
如果您使用
--enable=unusedFunction
参数调用它,它将警告未使用的函数。You can use static code analysis tool like cppcheck.
If you call it with
--enable=unusedFunction
parameter it will warn about unused function.