On 02/10/2010 06:56 AM, Paulo J. Matos wrote:
> Hi all,
>
> Sometimes to have an idea of the flow of a C program I just go
> `semantic-symref`ing functions so I get an idea of who calls who, etc.
>
> The perfect way would be to generate an image (maybe to a certain search
> depth) of the callers for a certain symbol.
> Was this done before? Any tips?
Howdy,
There is cogre for drawing graphs, but the only call graph I've done is
an eieio example for Elisp only.
Hooking up GNU/Global or IDUtils, and then writing a script to use
semantic symref seems like a clever way to gather a bunch of data.
COGRE provides a simple way to create a pile of nodes. If you then have
dot installed (the AT&T graph layout routines), COGRE will do a layout
of the graph, and can port it into various fancy output formats like PS,
or PNG.
If you look in cogre-uml-quick-class, you will see that the graph
creation part is only 11 lines long.
For the symref code, the initernal API that provides the raw data is
pretty easy too. If you look in semantic-symref, you will see that
getting the data is 2 lines of code. One for getting the tag under
point, and another to retrieve the symref object. Once you have that,
you can semantic-symref-result-get-tags, and then just get the :hit-tags
from the results, and you are good to go for dumping out a pile of COGRE
nodes.
To make it super-useful, creating custom cogre nodes that handle events
for showing source would be neat too. I think dot output supports
making HTML image maps. There are a few options here once the call
graph is generated.
Cool idea. It hadn't occurred to me that we were so close to getting
such a tool built, and it would probably be language agnostic, and work
for almost anything.
Eric
|