Slashdot Mirror


Visualising Code Structure in Large Projects?

TheMaccLads asks: "I've recently joined a new C++ project, and it's in a terrible state. There are 100-odd source directories, dozens of libraries, and a couple of dozen executables and DLLs. Some executables pull in (i.e. compile themselves) the occasional source file from a library, instead of using the libraries. My job is to port a subset to unix, but I need a tool to visualise all the relationships between directories, projects, libraries, and so on, because my brain will overheat soon otherwise. Preferably a tool that will do it by parsing the MS Dev studio projects and workspaces, but if I have to write it myself in Perl, I will! Anyone know of any tools? Or suggest an approach?"

47 comments

  1. visio by Anonymous Coward · · Score: 0

    Use visio

  2. Sounds rough by Anonymous Coward · · Score: 1, Interesting

    Use visio.

    Rational may have some software as well...

    Visio's definitely the way to go, though.

    1. Re:Sounds rough by Anonymous Coward · · Score: 1, Interesting

      Since when did visio parse MSVC project files?

    2. Re:Sounds rough by Anonymous Coward · · Score: 1, Interesting

      .dsp files are nothing more than a collection of compiler flags, there's no magic about them in regards to understanding the structure of the program.

  3. Pen and Paper. by spt · · Score: 5, Insightful


    Really! Just start drawing lines and boxes as you delve through manually. If you get something to do it automatically, you still won't have a good visualisation in your head.

    1. Re:Pen and Paper. by Anonymous Coward · · Score: 0

      I can second this. What I find useful to do often:

      - Make a pass over the code and list all the data structures that you see. Write down their definitions on paper for quick access.

      - Go through the files and document the code flow using diagrams. Label to show what gets passed around. Fill in the boxes with the computation thats done.

      - You can skimp on what seems obvious.

      This will take some time but in the end you will have a solid understanding of what's going on.

      Hope that helps.

    2. Re:Pen and Paper. by Anonymous Coward · · Score: 0

      But most programmers are lazy! That is what recursion and making tools to build your tools is all about! :-)

    3. Re:Pen and Paper. by spt · · Score: 1

      most programmers are lazy

      yes ... and I am the laziest of them all.

      This might seem like hard work, but I've discovered 2 things

      1) Spending some time like this up front will save you loads of time later. And saved time is lazy time.

      2) If you do something proactive at the start of a project, then everyone else thinks you are wonderfully energetic. If you build up some workplace brownie points now, you can squander them through laziness later.

  4. Rational Rose by Dr.+Bent · · Score: 1, Informative

    Rational Rose has some of what you're looking for, but the best way might just be a big, fat whiteboard, a digital camera (for taking pics of the whiteboard), and some elbow grease.

  5. Hmmm by Lord+Hugh+Toppingham · · Score: 2, Informative
    Software Emancipation's Discover product is pretty good at that, as is Takefive software Sniff++.


    Theres other products out there too, All are expensive.

  6. Perl's the Solution by maol · · Score: 1
    I've seen something like that for Perl (in perl), but google won't find it for me anymore.

    It went through all files and printed a nice graphical output (with gd?) with all functions in bubbles with connections all over.

    Should be possible to modify for C++.

    --
    --
    Du Deutsch -> Du gehe Symlink
  7. Doxygen by brenfern · · Score: 5, Informative

    I have used this, it is fantastic; it will work with your old C++ code straightoff, & also accepts javadoc-style comments. Handles the worst code elegantly. Draws pretty graphs for you. Does the bits of a programmer's job that really ought to be automated.

    1. Re:Doxygen by bitMonster · · Score: 5, Informative
      I agree. It works wonders on 3rd party sources too, even when they did not use any of the supported commenting conventions.

      Get it.

      I wish it supported python, which is the other OO language I routinely use.

  8. McCabe Visualization tools by Jack+Tanner · · Score: 3, Informative

    McCabe & Associates makes some software that will automatically create a graph for visualizing a large software project, even one using mixed languages. Their marketing department renames the software every other week, but that's what they do. Arthur Watson (PhD, Computer Science, Princeton) did their most interesting research a few years ago, but has since left the company.

    Their software will also help re-engineering and testing efforts: it'll tell you how complex your code is (and thus what parts of it are most likely to break), and it'll instrument your source code and show you what logic paths you've hit in your program during testing, and what code remains untested. It used to be pretty solid stuff (and pretty pricey!); I'd love to see some free/open software that does stuff like this.

    Disclaimer: I'm a former intern.

    1. Re:McCabe Visualization tools by Lord+Hugh+Toppingham · · Score: 1
      I'd love to see some free/open software that does stuff like this.


      Me too, but I doubt it will ever happen. This is not the kind of effort that interests the open source development community, since the projects they work on are (on the whole) not large enough to warrant such tools.


      I saw some evidence that the X-Consortium have started to use Rational ClearCase for their conf mangaement, I would love to see a free tool with the capabilities of ClearCase, but again Open Source developers have other more interesting things to work on.

  9. A HUGE whiteboard by ReidMaynard · · Score: 1

    and lots of colored markers...we do that here [for networking] and people gather round like a water cooler and point out issues, etc.

    --
    -- www.globaltics.net

    Political discussion for a new world

  10. Understand by __past__ · · Score: 1

    I never used it myself, but was told that Understand was pretty good at doing exactly this. It claims to support big and hairy projects, and runs both on Windows and Unix. Unfortunatly it is Free as in "Free trial" only.

  11. CodeWright for mapping by andaru · · Score: 4, Informative
    If you are going to map out the project by hand, CodeWright from StarBase (formerly from Premia) is excellent.

    It is the best editor I have seen yet (multiple language support, totally configurable, excellent tech support), and it is great for navigating large projects. It parses all of the files in your project as text (so you can browse code that does not compile), and is a good complement to Dev Studio's build-based browsing.

    It integrates with Dev Studio, so the two editors and environments will update each other when you switch between them.

    I probably shouldn't admit this on /., but at one job, I had a Windows box dedicated to running CodeWright, editing QNX code over Samba. It was actually worth the extra box. At another job, I was using it to edit files for Sun and DEC UNIX (no Samba this time), and it was still worth it to ftp the files back and forth, rather than use what I could find in the UNIX world at the time.

    I know also that there is some really good code mapping software out there, but I can't give you any names off of the top of my head. Large sheets of paper really do the trick, though. I have seen people spend a lot of time with visio getting very little done, but I haven't used it myself, so don't listen to me and I'll shut up now.

    --

    Why is Grand Theft Auto a much more serious crime than Reckless Driving?

    1. Re:CodeWright for mapping by Kaya · · Score: 1

      CodeWright is nice (for a Windows only editor), but Visual SlickEdit and Source Insight are superior when it comes to code navigation and analysis.

  12. Code Surfer by CFN · · Score: 1

    I've never used it, but I've heard about code surfer from GrammaTech.

    Is commercial software though.

  13. My story by Kz · · Score: 2, Insightful

    A few years ago, I found myself at a similar situation; I had to port a Bridge game from DOS to Mac. I had the full source code, but it was so old I couldn't make it compile. Even worse, I had never played Bridge!

    I started playing with the executable, and learned the cards game (very boring! never played it again).

    Then I wrote some utilites using .BAT files, the 'Find' command from DOS, and QBasic. Those utilities allowed me to type any function or global variable (there were lots of globals!!) and it would tell me in what file was defined, declared, and what functions used it (with a tree of callers)

    It took me a couple of days to write the utilities, and proved really lifesaving

    after that, I used paper. If there was a long function with lots of nested loops and goto's (it was C, but looked like bad basic); I would print it and tape the paper to the wall. Then just spend hours looking at it, pencil at hand, drawing arrows and notes over the code

    Very slowly, I separated the engine from the UI and IO code.

    Then I just wrote a new application on the mac, that called the old engine code. Of course the game gained a lot of mouse manipulability, sound effects and even a video intro (without QuickTime, of course)

    In short, first craft your tools, then use them. Spend lots of time just looking at the code. Slowly the hate will melt into pity for it, then your job will be to liberate it!

    --
    -Kz-
    1. Re:My story by Tablizer · · Score: 1

      (* If there was a long function with lots of nested loops and goto's .... *)

      Just curious. If you re-wrote it from scratch, do you think the result would be quicker and/or better than reverse-engineering a mess like that?

    2. Re:My story by Kz · · Score: 1

      It was a mess, but it worked.

      Remember, I barely knew how to play bridge, I wouldn't try to reimplement the inference engine that chose which cards to play. That code had lots of years of debugging and real world exposure in there.

      All the analisys was to separate the core (untouchable) from the UI and IO and re-creating the environment it needed to work

      --
      -Kz-
  14. CDOC by Software Blacksmiths by qurob · · Score: 1


    This works pretty well

    http://softwareblacksmiths.com/

  15. Some other solution by fm6 · · Score: 2

    I remember seeing some other solution somewhere that might be applicable. Can't remember what it was called. No wait, I'm thinking of a Thai cookbook. Never mind.

  16. Am I missing something? by fm6 · · Score: 2
    Doxygen seem to be a sort of Javadoc clone. The main difference is that it's not limited to Java and it supports more output formats. Nice if you have an API you want to document with a minimum of work, but that's hardly a "visualization tool".

    Unless I overlooked something, the only diagrams Doxygen draws are class hierarchies. Unless you have a lot of classes, I can't see bothering with a whole big app just for that.

    Doxygen sounds like it's handy for generating API docs with a minimum of effort, but pretty useless for analyzing mysterious legacy code.

    1. Re:Am I missing something? by bitMonster · · Score: 2, Informative
      Yes.

      The class hierarchies are very sophisticated. For example, you can see a page with a summary of all the methods for a derived class showing where all of these methods are inherited from. The same view shows all the attributes on each method, such as virtual, inline, static, etc.

      There is also a whole section generated on include file hierarchies. You can see quickly where everything is declared without doing a bunch of greps to try to see how things fit together.

      Finally, the hyperlinking scheme is simply inspired. For example, it will even take you to the exact line of a header file that corresponds to a particular method (complete with syntax highlighting).

      Go look at it. It's not going to reverse engineer design documentation from the intent of the code, but it gives you a huge advantage over a big pile of C++ files. (If you think you are going to find a tool that does the former, you're smoking something.)

  17. Yes you are missing something by brenfern · · Score: 1

    Go and try it. Of course it cannot do your whole job for you, but a major step in understanding old code is to understand the class hierarchy. It is not a whole big app - you just run it on the code and it spits out HTML + diagrams. How can you say that it is useless if you have never used it and do not know what it is or does?

  18. Post-It notes and a DryErase Board, Bake at 350 by QuietRiot · · Score: 3, Funny

    5 People
    3 Afternoons
    1 Huge Pile of Code
    2 Large White-boards
    3 small little cubes of those MultiColored post-ITs
    2 Handfuls of assorted colors DryErase markers

    Start by pouring all the ingredents into a medium sized classroom-type-room with lots of chairs and a small assortment of refreshments. (Be sure to wash off the white board.) Tell all the people what you are trying to do and tell them they will have to help you out for at least one afternoon over the next couple of days. [Whatever. Intimate time with code. They'll learn something. You'll get to talk to eachother.] Tell some they have to stay, others they'll have to help you tomorrow, etc. Look over the code and decide which portion you'd like to work with today. Isn't it pretty? Now - by applying the markers and the PostITs to the White-board, carefully extract the useful parts of the code, leaving the nasty, hairy choke behind. Go for the structure. Go for the connections. Dispose what is leftover. Take a high resolution picture. Go home and get some sleep.

    Repeat the above for each piece of the program you'd like to work on for each particular day. After you have extracted all the good, and none of the bad, combine the extract with your wonderful programming skills, the sarcastic cheers from your friends in nearby cubicles, and big high-resolution printouts of your photography work in a CPU Unit Processor, blending until firm. Chill, Serve and Enjoy!

    1. Re:Post-It notes and a DryErase Board, Bake at 350 by flacco · · Score: 2
      You left a couple things out:

      First, you forgot to include the disgruntled Evil Janitor in your list of people, for a total of 6.

      Insert the following step before "Repeat the above...":

      "Evil Janitor swaps around pretty colored paper squares in the middle of the night."

      --
      pr0n - keeping monitor glass spotless since 1981.
  19. snavigator by Anonymous Coward · · Score: 1, Interesting

    Source Navigator. Free since red hat bought out cygnus.

    rpm's for most distros.

    Great tool for what you're talking about. I'm just surprise no one else mentioned it.

    -Jay

    1. Re:snavigator by Bruce+Stephens · · Score: 1

      Source Navigator also produces databases (documented) which, with simple scripts, you can process in various ways, for example to feed to graphviz tools (also free) to produce pictures, http://www.graphviz.org/

  20. What I want... by ptomblin · · Score: 2

    ...is something like etags, but which will show who calls the function/method I'm looking at now. Etags in vim is great for tunneling down to the definition of the functions that I'm calling, but not so good for going "up". So far I mostly end up using "find . -type f -name \*.[Chc] -print0 | xargs -0 grep foo", which is time consuming and annoying.

    --
    The next Cmdr Taco duplicate will be ready soon, but subscribers can beat the rush and see it early!
    1. Re:What I want... by MemRaven · · Score: 3, Informative
      Well, I've been using Visual SlickEdit (mentioned elsewhere in the thread) for a couple of years now as virtually my exclusive editor, and it runs on almost every platform I care about (Intel Linux, Windows, Sparc Solaris, FreeBSD, etc.). Its tagging goes way beyond what etags does, and has built-in reference analysis. Once you've built your tag database (which automatically updates when you edit a file in slickedit), you can choose to view references. You type in a tag (such as a method or variable name), it'll pop up a list of potentially matching tags (so if you have a lot of things named getName(), for example, it'll let you choose which one), and then it will display all code which references that tag. You can then double click on a code region to go straight to the file and area where that exists (although it shows you a few lines at a time normally). I think there's actually a keyboard shortcut to do that for a particular tag (just like you can automatically go to the declaration of a tag)

      Although this seems like a convoluted feature, it's extremely useful for doing any kind of refactoring work where you want immediate feedback analysis. You get to see immediately where everything is used, and it's got other tools which help with that as well (like the class browser and the like). (It also has Visual Basic-style autocomplete, which I absolutely love, because on large projects I never remember exactly what everything's named).

      Admittedly, you might not want to change editors just for this feature, but you might want to have it in your arsenal of tools for when you do need/want it.

    2. Re:What I want... by Anonymous Coward · · Score: 0

      grep -in foo *.[cCh]

  21. to start with ... by Anonymous Coward · · Score: 0

    Download cygwin, first. Then ...

    cd wherever
    find . -name '*.cpp' {} -exec "more" {} \;

    start reading.

    keep using "find . -name '*.cpp' -exec grep \
    whatever {} \; -print"

    until you've sort of figured it out.

    then ...

    tar cvf 2unix .
    gzip 2unix.tar
    ftp linuxbox
    user root h4ckm3
    binary
    put 2unixtar.gz
    quit

    turn the old windows box into a dedicated
    winamp player: somafm.com, radiopardise.com.
    ... or reformat the hard drive, install Red Hat
    and donate it to charity.

    No rational chablis or burgundy or rose
    tool is going to solve your problem You must
    grab the code, smash against it your skull, and
    figure it out. Large projects must have
    conceptual integrity. Your tool is your brain.
    There's no subsitute for success: it's hard
    work, learning from mistakes, preparing and
    taking advantage of opportunities.

    Good luck.

  22. How to make typing the find command less hassleous by Anonymous Coward · · Score: 0

    1) Use the "vi" (or "emacs") editing mode
    in the command line
    so you can redisplay previous typed in commands
    and f)orward to n)ame and c)hange w)word.
    This means less stressed fingers.

    2) Make a damn batch file that takes the
    thingie your greping for an argument.

    ZZ

  23. Cscope by Anonymous Coward · · Score: 0
    Cscope will help you do this sort of thing. Run it over your source code and it will build a database of functions, functions calling functions, include files, etc. Then you can query that to search for definitions, occurances, etc. There is even an Emacs interface for it.

    Cheers,

    Toby Haynes

  24. no real shortcuts by markj02 · · Score: 2

    If you really need to understand the code, you will just have to spend the time. Diagrams and tools may help a little, but ultimately, there are only so many bits you can get into your head per hour.

  25. Definitely doxygen by Anonymous Coward · · Score: 0

    As others have said, Doxygen (http://www.doxygen.org) is spectacular on C, C++ and Java.

    We have used it on a 300K line C++ system that had a myriad of developers working on it, and it has worked exceptionally well.

    Make sure you couple dot (GraphViz) to it so that you get the nice collaboration and dependency graphs; they are exceptionally useful.

  26. Source Insight... (and 30 day free eval) by MeerCat · · Score: 2

    You say "DLLs" so I'm guessing PC rather than Linux... Source Dynamics produce Source Insight which is a groovy C++ editor that scans all your code, holds it all in a metabase, and while you're perusing it runs a lazy thread in a seperate window to show you more details of whatever is under the cursor. It's not a C++ visualisation tools (it has a speedbar outline of the current file) but is very good at helping you jump navigate thru large amounts of source code.

    The bonus is that it runs very fast, is useful as an editor, and knows enough about all your code to do smart things like smart-gloabl-rename, find all references to symbols, etc.

    They do a 30 day free eval too...

    T

    --
    I spent a lot of money on booze, birds and fast cars. The rest I just squandered. - George Best
  27. Visualising Code Structure in Large Projects=ROSE by man4allczn · · Score: 1

    The Rational Rose product includes round trip engineering that allows you to model the architecture of your project either from the beginning and providing a framework for you to code into, or by reading your current completed code and generating a model from it. p.s. I used to work there as an engineering manager.

  28. Together by ansonyumo · · Score: 1

    Together from TogetherSoft is an excellent reverse-engineering package for C++ and Java. There is a free eval that does most everything, but will not print or export diagrams. The full-version license is pretty pricy (around $3k) from what I hear, the website doesn't list a price.

    Also, to find references to particular methods and subroutines, LXR is very useful. LXR is designed for use with the Linux codebase, but it is generic enough to be used with any C/C++ project. It takes a couple of hours to get running, but it is free and very cool. I just wish it would support Java.

  29. DOC++ by ansonyumo · · Score: 1

    DOC++ looks useful, too. I spent 7 years coding C/C++, and moved into the Java world 3 years ago. One of the greatest assets to the Java platform is the self-documentation supported by JavaDoc (that is, comments in the code are used to compile the API reference manual). Granted, your project doesn't conform to the DOC++ commenting syntax, but it should be useful for viewing the class hierarchy and browsing the API.

  30. Doxygen by TheMaccLads · · Score: 1

    Well, after reading all that (I had no idea my story had been accepted until today!), I've had a look at Doxygen, as it seemed to get the most favourable comments/moderator points. It's pretty impressive. I downloaded a win32 binary, ran the "wizard", pointed it at a few directories, and a few hours of 90% CPU usage later I have a pretty good HTML resource. Part of my problem has been finding out what's defined where (there are three main areas of development, each of which is split into five to ten subsystems, and subsystem 1 in area 1 is a bit like subsystem 7 in area 2, etc), and this really helps. Click on a class, it takes you to a doc on the header file. I haven't got any relationships between classes (I don't know if doxygen can do this, yet), but I'm impressed. It managed to parse a lot of the crazy preprocesor definitions (y'know DECLARE_SINGLETON kind of thing) without a hiccup. The points about learning how the system is put together the hard way are well made, I agree with the sentiments, but when time is limited the tools make a difference to productivity. Thank you all for your comments, most informative. If I ever get the time, I'll look at some of those other tools.

    --
    Money implies poverty (Ian M. Banks)