Best way of debigging a C extension

Christian Heimes lists at cheimes.de
Thu Dec 11 16:57:39 EST 2008


Paul Moore wrote:
> I have gdb (although I've hardly used it, but I can learn :-)) but if
> I try building my extension with python setup.py build --debug, I get
> an error because -lpython25_d does not exist. I'm not surprised by
> this, as I don't have a debug build of Python - but that should be OK,
> I'm only looking for debugging info from my code.

You have to build Python on your own to get debug builds. Only debug 
builds allow to do extension debugging like memory leak finding.

> I tried copying libpython25.a to libpython25_d.a - my extension now
> builds, but the resulting pyd is XXX_d.pyd, which won't import. If I
> rename this to XXX.pyd, I can import and things seem to work - but it
> seems a bit of a roundabout way of doing things. Is there a simpler
> way that I've missed? It seems to me that this (debugging a C
> extension without compiling a debug build of Python) would be a fairly
> common situation, so I would have expected a "cleaner" way of doing
> it.

You are working against the system ;)
On Windows all extensions and shared libraries of a debug build have a 
_d suffix.

> At the very least, a documentation patch to explain the best way of
> doing things might be useful. I'll see what I can put together based
> on the responses I get here.

http://svn.python.org/view/python/branches/release25-maint/PCbuild/readme.txt?rev=51333&view=auto

Christian




More information about the Python-list mailing list