Saturday, June 23, 2012

Debugging Cython

The documentation posted for debugging Cython appears to be out of date. To setup Cython to generate GDB debugging symbols, you need to use the --debug-gcc parameter, which will add the extra -g2 parameter during compiles.

~/projects/lxml-2.3.3$ python setup.py build_ext --debug-gcc --inplace --cython-gdb
~/projects/lxml-2.3.3$ make
Make sure that core dumps are enabled:

~/projects/yourproject$ ulimit -c unlimited # unlimited core size dumps, set to 0 by default so no dumps

You should now run your Python script that uses the shared object (.so) file. If your Python script dumps a core file, you can then use gdb by using "gdb python core":
$ gdb python core
Program terminated with signal 11, Segmentation fault.
#0  0x00007f0c1f02203b in __pyx_module_cleanup (self=, unused=) at src/lxml/lxml.etree.c:180630
180630   Py_DECREF((PyObject *)__pyx_v_4lxml_5etree___findStylesheetByID); __pyx_v_4lxml_5etree___findStylesheetByID = 0;

You can go up the call stack and see that it's my code changes that causes the problem:

Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `python ba.py'.
Program terminated with signal 6, Aborted.
#0  0x00007f886e25c445 in raise () from /lib/x86_64-linux-gnu/libc.so.6

#4  0x00007f886d8a3d84 in __pyx_f_4lxml_5etree__tofilelikeC14N (__pyx_v_f=, __pyx_v_exclusive=1, __pyx_v_with_comments=0, __pyx_v_compression=0, 
    __pyx_v_inclusive_ns_prefixes=, __pyx_v_element=) at src/lxml/lxml.etree.c:102124
102124     PyMem_Free(__pyx_v_c_inclusive_ns_prefixes);

No comments:

Post a Comment