Link to home
Start Free TrialLog in
Avatar of phoffric
phoffric

asked on

Free Linux C++ Function/Method Call graph/tree Static Analyzer Generation using Doxygen, GraphViz, Dot

How can I generate a C++ function/method call graph/tree using Doxygen, GraphViz, and Dot? The result could be a text file and I would search on a function or method name, and I would be able to see who calls it (my main interest). Who it calls is OK, since a search on a name would show the caller anyway.

I do not want to use Dynamic profiling.

I heard that Doxygen has a way to do this. If someone is familiar with that approach, maybe you would be able to help me through the steps to get there.

I am not looking to write a C/C++ program to do this. I got the impression there are some scripts to do this job.

Thanks,
Paul
SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phoffric
phoffric

ASKER

Hi pepr,

Thanks for your reply.

> I may be biased as I am the translation coordinator for Doxygen.
Nah, now why would you think that? lol

I found a Doxyfile in trunk after doing an svn checkout. The attributes were set to your recommendations except for CLASS_DIAGRAMS and  SOURCE_BROWSER which I changed from NO to YES.

Note: HAVE_DOT is set to NO.

I looked up how to generate html and did this: doxygen Doxyfile

BTW - I did a search on "\;" and found close to 300K lines. It took about a minute to generate the html files.

I picked a class and saw a graph showing the inheritance hierarchy both above and below the class. That is nice.

Can I select a class member now, and see who calls it, and maybe even a caller hierarchy?
Have a look at http://www.doxygen.org/download.html. You will find the reference to the Git repository. The SVN was used earlier and you possibly have the older version.

For tha CALL_GRAPH and CALLER_GRAPH, you have to install the Dot tool (graphviz) and se the mentioned options to YES. I am not at the production computer now. However, you can read about the installation here http://www.doxygen.org/manual/install.html
Our Ubuntu 12.04 repository is not the public one, so I am at the mercy of whatever is in there. Is there any information that I can get to see if I can proceed with this approach? (If so, please let me know the command line.) Also, I do have a Synaptic Package Manager if that helps.
BTW - I had used doxygen occasionally in trying to navigate; but getting the graphical inheritance hierarchy is a nice newer touch. (Old style just gave long lists inheritance information.)

Just got back to work. Brought up Synaptic. Here is the Installed Version information (All this is new to me, so just shooting information in the dark):

doxygen            1.7.6.1-2ubuntu1 (also the Latest)
doxygen-latex   1.7.6.1-2ubuntu1 (also the Latest)
graphviz              2.26.3-10ubuntu1.1 (also the Latest)

Here are a few others that may be useful in the graphviz search that are not installed:
graphviz-dev       2.26.3-10ubuntu1.1
kgraphviewer      4:2.1.1-0ubuntu1    "a GraphViz dot graph viewer for KDE 4" (and I have KDE 4.8.5)
xdot                      0.4-2                         "Interactive viewer for Graphviz dot files"

If I install some of these and set HAVE_DOT to YES, do you think I will be able to see who the callers of a method are? Are there depth (or height) controls. Years ago I used Understand for C++ which produced very nice interactive caller/callee graphs, which were also great for documentation.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cool looking graphs. Could you tell me what I have to install on Ubuntu 12.04 and how to set up this GraphViz and Dot configuration files (if any).

A typical case inheritance case: Base <-- Class1 <-- Class2 <-- Class3
If I looking at a virtual method in Class3, then there may be several ways to reach it via calls to Base or Class1 or Class2, or Class3 directly. I get lost in our huge program as to how I got there.

Is there a way to set up the GraphViz and Dot configuration files so that I can ask how many different ways are there to get to Class3::foo(), or at least something that would help me get to that answer even if it takes multiple steps? If so, could you tell me how to do it.

Since the only suggestion to this cross referencing question is Doxygen approach, I am going to have the question customized to this. Otherwise, this thread could get unwieldy.
I am not sure as I use Doxygen and Graphviz on Windows. However, `apt-cache show graphviz` knows the package. This way `apt-get install graphviz` should be the way to install it. The same way, `apt-get install doxygen` should be the way to install Doxygen. Only, you probably have to set the path to the dot tool in the Doxyfile:
DOT_PATH               = "whatever on your OS"

Open in new window

I have no experience with what you try to do. The Dot tool is used only to generate the images. The input is prepared by Doxygen. If anything can be configured, then you should find it in Doxyfile.

I suggest to switch on all the Doxygen graphs to see whether it helps you or not. The situation and the Doxygen tool -- both are rather complex things, and you will know more when you see the results it is capable to produce. I am sorry, I do not have any better advice.
Thanks! I got call graphs and caller graphs after setting HAVE_DOT to YES. (Not sure why I didn't have to set DOT_PATH.) When the bottom-most method was derived from a pure virtual method, the caller graph did not appear. However, I then clicked on "Implements" <base class name>, and it produced a very nice hierarchy four levels up. Very nice! Now I should be able to navigate through the system much faster. Thanks again for you patience and help.

Although, the font in the graphs are unreadable (oh well), by hovering over them, I get a nice readable tool tip, and can click on the node.

Paul
Search for the DOT_FONTNAME and DOT_FONTSIZE in Doxyfile. You can set a better font and its size for your project.
Thanks!!!! How lucky does one have to be to get the translation coordinator for Doxygen helping you? The size was 4 (and I was ready to buy new glasses). I'll play around for the goldielocks-just-right size (8 was a tad too big). The font is FreeSans, which seems OK to me.

Thanks again for your help.
Paul
> How lucky does one have to be to get the translation coordinator for Doxygen helping you?

:) It would be better if someone else from Doxygen would help you. I am basically the one that tells the others: "Please, translate this or that." :)  Well, not to be so modest. I have designed the adapters for the human-language translator classes so that the pace of development of the core and the pace of translation of each language are separated.

I probably did something similar to what you are doing just now. I am not using Doxygen that intensively these days, but it is a good tool, in my opinion.

Have a nice day,
   Petr
Now I am curious. Are you using another product in lieu of Doxygen?
No, I am not using another documentation tool. Actually, I am still documenting my C++ sources using the Doxygen comments. I also write some separated documentation pages for the project. However, I do not use the generated results for looking what is the project about.