基于Clang编译器的程序结构分析器设计
2016-11-30周睿
周睿
摘 要: 国内的软件测试研究目前还基本停留在比较基础的理论方法和管理方法上,没有在软件测试技术上取得突破。基于当前流行的Clang编译器前端,在抽象语法树生成的过程中运用不同的规则标识各语句结构,同时进行中间结构的改造和校正,得到一个有效的、高正确性的程序结构分析器。程序结构分析器的设计为实现一个有理论基础的综合性白盒测试工具奠定了坚实的底层数据支持。
关键词: Clang编译器; 抽象语法树; 程序结构分析; 软件测试
中图分类号:TP311.1 文献标志码:A 文章编号:1006-8228(2016)10-54-03
Design of program structure analyzer based on Clang compiler
Zhou Rui
(Shaanxi institute of technology, Xi'an, Shaanxi 710300, China)
Abstract: At present, the research of software testing in China is still in the basic stage of theoretical methods and management methods, and it has not made any breakthrough in the software testing technology. Based on the front end of current popular Clang compiler, using different rules to identify the structure of statement in the abstract syntax tree generation process, and to carry out the reform and correction of the intermediate structure, an effective program structure analyzer with high accuracy is obtained. The design of program structure analyzer lays a solid underlying data support for realizing a theory based comprehensive white box testing tool.
Key words: Clang compiler; abstract syntax tree; program structure analysis; software testing
0 引言
程序结构分析器的实现离不开一个高效的编译前端作支持,而编译技术到目前为止在各领域得到了广泛的应用。从银行的管理软件到高性能计算,大多数都是高级语言进行编写完成,然后通过静态或动态编译最终在计算机上运用。目前比较流行的编译器是在Apple上使用的LLVM/Clang编译器、由GNU开发的程序语言编译器GCC用于Linux系统下编程、IBM公司研制开发的Java编译器Jikes、Inter公司开发的Open Research Compile,还有常见的MSVC、Borland c、myeclipse和jbuilder等等[3-4]。
程序中的缺陷检测是编译器的一项重要任务,也是目前研究的热点和探讨的核心问题。要识别各种错误包括:变量未定义、类型检验、语义错误以及内存泄漏和违规等,就必须在程序分析方面投入更多精力进行设计研究。在保证可靠性和安全性的同时也要减少分析工具的误报,从而避免给程序员带来不必要的麻烦,节约时间,提高效率。因此,编译器技术中静态或动态的程序分析对识别程序中的错误和缺陷有着重要的作用,不过现在面临的问题还不少,出现了许多新的挑战[5]。……
