How to generate UML sequence diagrams from C code?

依然范特西╮ 提交于 2019-12-11 07:25:54

问题


I have looked at a utility trace2uml which parses the source code and looks for a Trace2UML syntax to describe the sequence diagram and creates the sequence diagram. I am interested to know if it is possible to create the sequence diagram by parsing the C source code alone?


回答1:


I am not a big connoisseur of UML diagrams but i know that generating diagrams from the code like: sequential diagram or class diagram are intended for object oriented languages like Java, c++, c# and many others. So if you ask me, it is not possible no generate sequence diagram from the code written in the C.

If you have some code written in the some objected language its possible to generate sequence diagram especially in the visual paradigm (tool for creating UML diagrams).




回答2:


It does not matter whether it's C (not-/) or C++ (OO). The problem is called Halting problem: see wikipedia. For that simple reason you can not create SDs from pure source. Anyway, a SD is meant to emphasize a certain phase of the executing code, not all paths. Just imagine how ridiculously spider-webby such a SD would look like. It were just useless.




回答3:


I don't think this is possible at all, by principle. Source code is inherently static. Sequence charts depict dynamical behavior. The dynamic behavior isn't in the source code, so it can't be extracted.

There are tools to make call graphs from C source in both directions, like cflow. Maybe a call graph can provide some insight into some source code's inner workings.




回答4:


Have you tried with plantuml? It works really well with doxygen, I use it at work with the company template and the syntax it's really easy, you have to write the call sequence yourself though. There are plenty examples in the page, if you are working in Linux you can use your native packaging tool to install it, the same applies to doxygen (e.g. sudo apt-get plantuml). Otherwise if you are using Windows you can use the installers from the official pages too.

You'll have to do some configuration but it's pretty straightforward, I'll leave you the links to each tool.

Download pages:

  • http://plantuml.com/download
  • http://www.doxygen.nl/download.html

Plantuml examples: http://plantuml.com/sequence-diagram

You can find the documentation in each page, for plantmul you use java executable (.jar) then you don't have to install nothing, you just need to configure doxygen to find the executable, you can find how in the doxygen documentation page:

http://www.doxygen.nl/manual/index.html

If you want to configure it without reading the documentation you could also watch this video: https://www.youtube.com/watch?v=LZ5E4vEhsKs

I hope this helps, cheers.



来源:https://stackoverflow.com/questions/49817793/how-to-generate-uml-sequence-diagrams-from-c-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!