I'm building tool for testing ansi c applications. Simply load code, view control flow graph, run test, mark all vertexes which was hit. I'm trying to build CFG all by myself from parsing code. Unfortunately It gets messed up if code is nested. GCC gives ability to get CFG from compiled code. I might write parser for its output, but I need line numbers for setting breakpoints. Is there way for getting line numbers when outputting Control Flow Graph with -fdump-tree-cfg
or -fdump-tree-vcg
?
For the control flow graph of a C Program you could look at existing Python parsers for C:
Call graphs are a closely related construct to control flow graphs. There are several approaches available to create call graphs (function dependencies) for C code. This might prove of help for progressing with control flow graph generation. Ways to create dependency graphs in C:
Using cflow:
--cpp
option to preprocess the code.Using cscope:
ncc (cflow like)
The following tools unfortunately require that the code be compilable, because they depend on output from gcc:
egypt
uses gcc
to produce RTL
, so fails for any buggy source code, or even in case you just want to focus on a single file from a larger project. Therefore, it is not very useful compared to the more robust cflow
-based toolchains. Note that egypt has by default good support for excluding library calls from the graph, to make it cleaner.Also, file dependency graphs for C/C++ can be created with crowfood
.