How to produce call graphs

Hi,
What kind of tools can produce call graphs from Ada code (or object code, no matter) ?
The kind you would ask “What / How is called function F1 ?”
and it would retrace all the sequences of subprograms leading to call F1, starting from the main subprogram.

I haven’t tried it (I don’t have GNAT studio installed), but their documentation suggests GNAT studio can:

https://docs.adacore.com/gps-docs/tutorial/_build/html/callgraph.html

You might try “Understand for Ada” from SciTools – they support Ada 83 up to Ada 2012 according to their website, and have a free trial/educational license:

Scitools Licensing

1 Like

Getting a demo ain’t easy !
I think the word I wanted was a “control flow graph”.
But it doesn’t seem there are any free tool with these kinds of features. Really disappointing.

Looks like the Adacore Ada Language Server can do this :

The language server can be installed in VScode. I guess it is also embedded in GNATStudio (which I don’t use).

Another possibility it to use libadalang, or its programmable interface LKQL (GitHub - AdaCore/langkit-query-language: query language for Libadalang and Langkit), which would allow you to write out a graph yourself in .dot format, for graphviz to process. I use graphviz all the time for displaying graphs, and it is a great, open-source tool. Visit https://graphviz.org/ to learn the syntax of the DOT language. It is extremely simple.

2 Likes

From a profiling perspective, you can use valgrind --tool=callgrind and then visualize the gathered data with kcachegrind. Even if not interested in the profiling, the call graphs are there, but only for actual calls that happened during the execution.

1 Like