python - 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...
在我的代码中没有捕获错误,甚至我无法杀死进程。允许忽略这些错误文件。最重要的是,我不希望代码运行中断。
解决方案
推荐阅读
- c++ - 定时器是从另一个线程启动的吗?
- c++ - C++ 2D 数组索引比较
- vulkan - 归一化、缩放和整数 VkFormats 有什么区别?
- android - 自定义对话框扩展对话框不通过 onCreate 呈现布局被执行
- c - futex 手册页演示结果不正确
- javascript - Vue-router嵌套路由未加载我的组件页面
- c# - 将 Linq 结果转换为 CSV
- git - 需要集中式系统中不可能的工作流示例,例如分层模型
- visual-studio-code - VSCode:获取语言服务器中的编辑器内容
- r - 是否有一种最佳方法可以使用 data.table 创建一堆新列?