Best way of debigging a C extension

Diez B. Roggisch deets at nospam.web.de
Thu Dec 11 17:52:23 EST 2008


Paul Moore schrieb:
> I'm writing a C extension. My environment is Python 2.5, with the
> mingw compiler, on Windows XP. At the moment I'm debugging by
> scattering printf() statements around, but it's not always easy. Is
> there a better way of debugging - particularly for diagnosing crashes?
> 
> 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.
> 
> 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.
> 
> 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.

I never tried this on windows - but what happens if you start python 
inside GDB, and then set breakpoints inside your extension?

This works flawlessly for me under *nix.

The debug-build of python isn't needed for this - and I doubt a bit that 
it helps you much, as being inside the interpreter & getting detailed 
information isn't your goal - you want to see your extensions functions, 
what parameters they get and so on.


Diez



More information about the Python-list mailing list