Geting Control Flow Graph from ANSI C

I am creating ansi c application testing tool. Just download the code, view the control flow diagram, run the test, mark all the vertices that were deleted. I am trying to build my own CFG from code analysis. Unfortunately, it got messed up if the code is nested. GCC allows you to get CFG from compiled code. I can write a parser to output it, but I need line numbers to set breakpoints. Is there a way to get line numbers when displaying a flow control graph using -fdump-tree-cfg or -fdump-tree-vcg ?

+8
c gcc graph ansi
May 6 '13 at 7:23
source share
2 answers

So, I did some more research, and it’s easy to get line numbers for nodes. Just add the lineno parameter to one of these parameters to get it. So use -fdump-tree-cfg-lineno or -fdump-tree-vcg-lineno . It took me a while to check if these numbers are reliable . In the case of a graph in VCG, the format label for each node contains two numbers . These are the line numbers for the beginning and end of the piece of code represented by this node.

+6
May 09 '13 at 6:15
source share

For a graph of the C program's control flow, you can look at existing Python parsers for C:

Call graphs are a closely related construction for managing flow graphs. There are several approaches to creating call schedules (function dependencies) for C code. This can be useful for progress with the generation of the control flow. Ways to create dependency graphs in C:

The following tools, unfortunately, require compiling the code, as they depend on the output from gcc:

  • CodeViz (GPL v2) (weak point: compiled source required since it uses gcc to dump cdepn files)
  • gcc + egypt + dot (GPL v *, Perl = GPL | Artistic License, EPL v1) ( egypt uses gcc to create RTL , so it’s not possible to find any source code with an error, or even if you just want to focus on one file from a larger project, so it’s not very useful compared to more robust cflow based cflow that by default, gtypt has good support for excluding library calls from the graph to make it cleaner.

In addition, file dependency graphs for C / C ++ can be created using crowfood .

+15
Jul 24 '13 at 20:34
source share



All Articles