8

I'm looking for Control Flow Graph generator for source code written in C++. Do you know any open-source, static generator?

I would like to use it in my graduation project to generate control flow graph and highlight paths which has been executed during the execution of analyzed application.

I've already written entire engine to log executed lines.

Thank you for all answers.

  • These kind of questions are explicitly _off-topic_ here. Read point #4 from this [help center article](http://stackoverflow.com/help/on-topic). – πάντα ῥεῖ Nov 12 '16 at 13:20
  • 1
    Asking for software recommendations is off-topic on stackoverflow, but you can probably ask your question on [software recommendations](https://softwarerecs.stackexchange.com/). – nwp Nov 12 '16 at 13:20
  • Not open source, but see http://stackoverflow.com/a/41497191/120163 – Ira Baxter Jan 09 '17 at 02:06

2 Answers2

5

You can use clang or llvm.

First compile your program to llvm ir

clang++ -emit-llvm -S prog.cpp -o prog.ll

Then use opt to generate the control flow graph.

opt --dot-cfg prog.ll

This outputs a dot file which can be viewed with graphviz. On a mac you can do brew install graphviz and run the following to generate a png.

dot -Tpng cfg.main.dot -o main.png

You should have one dot file for every function in your program so it may be easier to write a script to automatically convert them all to pngs

1

CoFlo is a Free and Open Source source code analysis tool which generates and analyzes control flow graphs from C and C++ source.

Capsane
  • 11
  • 2