fa.bianp.net

Flags to debug python C extensions.

Category: General

I often find myself debugging python C extensions from gdb, but usually some variables are hidden because aggressive optimizations that distutils sets by default. What I did not know, is that you can prevent those optimizations by passing flags -O0 -fno-inline to gcc in keyword extra_compile_args (note: this will only work in GCC). A complete example would look like:

config.add_extension('foo',
    sources=['a.c'], # add this for gdb debug
    extra_compile_args=['-O0 -fno-inline'])

and it becomes much easier to debug from gdb.