Is there a tool to list global variables used and output by a C function?

女生的网名这么多〃 提交于 2019-12-10 13:22:36

问题


I want to make a list of global variables/macros consumed by a function and output by the function. For example, for:

void myfn(void) {
  out1 = in + 1;
  out2 = 2;
}

..the tool would list the inputs as 'in' and the outputs as 'out1' and 'out2'.

Does anyone know of such a tool?


回答1:


Understand for C/C++ (http://www.scitools.com/products/understand/)




回答2:


Our DMS Software Reengineering Toolkit is a customizable program analysis tool with a production quality C Front End.

It parses C, builds ASTs and symbol tables, provides control and data flow analysis, and constructs global call graphs, and has points-to-analysis. It can be customized to extract this information; in fact, we delivered a custom DMS-based tool to a large vehicle manufacturer to build a tool to extract almost exactly this information.

If you stick to just the symbol table information, you can extract "directly reads or writes" as in your example. If you use the call graph information, you can discover reads or writes to globals caused by calls to other functions. If you use the points-to analysis, you can discover (conservatively) reads or writes to global variables via indirection.




回答3:


You can try also CppDepend,the NDepend like for C\C++




回答4:


Clang at least can do this, but it might not be the easiest way. You will need to interface with the C++ API of it.



来源:https://stackoverflow.com/questions/2335568/is-there-a-tool-to-list-global-variables-used-and-output-by-a-c-function

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