一句话:提出 LExecutor,用神经网络预测缺失值并注入执行,使不完整代码片段也能运行。
执行任意代码对错误检测和动态分析至关重要,但常因变量未定义、缺少用户输入或第三方依赖而失败。LExecutor 提出一种学习引导的欠约束执行方法:让神经模型预测会导致程序卡住的缺失值,并将其注入执行,例如为未定义变量和缺失函数调用注入可能的值。作者在流行开源 Python 项目和 Stack Overflow 代码片段上评估,模型预测真实值的准确率为 79.5%–98.2%,能较好模拟真实执行;最终成功执行代码的覆盖率达 51.6%,远高于直接执行时的 4.1%。
Executing code is essential for various program analysis tasks, e.g., to detect bugs that manifest through exceptions or to obtain execution traces for further dynamic analysis. How- ever, executing an arbitrary piece of code is often difficult in practice, e.g., because of missing variable definitions, miss- ing user inputs, and missing third-party dependencies. This paper presents LExecutor, a learning-guided approach for executing arbitrary code snippets in an underconstrained way. The key idea is to let a neural model predict missing values that otherwise would cause the program to get stuck, and to inject these values into the execution. For example, LExecutor injects likely values for otherwise undefined vari- ables and likely return values of calls to otherwise missing functions. We evaluate the approach on Python code from popular open-source projects and on code snippets extracted from Stack Overflow. The neural model predicts realistic values with an accuracy between 79.5% and 98.2%, allowing LExecutor to closely mimic real executions. As a result, the approach successfully executes significantly more code than any available technique, such as simply executing the code as-is. For example, executing the open-source code snippets as-is covers only 4.1% of all lines, because the code crashes early on, whereas LExecutor achieves a coverage of 51.6%.