views:

102

answers:

2

Hi all, I am using Ubuntu 10.04, and studying programming of kernel objects.

I have come across some rather complicated structs which I have difficulties reading, so I thought I'd try to find some tool that can help me visualise them.

Only thing I could find so far is VCG, which has a C Struct Visualization Example, which looks like this:

which looks like something I'd like to use.

First thing, is that the last VCG packaged for Ubuntu is vcg (1.30debian-6) in hardy - but the .deb package can be downloaded and installed in Ubuntu Lucid without problems.

However, it seems this package is only a VCG viewer (similar to vcgviewer, I'd guess). The vcgviewer page notes:

To generate compiler graph data with newest gcc compilers use:
gcc -g -da -dv -fdump-tree-original-raw -fdump-tree-all-all 

So, apparently I'd have to use those switches along with gcc while compiling, to generate .vcg graph files from the C source.

The problem, however, is that I'm building a kernel module, which only references the Linux headers - as I try to avoid as much as I can the recompilation of entire kernel. And it seems, as soon as I try to use -fdump-tree-... switches in that context (kernel module), gcc wants to start compiling the rest of the kernel too! (and obviously fails, in both compilation and generation of .vcg graphs - as I don't have the kernel sources, only headers)

So my question is - is there a tool, that would produce .vcg or .dot graphs of structs - simply using a plain text header file as input? (it would not have to resolve all dependencies - simply those in header files in same directory)

EDIT: it is actually not that important for me that the backend is .vcg or .dot in particular, I mentioned them just because I've found them so far; any sort of software that would allow similar struct visualization, regardless of backend, is welcome :)

PS: Note that if you do not want to use VCG viewers for viewing .vcg graphs, you can convert the .vcg format to a .dot format, and use graphviz instead for the visualisation. What worked for me is to use graph-easy - search.cpan.org for perl - which first got packaged in Ubuntu with Maverick edition, as libgraph-easy-perl (however, the .deb file can - again - be downloaded and installed without problems in Lucid). libgraph-easy-perl installs a graph-easy script, which then allows to do stuff like:

graph-easy test.vcg --as_dot | dot -Tpng -o test.vcg.png 

See also "[graphviz-interest] VCG files" and "Diego Novillo - Re: can't find VCG viewer" for another vcg-to-dot script (which, unfortunately, didn't work for me).

+2  A: 

I have had good experiences with using doxygen for that task. It is designed to create documentation out of annotated source files, but it can already give you a lot of things without the annotations, including various graphs. Doxygen uses dot for the graph creation.

Bart van Ingen Schenau
Hi Bart, thanks for your response! This SO page: [Open-source tool to visualize C/C++ header file dependencies? - Stack Overflow](http://stackoverflow.com/questions/1190597/open-source-tool-to-visualize-c-c-header-file-dependencies) has a nice, quick intro to doxygen - but it seems it will require some messing around :) Also, edited my question, so it is clear that I do not necesarilly require `dot` or a specific backend; any facility to visualize structs based on source files would do. Cheers!
sdaau
@sdaau: Powerful tools always need some work to get them to do exactly what you want, especially if it is not the default use they were designed for. Doxygen uses dot internally, but its output is directly viewable image files.
Bart van Ingen Schenau
Hi Bart - just to mention: I agree completely re: need some work! I was just wandering if there are any alternatives, that could be possibly more suited to the task :) ... Thanks for the comment - cheers!
sdaau
+2  A: 

I've managed to successfully build a kernel module with vcg generation by doing the following:

  1. Creating a linked copy of the kernel source or header directory using cp -al /usr/src/linux-srcdir /tmp/tmp-srcdir since gcc wants to write to the current working directory.
  2. Adding EXTRA_CFLAGS="-g -da -dv -fdump-tree-original-raw -fdump-tree-all-all" to the make command line eg. -C /tmp/tmp-srcdir M=pwdEXTRA_CFLAGS="-g -da -dv -fdump-tree-original-raw -fdump-tree-all-all". the vcg files are generated in /tmp/tmp-srcdir
Hasturkun
sdaau