Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用 clang 提取头文件中的结构体定义信息 #34

Open
yunwei37 opened this issue Feb 1, 2023 · 1 comment
Open

用 clang 提取头文件中的结构体定义信息 #34

yunwei37 opened this issue Feb 1, 2023 · 1 comment

Comments

@yunwei37
Copy link

yunwei37 commented Feb 1, 2023

增加struct2json 结构体与JSON转换代码自动生成的Python脚本,支持从头文件中提取结构体定义,并根据结构体定义自动生成结构体与JSON互转代码,并提供相关示例。

我看这个好像是使用正则表达式完成的信息提取? 我最近也碰到了类似的需求,但是是用 clang 生成 btf 信息之后实现代码生成的;

https://github.com/eunomia-bpf/c-struct-bindgen

有没有想过使用 clang 导出 ast 和 debug 信息,或者 btf 信息,来做这样的事情? (btf 也可以理解成 debug 信息的一种,通过 clang -target bpf -g 即可生成,可以用 libbpf 解析获取结构体定义,类型和字段之类的)

@armink
Copy link
Owner

armink commented Feb 1, 2023

好想法,通过 ast 和 debug 信息来做这个事情就更加简单了,还有一些目前 struct2json 不支持的功能,比如结构体成员是子结构体或者结构体数组都可以被实现了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants