Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate sequence diagram for my Native (C, C++) code?


I would like to know how to generate a sequence diagram for my Native (C, C++) code. I have written my C code using vim editor.

Thanks,
Sen

like image 666
Navaneeth Sen Avatar asked Jan 07 '11 14:01

Navaneeth Sen


People also ask

How do you create a sequence diagram code?

In the Model Tree, right-click an operation and select Create Sequence diagram for code. You will then be prompted if you want to use the new diagram for forward engineering. The result is a new Sequence Diagram containing the lifeline of that class.

How do I create a sequence diagram in Visual Studio code?

seqdiag file in Visual Studio Code, preview tab will open automatically. If you wish to reopen the preview tab, press CTRL+SHIFT+P or F1 to open Command Palette and execute Show Sequence Diagram Preview command. See js-sequence-diagrams for syntax details.

What software is used to make sequence diagrams?

Sequence diagrams are a type of Unified Modeling Language (UML) diagram that shows interactions over time. This tutorial shows you how to draw sequence diagrams with Lucidchart.


3 Answers

First of all, sequence diagram is an object oriented concept. It is meant to convey, at a glance, message passing between objects in an object oriented program in a sequential fashion, which is supposed to help understand time-considerate interaction between the objects. As such, it does not make sense to talk about sequence diagrams in the context of a procedural language like C.

When it comes to C++, sequence diagrams are defined in the general sense by the UML specification, which is the same for all object oriented languages. UML is considered a higher-level concept from source code that looks the same for all languages, and the process of converting source code to UML is called code reverse engineering. There are tools that allow you to convert source code of Java, C++ and other languages into UML diagrams that show relationships between classes, like Enterprise Architect, Visual Paradigm and IBM Rational Software Architect.

A sequence diagram, however, is a special kind of a UML diagram and it turns out that reverse engineering a sequence diagram is quite challenging. First, if you wanted to generate a sequence diagram through static analysis, one of the first questions you must answer is whether, given two objects and a message passed between them, a result is ever returned. This means that, given a method, you would have to analyze its algorithm and figure out if it loops forever or it returns. This is known as the halting problem and has been proven to be undecidable in computer science. This means that in order to produce a sequence diagram through static analysis, you would have to sacrifice accuracy. Dynamic analysis works by actually running the code and mapping the interactions between the objects at run time. This presents its own challenges. First, you would have to instrument the code. Then, filtering out the interactions you are interested in from library and system calls and other fluff present in the code would not be doable without user intervention.

This is not to say that creating a tool that would produce usable sequence diagrams is not possible, but the market interest has apparently not been strong enough to justify the effort, and apart from a few research papers on the subject, like CPP2XMI, I'm not aware of any commercially available tools to reverse engineer C++ into sequence diagrams.

Compounding the problem is the fact that C++ is one of the most complex object oriented languages around, so even if somebody devised a good way of reverse engineering sequence diagrams, C++ would be the last language to receive the treatment. Case in point: Visual Paradigm offers rudimentary support for reversing Java code into sequence diagrams, but not for C++.

Even if such a tool existed for C++, the sad truth is that if your C++ code is complex enough that you would rather use a tool to make a sequence diagram for it instead of doing it manually, then it is most likely too complex for the tool to give you anything useful and you would have to fix it up yourself anyways.

like image 87
mnistic Avatar answered Oct 18 '22 13:10

mnistic


You could explore trace2uml with works with doxygen.

like image 29
Peter G. McDonald Avatar answered Oct 18 '22 15:10

Peter G. McDonald


You can try CppDepend which provides the Dependency graph and the dependency matrix to explore the dependencies between directories, files and functions.

like image 34
James from CppDepend Team Avatar answered Oct 18 '22 15:10

James from CppDepend Team