Tuesday, March 14, 2006
Static analysis of K&R C code
I've got a body of C code (mostly K&R) that I'd like to quickly dip into. It would be great if there was a tool that could visualise the (Static) call relationships between functions - I don't expect the tool to be able to meaningfully interpret function pointers, so it would not have to do anything smart with the following code:
int foo( int x ) { return x + 1; } int bar( int x ) { return x + x; } int baz( int (*qux)(int), int x ) { return qux( x ); } int main( int argc, char ** argv ) { return baz( 1 == argc ? foo : bar ); }But the tool should be able to identify that main() calls baz(), and that baz() invokes a function pointer. It would be absolutely fantastic if it identified that baz() calls either foo() or bar(), but I won't hold my breath waiting for this functionality. Do you know of any tools like this? A quick search on google did not find any tools like this. I did find:
- Call Graph Drawing Interface This looks like a great tool for analysing dynamic call graphs collected by a profiling tool. The code I have is incomplete and will not compile on a modern platform, so unfortunately this tool cannot be used.
- NCC From the homepage: ncc is a compiler that produces program analysis information. ncc is a decent replacement of cflow and cscope able to analyse any program using the gcc compiler. The program also incliudes a graphical call-graph navigator and source browser which is extremely practical for hacking and comprehending large projects. Wow! It sounds like what I need - unfortunately it is very Unixy, and I'd like to analyse the code on Windows. As a last resort I'll try and port it...
- CodeViz This looks like another great tool - and it provided the link to ncc (above). Uses graphviz (== good). Maybe codeviz will need porting to Windows, but that is moot point until ncc is working... this project seems to be getting larger all the time.
- cKit Hmmm... I like excuses to learn new languages. Never played with Standard ML - maybe this is my chance!
- The ASTRÉE Static Analyzer This is a heavyweight tool - more than I need - but unfortunately it doesn't do what I need!