1

I am trying to understand a C++ codebase. I have used some free tools that will scan the code and produce diagrams, but they are not so easy to understand.

What I think would be useful is to manually construct something assisted by the UML tool.

What i need is to create something that looks like the data structure at run-time. Ideally by pulling objects from the UML and arranging them. Also I would like to organise the classes in sub-packages - like those close to the DB, or towards the branches of the datastructures.

(I am partly doing this now with Folders in the Visual Studio Solution explorer)

This is a LINUX project with many Makesfiles, but many tools like Visual Studio, "understands" the code when I just create projects with the files in the main directory of the exe I am working on

Olav
  • 1,758
  • 4
  • 27
  • 49

4 Answers4

0

Honestly, you might have substantial problems getting anything useful out of a UML tool with regard to reverse generating code.

If the code is unusually clean and had a decent OO design, good containment, inheritance, and few associations theres a chance that it might look alright... but with most real projects, when you reverse generate into UML, the resulting diagrams are a spidery mess that will probably do more harm than good.

If you are going to stick with the reverse-model genreation though, try and configure the UML utility to show less items - keep it to the key relationships like aggregation and inheritance. When you start showing uses relationships rather than contains/aggregation relationships then everything tends to connect to everything unless the project was very well written, and that will just lead to more confusion and micsonceptions.

My best recommendation would be - if the tool makes it look incomprehensible, save yourself some time and do it yourself.

John Humphreys
  • 37,047
  • 37
  • 155
  • 255
  • When I try to read the code I try to imagine the main data-structure and how the rest of the code interacts with it. It should be easier to draw these from UML than to draw it manually. Also tools can have knowledge about how objects can relate to each other – Olav Aug 01 '11 at 14:29
0

UML and C++ code that wasn't generated from UML don't play together that nicely. Especially as soon as templates are involved you might get into more trouble then you would actually like and you need to ask yourself if the time spent into getting those models isn't actually better invested in good old-fashioned source code reading. You will have to read the code eventually to understand what it does so just get started now.

pmr
  • 58,701
  • 10
  • 113
  • 156
0

Most tools will only give you a structural view (classes and packages), which honestly doesn't tell you that much of what goes on in runtime.

Enterprise Architect from Sparx Systems incorporates a Visual Execution Analyzer, which can generate sequence diagrams from a debug session. It supports C++ but only on Windows so you'd have to rebuild, but if I understand you correctly you've already got your code running in Visual Studio.

Here's a brief demo (in this case the code is in C#, but they do claim to support C++ as well). This isn't a full-roundtrip, write-the-code-in-UML kind of thing, but personally I think that's a pipe dream anyway. Use UML to document, use a programming language to code.

Uffe
  • 10,396
  • 1
  • 33
  • 40
-1

Didn't understand if it's linux or windows (you say linux, but then say you're using visual studio).

If you want to understand the code, Source Insight is a good tool for that. Not necessarily UMLs, but produces nice graphs in real time.

Gilad Naor
  • 20,752
  • 14
  • 46
  • 53
  • It is LINUX, but it seems many tools "understands" the code without the Makefiles and the include-files, and therefore I can also work from Windows. – Olav Aug 01 '11 at 13:43
  • "real time" you mean from a running executable? – Olav Aug 01 '11 at 13:45
  • No, I mean real time as you edit the code. You will not get formal UML diagrams, but you will get graphs depicting the data structures, and the way they interact with the code, AS YOU BROWSE the source – Gilad Naor Aug 01 '11 at 17:16
  • I don't think you can really deduct data-structures at code time? (In the sense of how objects are connected to each other) – Olav Aug 02 '11 at 08:21
  • Then how do you expect the UML tools to do that? Source Insight does the same, except that it does it much faster. The price is a large index file on the hard-disk. – Gilad Naor Aug 02 '11 at 11:00
  • It could potentially be better than Office Draw :-) I could drag objects from the UML tools into my own diagrams, and click back to UML again. An UML tool could know what can connect, and also give some order in the classes. – Olav Aug 05 '11 at 07:36