如何过滤掉 C++ 中未触及的代码
为了剖析/理解庞大的模板密集型代码库,有一个工具可以告诉我哪些类/代码已成为最终的二进制文件,这将非常有用。
例如,如果代码中有两个类 A 和 B,但我最终只实例化 A,那么我想知道过滤掉 B。是否有任何工具可以使用基于模板的代码实现相同的目的。
For dissecting/understanding huge template-heavy code base it would really useful to have a tool that tells me what class/code have made it to the final binary.
For example if there are two class A and B in the code but I only end up instantiating only A then I would somehow like to know filter out B. Are there any tools to achieve the same with template-based code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用一些分析器/代码覆盖率工具。 MS Visual Studio 的某些版本附带了探查器。还有一些商业分析器/覆盖工具,例如 Intel VTune。在带有 GCC 的 *nix 上有 gcov。
Use some profiler/code coverage tools. Some versions of MS Visual Studio ship with profiler. Then there are several commercial profilers/coverage tools like Intel VTune. On *nix with GCC there is the gcov.
运行 doxygen 生成引用图并查看哪些类没有被引用
run doxygen to generate referral graph and see what class is not been referred
您可以尝试使用 nm:
尽管使用它并浏览其输出并不是很有趣。
作为一种不同的方法,是否不可能首先开始浏览/阅读/理解调用者代码以记下使用/包含的类?
You can try using nm:
although using it and wading through its output is not very fun.
As a different approach, is it not possible to start browse/read/understand the caller code first to note down the classes that are used/included?
请参阅我的回答 回答我最近在 SO 上提出的问题。
这个想法是在启用“showInincludes”编译器选项后编译代码,然后处理输出以提取所需的信息(例如,手动或自动,使用 python 脚本)。
通过这样做,我已经能够提取用于构建我们的软件的确切代码文件。
See my answer to the question i asked recently on SO.
The idea is to compile your code after having enabled the "showIncludes" compiler option, then deal with output to extract the information you need (either manually or automatically, using a python script, for example).
Doing this, i have been able to extract the exact code files that are used to build our software.