Home » Linux » Spaghetti code visualisation software?

Spaghetti code visualisation software?

Posted by: admin November 30, 2017 Leave a comment


a smoking pile of spaghetti just landed on my desk, and my task is to understand it (so I can refactor / reimplement it).

The code is C, and a mess of global variables, structure types and function calls.

I would like to plot graphs of the code with the information:
– Call graph
– Which struct types are used in which functions
– Which global variable is used in what function

Hopefully this would make it easier to identify connected components, and extract them to separate modules.

I have tried the following software for similar purposes:
– ncc
– ctags
– codeviz / gengraph
– doxygen
– egypt
– cflow
– frama-c
– snavigator
– Understand

The shortcomings of these are either
a) requires me to be able to compile the code. My code does not compile, since portions of the source code is missing.
b) issues with preprocessor macros (like cflow, who wants to execute both branches of #if statements). Running it through cpp would mess up the line numbers.
c) I for some reason do not manage to get the software to do what I want to do (like doxygen; the documentation for call graph generation is not easy to find, and since it does not seem to plot variables/data types anyway, it is probably not worth spending more time learning about doxygen’s config options). EDIT: I did follow a these Doxygen instrcutions, but it did only plot header file dependencies.

I am on Linux, so it is a huge plus if the software is for linux, and free software. Not sure my boss understands the need to buy a visualizer 🙁

For example: a command line tool that lists in which functions a symbol (=function,variable,type) is referenced in would be of great help (like addr2line, but for types/variable names/functions and source code).



My vote goes to gnu global. It has all the features of ctags/cscope combined as well as the possibility to generate fully indexed html which allows you to browse the code in your favorite browser. Fire it up in apache and you have a web-service that anyone can access including full search capabilities.

It integrates nicely into emacs/vim/even the bash-shell, and you can use it directly from the shell-prompt.

To see it in action on the linux kernel, visit this

Combine that with a tool for cyclomatic complexity plugin for eclipse which calculates the complexity of your code. besides the cyclomatic complexity it can handle:

  • McCabe’s Cyclomatic Complexity
  • Efferent Couplings
  • Lack of Cohesion in Methods
  • Lines Of Code in Method
  • Number Of Fields
  • Number Of Levels
  • Number Of Locals In Scope
  • Number Of Parameters
  • Number Of Statements
  • Weighted Methods Per Class

…and you should have everything you need.


If you like command line 😉 maybe you could try cscope, it does static analysis of code and can tell you where are referenced some symbols/variables/functions… Not the Holy Graal, but it can be pretty usefull to browse unknown source code.

There are also some GUI that can handle csope results (Vi, Emacs, JEdit…).

On the other hand, Eclipse with the CDT plugin can also help you to navigate into the spaghetti code you have to maintain.


It’s not free and afaik not linux but cppDepend might be worth evaluating – at least until someone comes up with a more suitable suggestion 🙂

http://www.cppdepend.com/ [Demo video here]


If you’d like to know in which functions a symbol is declared or referenced you can try LXR. It’s not console based, but is quite usable.