I always find it difficult to understand the legacy code after joining a new project. I cannot understand it until I can visualize it. Cscope, Ctags have been great help in this effort, but they don't present the source code structure in visual form. I tried KScope a while back, it's good. But today I got working a very useful method of visualizing the program execution. It's documented in this article on IBM Developerworks.
If your project has a C binary, then using the pvtrace utility mentioned in the article (which uses addr2line) and graphviz, you can create awesome picture of your C source code. (I haven't tried this yet on C++). One hiccup that was keeping me from getting this to work was resolved today. I was running it on an executable that was linking to a shared library. So even though I was compiling the whole library and the executable with debug symbols, the addr2line utility couldn't get the symbols that were in the shared library. When I realized that, I re-ran the linking part of my executable, so that it would now link the .a file statically, instead of .so file dynamically. The resultant binary had all the symbols.
After following all the steps in the article I came up with this picture.
Tuesday, August 12, 2008
Subscribe to:
Post Comments (Atom)
4 comments:
Do you still have pvtrace.zip ?
Original link is broken http://www.mtjones.com/developerworks/pvtrace.zip
Hi, I do have the pvtrace.zip. Unfortunately the source code doesn't have any licensing information. It won't be appropriate of me to host it for people to download, w/o the original author's consent.
Here is another tool I came around to do the same job.
http://www.gson.org/egypt/
I haven't tried it yet, but the results from the site look good.
The popular Doxygen tool now does an excellent job of this as well - incidently it also uses GraphViz to achieve this. Simply run an HTML output documentation generation on your project with 'charts' switched on, then go to the resulting index.html and you should see an option in the navigation pane called 'Graphical Class Hierarchy' which brings up the image.
Post a Comment