Combine C-Call Graphs with Doxygen or Define Combine All Calls

I have a set of legacy C code that I am refactoring to break C compute code from a GUI. This is complicated by a strongly recursive mathematical key code, which is a K & R style declaration. I already abandoned the attempt to convert them into ANSI declarations due to the nested use of functional parameters (I just could not get these last 4 compiler errors).

I need to move some files to a clean DLL and define a minimal interface to make it publicly available, which will require the use of wrapper functions to publish a typed interface.

I highlighted the key source files using the Doxygen @callergraph markup, so informative graphics are created for individual functions. What I would like to do next is to combine these graphs so that I can determine the narrowest border of functions that are open in the outside world.

The source header files are useless - they expose everything as untyped C functions.

There are hundreds of functions, so simply inspecting the generated calligraphers is painful.

I am thinking of writing some kind of DOT merge tool - setting DOT_CLEANUP = NO makes Doxygen leave the intermediate DOT files, and then just saves the png files that they generated.

I am not obsessed with this graphical solution - I would be very pleased if someone could offer an alternative analysis tool (free or relatively cheap) or a technique using Doxygen XML output to achieve the same goal.

The accountant, combined at the file level, has a certain attractiveness for client documentation, and not a simple list :-)

+4
source share
3 answers

In your doxyfile install

GENERATE_XML = YES 

and then you can find your call schedule in the XML files. For each function marked with callergraph, you will find <referencedby> output elements that you can use. Here is a sample from one of my C files:

  <memberdef kind="function" id="spfs_8c_1a3" prot="public" static="yes" const="no" explicit="no" inline="no" virt="non-virtual"> <type>svn_error_t *</type> <definition>svn_error_t * init_apr</definition> <argsstring>(apr_pool_t **ppool, int *argc, char const *const **argv)</argsstring> <name>init_apr</name> <!-- param and description elements clipped for brevity ... --> <location file="src/spfs.c" line="26" bodystart="101" bodyend="120"/> <referencedby refid="spfs_8c_1a13" compoundref="spfs_8c" startline="45" endline="94">main</referencedby> </memberdef> 

So, for each memberdef / referencedby pair, you have a caller relationship that you can capture through XSLT:

 <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:apply-templates select="//memberdef[@kind eq 'function']"/> </xsl:template> <xsl:template match="memberdef"> <xsl:variable name="function-name" select="concat(definition, argsstring)"/> <xsl:for-each select="referencedby"> <xsl:value-of select="concat(./text(), ' calls ', $function-name, '&#xA;')"/> </xsl:for-each> </xsl:template> </xsl:stylesheet> 

Which gives you the line for the caller as follows:

 main calls svn_error_t * init_apr(apr_pool_t **ppool, int *argc, char const *const **argv) 

You want to customize this XSLT and then split this oriented graph so that it crosses the smallest edges. Woo hoo, NP is a complete problem! Fortunately, there are many papers on this subject, some of them: http://www.sandia.gov/~bahendr/partitioning.html

+5
source

I had a similar requirement. Wrote a perl script to combine a set of point files into one point file.

https://github.com/bharanis/scripts/blob/master/doxygen_dot_merge.pl

merge several files generated by doxygen points. This is useful for creating a call map for a file or multiple files.

1) This command is run from outside the html directory where doxygen places all the html, dot and map files.

2) This command assumes a flat directory structure used in doxygen CREATE_SUBDIRS = NO

3) doxygen prefix of the original file name for the name of the output point files. One point file is generated for each function.

4) provide a list of files created using doxygen for combining. eg:

 ./doxydotmerge.pl `ls html/ssd_*_8c*_cgraph.dot | grep -v test | grep -v buf` 
+1
source

You can use Scientific Toolworks to see your system call schedule.

If you want to automate analysis and cutting, you can consider the DMS Software Reengineering Toolkit. It can calculate full call graphs for C (complete with point analysis for function pointers) and is proven for systems of 35 million lines of code. This will produce fully functional DOT files for verification; they are quite large, but you can select subsets to view. See flow analysis and call schedules .

0
source

All Articles