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

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

问题描述

我正在构建用于测试 ansi c 应用程序的工具.只需加载代码,查看控制流图,运行测试,标记所有被命中的顶点.我正在尝试通过解析代码自己构建 CFG.不幸的是,如果代码是嵌套的,它就会变得一团糟.GCC 提供了从编译代码中获取 CFG 的能力.我可能会为其输出编写解析器,但我需要行号来设置断点.使用 -fdump-tree-cfg-fdump-tree-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?

推荐答案

所以我做了更多的研究,获得节点的行号并不难.只需将 lineno 选项添加到这些选项之一即可获得它.所以使用 -fdump-tree-cfg-lineno-fdump-tree-vcg-lineno.我花了一些时间来检查这些数字是否可靠.在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天全站免登陆