I want to make a list of global va开发者_JAVA技巧riables/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?
Understand for C/C++ (http://www.scitools.com/products/understand/)
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.
You can try also CppDepend,the NDepend like for C\C++
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.
精彩评论