该免费工具,我可以用它来生成C codeS的程序依赖图 [英] which free tools can I use to generate the program dependence graph for c codes

查看:1030
本文介绍了该免费工具,我可以用它来生成C codeS的程序依赖图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要生成C源$ C ​​$ C程序依赖图(PDG)。我发现,解释如何做到这一点的论文,但所有应用的商业codeSurfer工具。

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?

推荐答案

邮资-C是切片器对于基于程序依赖图的计算C程序。

Frama-C is an Open Source static analysis platform with a slicer for C programs based on the computation of a Program Dependence Graph.

需要注意的是切片写在一个真正的编程语言实际的程序,如C涉及到许多特殊的情况,而且在科学出版物掠过概念。不过,我相信,你不会找到比邮资-C的PDG计算任何简单,首先是因为它是唯一的开源一个可用(据我所知),二是因为处理的C程序的任何其他PDG计算将有解决同样的问题,并介绍了同样的概念。

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.

下面是一个例子:

int a, b, d, *p;

int f (int x) {
  return a + x;
}

int main (int c, char **v) {
  p = &b;
  a = 1;
  *p = 2;
  d = 3;
  c = f(b);
}

命令邮资-C -pdg -dot-PDG图-pdg打印TC 生成点文件 graph.main.dot graph.f.dot 包含的main()和 F()分别。

The command frama-c -pdg -dot-pdg graph -pdg-print t.c generates dot files graph.main.dot and graph.f.dot containing the PDG of main() and f() respectively.

您可以使用程序pretty打印其中之一这样的:点-Tpdf graph.main.dot> graph.pdf

You can use the dot program to pretty-print one of them thus: dot -Tpdf graph.main.dot > graph.pdf

的结果是如下:

请注意从节点边缘C = F(B); 的节点 * P = 2; 。一个PDG计算自称是有益的C程序必须处理走样。

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.

在另一方面,使用这种PDG切片的标准切片器语句的输入 C = F(B); 将能够删除 D = 3; ,它不能影响函数调用,甚至通过指针访问 * p
邮资-C的切片机使用由该PDG指示保持仅是为用户指定的切片准则有用的发言的依赖关系。例如,命令邮资-C -slice-WR的温度系数 - 那么,在切片出口'-print 产生下面的程序减少,其中分配给 D 已被删除:

On the other hand, a slicer using this PDG to slice on the criterion "inputs of statement c = f(b);" would be able to remove d = 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' -print produces the reduced program below, where the assignment to d has been removed:

/* Generated by Frama-C */
int a;
int b;
int *p;
int f_slice_1(int x)
{
  int __retres;
  __retres = a + x;
  return (__retres);
}

void main(int c)
{
  p = & b;
  a = 1;
  *p = 2;
  c = f_slice_1(b);
  return;
}

这篇关于该免费工具,我可以用它来生成C codeS的程序依赖图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆