views:

117

answers:

3

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  A: 

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.

Tronic
+1  A: 

The 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.

Ira Baxter
The second link is incorrect.
Patrick
Second link fixed. Thanks.
Ira Baxter
+1  A: 

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

Patrick