debugging python extension modules with MS vc++ 6.0

Dilton McGowan II diltonm at pacbell.net
Tue Oct 15 19:21:02 EDT 2002


"Jens Farmer" <jens.farmer at kodak.com> wrote in message
news:3DAC86D9.93AFEE62 at kodak.com...
> What's the easiest way to step into a python extension module written in
> C++?  This seems to be a trivial
> question but before you answer, let me describe what's going wrong.
>
> I've contributed to and written ~3 python extension modules.  My
> experience with writing extensions in
> C / C++ is therefore a bit limited but suffice it to say that I've had
> some moderate success.  (not once,
> not twice, but thrice...)  Apparently I'm such a good programmer that
> I've never had the need to debug
> these extension modules by actually stepping into them with the
> Microsoft IDE debugger.  ;)
>
> Fearing that I will not be so lucky in the future, I've decided to prove
> that I can indeed step into these
> thingies whenever it becomes necessary.  Here's what I've tried...
>
> 1  Build my extension module for debugging making sure to use the "debug
> multithreaded dll" runtime
>     libraries.  (same as used for the python22_d.dll and python22_d.exe
> targets)
> 2  Give my extension module a slightly different name than the non-debug
> version.  I've started using
>     the python convention of postpending "_d" to the module basename.
> 3  Make sure that the entrypoint to the dll (aka, initialization
> function) has the same "_d" postpend to
>     its name.
> 4  Link my extension to "python22_d.lib" instead of "python22.lib" so
> that I don't end up binding to
>     2 separate copies of the python interpretter.  (why does this happen
> when I attempt to resolve
>     my symbols through the non-debug version of python22.dll?)
> 5  Use the debug version of the python shell to import my extension.
> (ie., "python_d.exe")
>
> ....but it doesn't work!
>
> 1  The debug version of "python_d.exe" can't seem to find ANY
> extensions.  The PYTHONPATH
>     is unchanged between using the debug vs non-debug shells.  (Hint:  I
> can import sys and the
>     sys.path is exactly the same)
> 2  If I attempt to use the non-debug "python.exe" shell then the shell
> crashes with a version mismatch.
>     ...but at least it finds my debug extension before crashing!
>
>
> Is this some kind of initiation rite?  Is there a FAQ on the topic?
> (I've looked a bit and I can't seem
> to find it.)
>
>                                                                     Jens
>
> ps:  My favorite language?  .....aaaaaaaaaaahhhhhhhhh.
>

With the help of a very knowledgable co-worker, we managed to get this to
work successfully by setting the IDE Project Settings under "Executable for
debug session" to point to python_d.exe and "program arguments" to the DLL
extension.





More information about the Python-list mailing list