I want to generate a Program Dependence Graph (PDG) from C source code. I found papers that explain how do it, but all used the commercial CodeSurfer tool.
Are there any free tools or open source projects that can do this job?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Frama-C is an Open Source static analysis platform with a slicer for C programs based on the computation of a Program Dependence Graph.
Note that slicing actual programs written in a real programming language such as C involves many special cases and concepts that are skimmed over in scientific publications. Still, I am confident that you won’t find anything simpler than Frama-C’s PDG computation, first because it is the only Open Source one available (that I know of), and second because any other PDG computation that handled C programs would have to solve the same problems and introduce the same concepts.
Here is one example:
The command
frama-c -pdg -pdg-dot graph -pdg-print t.cgenerates dot filesgraph.main.dotandgraph.f.dotcontaining the PDG ofmain()andf()respectively.You can use the
dotprogram to pretty-print one of them thus:dot -Tpdf graph.main.dot > graph.pdfThe result is below:
Note the edge from the node
c = f(b);to the node*p = 2;. A PDG computation claiming to be useful for C programs must handle aliasing.On the other hand, a slicer using this PDG to slice on the criterion “inputs of statement
c = f(b);” would be able to removed = 3;, which cannot influence the function call, even through the pointer access*p.Frama-C’s slicer uses the dependencies indicated by the PDG to keep only the statements that are useful for the user-specified slicing criterion. For instance, the command
frama-c -slice-wr c t.c -then-on 'Slicing export' -printproduces the reduced program below, where the assignment todhas been removed: