Debugging python with C++ extensions

Dave Kuhlman dkuhlman at rexx.com
Mon Nov 18 17:16:35 EST 2002


Karl G. Merkley wrote:

> 
> I am looking using python as a framework for some C++ components.
> However, I am concerned about debugging across the python/C++ interface.
> How do people currently debug python with C++ extensions.  Every C++
> component will have it's own unit test; however, it seems inevitable that
> there will be times when it would be helpful to step from the python
> code into the C++ component.

Here is a technique that I've used:

Put a call to raw_input('Press Enter to continue') in your Python code 
before the point at which it executes the C/C++ code you want to debug.

Then, when it stops, go to another command line window (e.g. bash on Linux) 
and attach the debugger to the task.

On Linux I use:

    gdb python <pid>

You can find the process ID by doing:

    ps -ef | grep python

On Windows if I recall correctly (it's been a while for me), look the PID up 
in the process manager, then (with MS Visual C++), use:

    msdev -p <pid>

Then set a breakpoint and continue.

  - Dave

-- 
Dave Kuhlman
dkuhlman at rexx.com
http://www.rexx.com/~dkuhlman



More information about the Python-list mailing list