arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2103.00587cs.PLcs.SE
收藏

PyCG:Python中的实用调用图生成

PyCG: Practical Call Graph Generation in Python

Vitalis Salis, Thodoris Sotiropoulos, Panos Louridas, Diomidis Spinellis, Dimitris Mitropoulos

摘要:

调用图在不同的环境中发挥着重要作用,例如分析和漏洞传播分析。当涉及到模块化并包含动态特性和高阶函数的高级语言时,以有效的方式生成调用图可能是一项具有挑战性的任务。尽管这种语言很受欢迎,但很少有工具旨在为Python程序生成调用图。更糟糕的是,这些工具存在一些有效性问题,限制了它们在实际程序中的实用性。我们提出了一个实用的,静态的方法在Python中的调用图生成。我们计算所有的程序标识符的函数,变量,类和模块之间的分配关系,通过一个过程间的分析。基于这些分配关系,我们产生的调用图,解决所有潜在的调用函数的调用。值得注意的是,底层分析被设计为高效和可扩展的,处理几个Python功能,如模块,生成器,函数闭包和多重继承。我们已经评估了我们的原型实现,我们称之为PyCG,使用两个基准测试:一个包含小型Python程序的微基准测试套件和一组包含几个流行的真实Python包的宏基准测试。我们的研究结果表明,PyCG可以在不到一秒的时间内有效地处理数千行代码(1 k LoC平均为0.38秒)。此外,它在精度和召回率方面都优于Python的最新技术:PyCG实现了高精度~ 99.2%,足够的召回率~ 69.9%。最后,我们展示了PyCG如何通过使用真实世界的示例展示对GitHub的“安全咨询”通知服务的潜在增强来帮助依赖影响分析。

英文摘要:

Call graphs play an important role in different contexts, such as profiling and vulnerability propagation analysis. Generating call graphs in an efficient manner can be a challenging task when it comes to high-level languages that are modular and incorporate dynamic features and higher-order functions. Despite the language's popularity, there have been very few tools aiming to generate call graphs for Python programs. Worse, these tools suffer from several effectiveness issues that limit their practicality in realistic programs. We propose a pragmatic, static approach for call graph generation in Python. We compute all assignment relations between program identifiers of functions, variables, classes, and modules through an inter-procedural analysis. Based on these assignment relations, we produce the resulting call graph by resolving all calls to potentially invoked functions. Notably, the underlying analysis is designed to be efficient and scalable, handling several Python features, such as modules, generators, function closures, and multiple inheritance. We have evaluated our prototype implementation, which we call PyCG, using two benchmarks: a micro-benchmark suite containing small Python programs and a set of macro-benchmarks with several popular real-world Python packages. Our results indicate that PyCG can efficiently handle thousands of lines of code in less than a second (0.38 seconds for 1k LoC on average). Further, it outperforms the state-of-the-art for Python in both precision and recall: PyCG achieves high rates of precision ~99.2%, and adequate recall ~69.9%. Finally, we demonstrate how PyCG can aid dependency impact analysis by showcasing a potential enhancement to GitHub's "security advisory" notification service using a real-world example.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑