Identifying Unused Functions in C/C++ [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-06 05:20:22
Brady

You can use CCCC (free, open source) which gives you lots of metrics about your program. Another option would be Coverity (not free).

This question may be a duplicate of this one: Dead code detection in legacy C/C++ project

I don't think that the map file will be of any use. If it's like other map files I've seen, it won't indicate where (if anywhere) a symbol is used—only where it is defined. What you can do is run dumpbin over your object files: dumpbin /relocations, for example, will in fact display every use of a symbol with an address which may need relocation (practically speaking, functions and variables with static lifetime). You then use your usual tools on the output to determine whether the function you are interested in is there or not. (As someone who has worked mostly on Unix, I've installed CygWin and would use grep. I'm not familiar with the native equivalents to the different Unix tools under Windows.)

It would be fairly simple (using Python, or some similar scripting language) to write a small script which would parse the output of dumpbin /symbols for each of your object files, to get the names of all of the functions you've defined, then parses the output of dumpbin /relocations to give you a list of the functions you use, and finally does the diff of the two. (Microsoft seems to have gone out of their way to make the output of dumpbin difficult to use, but it's still not that difficult; you just have to know which lines to ignore.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!