views:

230

answers:

6

Source code analysis and exploration tools for C and C++ seem to be sorely lacking.

Are there any tools which I can use to gather information about C and/or C++ source files? cscope does part of what I would need, Doxygen looks closer.

At a minimum list of all function, callers, callees, variable references etc. Perhaps Doxygen's xml output would work.

Ideally gcc or llvm could be hooked for this purpose but I have yet to find a convenient way to do so.

Any suggestions?

A: 

Sonar is a really good Java projects analyzer. It now supports some other languages, including .Net. At the end of this blog post, you can see that a C plugin will be released soon...

romaintaz
There are some really nice tools for java... unfortunately that doesn't help me much. Being able to walk the bytecode is quite useful for introspection.
Brian Makin
+1  A: 

You might find SourceMonitor helpful for more statistical analysis for code, plus its free :)

Necrolis
+2  A: 

There is the clang static analyzer which is part of the clang front end for llvm, but I don't know how well it works for C/C++. It seems most of their effort is going towards Objective-C.

http://clang-analyzer.llvm.org/

Doxygen is good for call graphs, you'll want to have GraphViz installed and use doxywizard to select the Call graphs and Called by graphs tick boxes in the Diagrams section (CALL_GRAPH and CALLER_GRAPH in the expert mode Dot section.)

Neth
+1  A: 

Our DMS Software Reengineering Toolkit with its C front end and C++ Front End can provide a lot of information about C and C++ programs.

DMS with the C front end can parse large sets of C source files, build complete ASTs (even capturing comments) and symbol tables, and provide control and data flow analysis, with points-to analysis and call graphs. The C++ front end builds ASTs and full symbol tables, but does not yet provide all the flow analysis information.

DMS provides facilities to invoke the parsers/flow analyzers; you provide some custom code to extract the information you want.

It has the additional capability of modifying the ASTs and regenerating compilable source code.

I think you'll find that no tools for which you can extract precise custom data are "easy" to use; the very nature of the questions you ask and the answers have lots of complications caused by the complex language semantics.

Ira Baxter
+1  A: 

Try Klocwork. It has every gory detail you could ever need about C/C++ source code plus much much more.

This actually looks fairly impressive. It's not free but that isn't a show stopper. What I was really looking for was something I could use to programmatically analyse source, but I think this is worth looking into.
Brian Makin
+1  A: 

CppDepend is very useful for this kind of needs, CppDepend provides a CQL language to query the code base like SQL, for example you can execute requests like:

WARN IF Count > 0 IN SELECT TOP 10 METHODS WHERE CyclomaticComplexity > 20 ORDER BY CyclomaticComplexity DESC

CppDepend provides also many useful views; like Dependency graph, matrix graph and metric view

Issam