首页 > 解决方案 > Clang Python 在解析一些 linux 文件时死机

问题描述

我正在使用 Clang Python 绑定自动解析源代码,但是当它解析一些 linux 文件时,进程死了,没有 CPU 消耗,没有错误异常,没有响应,甚至我无法使用 Ctrl+C 杀死终端。我的代码如下:

index = Index.create()
tu = index.parse(file_path)
next_func(tu)

它适用于许多源存储库,例如 Libpng、OpenCV 等。它如何在解析目录下的文件时死掉linux-master\drivers\gpu\drm\nouveau\nvkm\subdev\i2c,例如https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/anx9805.c. 我一步步运行代码,发现运行时出现错误tu = index.parse(file_path)

环境:Windows 10,libclang.dll(6.0) python2.7。

我尝试了命令clang -cc1 -fsyntax-only -ast-dump anx9805.c 它报告了一些头文件没有找到并构造它的 ast 如下:

In file included from \linux\linux-master\drivers\gpu\drm\nouveau\nvkm\subdev\i2c\anx9805.c:28:
In file included from \linux\linux-master\drivers\gpu\drm\nouveau\nvkm\subdev\i2c/bus.h:4: \linux\linux-master\drivers\gpu\drm\nouveau\nvkm\subdev\i2c/pad.h:4:10: fatal error: 'subdev/i2c.h' file not found
#include <subdev/i2c.h>
         ^~~~~~~~~~~~~~
TranslationUnitDecl 0x13de7f82728 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x13de7f82ca0 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
| `-BuiltinType 0x13de7f829c0 '__int128'
|-TypedefDecl 0x13de7f82d10 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
| `-BuiltinType 0x13de7f829e0 'unsigned __int128'
...
...

但是,进程能够结束,我不知道python中是否发生错误,为什么终端中的进程没有响应,try...except...在我的代码中没有捕获错误,甚至我无法杀死进程。允许忽略这些错误文件。最重要的是,我不希望代码运行中断。

标签: pythoncclangclang++

解决方案


推荐阅读