0

I created fake header files under pycparser/utils/fake_libc_include for every header found in kernel/sched/core.c and put

#include "_fake_defines.h"
#include "_fake_typedefs.h"

into them. A few other header files where missing, lot's of headers from kernel/sched/sched.h for example. So I added them too.

Preprocessed the whole stuff with

gcc -nostdinc -E -Ipycparser/utils/fake_libc_include ../kernel/sched/core.c > core_pp.c

which gave no error.

So I tried to get the function names

python3 examples/func_defs.py core_pp.c

but it gives me the error:

Traceback (most recent call last):
  File "examples/func_defs.py", line 46, in <module>
    show_func_defs(filename)
  File "examples/func_defs.py", line 34, in show_func_defs
    cpp_args=r'-Iutils/fake_libc_include')
  File "/usr/local/lib/python3.4/dist-packages/pycparser/__init__.py", line 93, in parse_file
    return parser.parse(text, filename)
  File "/usr/local/lib/python3.4/dist-packages/pycparser/c_parser.py", line 151, in parse
    debug=debuglevel)
  File "/usr/local/lib/python3.4/dist-packages/pycparser/ply/yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/usr/local/lib/python3.4/dist-packages/pycparser/ply/yacc.py", line 1181, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/usr/local/lib/python3.4/dist-packages/pycparser/ply/yacc.py", line 193, in call_errorfunc
    r = errorfunc(token)
  File "/usr/local/lib/python3.4/dist-packages/pycparser/c_parser.py", line 1721, in p_error
    column=self.clex.find_tok_column(p)))
  File "/usr/local/lib/python3.4/dist-packages/pycparser/plyparser.py", line 55, in _parse_error
    raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: ../kernel/sched/cpupri.h:14:2: before: atomic_t

What am I doing wrong? I've tried the redis example from this blog entry and it worked.

JohnnyFromBF
  • 9,873
  • 10
  • 45
  • 59

1 Answers1

0

Adding the headers is just one part of the solution - this helps the preprocessor resolve the #include statements.

The other part of the solution is adding types that the parser would expect to find there to _fake_typedefs. This way pycparser will know the identified is a type and will be able to parse the code properly.

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412