APP下载

大规模可变C代码增量式分析方法

2021-08-17石剑君刘法旺计卫星杨玚

软件 2021年3期

石剑君 刘法旺 计卫星 杨玚

摘 要:提出一种基于头文件复用的大规模可变C代码增量式分析方法。以Linux内核代码为例,首先统计和分析了大规模C代码中的头文件包含情况。然后根据头文件包含顺序,构建C代码分析的头文件加载树。最后,按照头文件加载树增量地分析C代码。实验结果表明,与原有的代码分析方法相比,本方法可以极大地提升大规模可变C代码分析的效率。

关键词:大规模C代码;可变代码;代码分析

中图分类号:V211 文献标识码:A DOI:10.3969/j.issn.1003-6970.2021.03.023

本文著录格式:石剑君,刘法旺,计卫星,等.大规模可变C代码增量式分析方法[J].软件,2021,42(03):079-085

Incremental Parsing Method for Large-scale Variable C Source Code

SHI Jianjun1, LIU Fawang2, JI Weixing1, YANG Yang3

(1.School of Computer Science, Beijing Institute of Technology, Beijing  100081;

2.Ministry of Industry and Information Technology Equipment Industry Development Center, Beijing  100846;

3.China Software Testing Center, Beijing  100086)

【Abstract】:An incremental code parsing technique for large-scale variable C source code is proposed. Taking the Linux kernel source code as an example, firstly, we summarize and analyze the included header files in large-scale C source code. Then, header file loading trees are built according to the inclusion order of header files. Finally, the C source code is parsed incrementally based on the header file loading trees. The experimental results show that compared with the traditioanl code parsing methods, our method can greatly improve the efficiency of large-scale variable C source code parsing.

【Key words】:large-scale C source code;variable code;code parsing

目前,大規模C程序已广泛存在于实际生产实践中,例如,Linux 内核、Apache HTTP Server和Mozilla Firefox等程序的代码规模已超过百万行,甚至达到几千万行。相比于普通程序,大规模C程序的开发、管理和维护都变得更加困难。

为了对程序进行优化,自动发现程序中存在的潜在问题,研究人员提出了静态分析和动态分析等程序分析技术[1-2]。静态程序分析是程序分析中一种有效的技术手段,它主要指在不运行程序的情况下,从源代码中提取程序的结构化信息,再进行进一步分析和处理。通过静态程序分析,开发人员可以在开发阶段即可发现代码中存在的潜在问题,从而实现代码优化、缺陷检测和修复,提升程序开发的效率。静态程序分析通常需要借助于编译器前端工具解析源代码,首先通过预处理、词法分析和语法分析等步骤,从源代码或者中间代码中提取出抽象语法树、函数调用图和控制流图等,再利用抽象解释[3]、数据流分析[4]和符号执行[5]等方法对源代码进行分析。……

登录APP查看全文