从ANSI C代码获取控制流图 [英] Getting Control Flow Graph from ANSI C code

查看:190
本文介绍了从ANSI C代码获取控制流图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建测试ansi c应用程序的工具。只需加载代码,查看控制流程图,运行测试,标记所有命中的顶点。我试图通过解析代码自己构建CFG。不幸的是,如果代码被嵌套,它会变得混乱。 GCC提供从编译代码获取CFG的能力。我可能会为其输出编写解析器,但我需要行号来设置断点。用 -fdump-tree-cfg -fdump-tree-vcg lineno 选项添加到其中一个选项即可。因此,使用 -fdump-tree-cfg-lineno -fdump-tree-vcg-lineno 。我花了一些时间来检查这些数字是否可靠。在 VCG 格式的图形中,每个节点的标签都包含两个数字。这些是由该节点代表的代码开始和结束的行号。


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?

解决方案

So I've made some more research and it is not hard to get line numbers for nodes. Just add lineno option to one of those options to get it. So use -fdump-tree-cfg-lineno or -fdump-tree-vcg-lineno. It took me some time to check if those numbers are reliable. In case of graph in VCG format label of each node contains two numbers. Those are line numbers for start and end of code portion represented by this node.

这篇关于从ANSI C代码获取控制流图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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