eliben / pycparser

:snake: Complete C99 parser in pure Python
Other
3.24k stars 609 forks source link

pycparser.plyparser.ParseError: xx/include/vadefs.h:24:28: before: __gnuc_va_list #511

Closed yuedong111 closed 1 year ago

yuedong111 commented 1 year ago

i recevie the error when i ran the script in the example/using_cpp_libc.py.I traced it back to the corresponding .h file, and found that the error occurred when parsing this line of code: typedef builtin_va_list gnuc_va_list; how to solve that?

mei-g commented 1 year ago

Had similar issue when running the pycparser pycparser.parse_file('xxx.c') against kernel code. Got the following: pycparser.plyparser.ParseError: xxx/kernel-source/include/linux/stdarg.h:5:27: before: va_list

It seems like it doesn't recognize gcc built-in symbols eg, char ... I have used the fake include headers. Got the same result. Can someone please help?

eliben commented 1 year ago

pycparser definitely recognizes char

Please carefully read https://github.com/eliben/pycparser#3using and the blog post linked there, and also the FAQ https://github.com/eliben/pycparser/wiki/FAQ

If the issue remains unclear, please create a minimal reproducible example https://stackoverflow.com/help/minimal-reproducible-example

mei-g commented 1 year ago

It is hard provide a minimal example. However if you can manage a linux kernel build and pre-compile any C file and run pycparser againt the pre-compiled output. It will report error straight away.

eliben commented 1 year ago

If you cannot provide a minimal example, unfortunately there's not a whole lot I can do.

Parsing real large projects with pycparser often takes some work (Real-world example section in https://eli.thegreenplace.net/2015/on-parsing-c-type-declarations-and-fake-headers), and the Linux kernel in particular is challenging - since it uses many GNU extensions AFAIK.

This is not expected to just work out of the box.