Debuggin a ptyhon extension
Mike Rovner
mike at nospam.com
Fri May 7 13:38:02 EDT 2004
Steve Menard wrote:
> I am writing a python extension module in VC++ on windows. At some
> point, my extension crashes.
Welcome to the club. :)
> Now I want to debug exactly why. I built the python projects in VC++,
> and put the resulting python_d.exe in my ptyon home directory, and the
> python23_d.dll in the windows/system32 directory. I also tried to put
> the python23_d.dll in python's home directory, to the same result.
>
> Problem is, running my scripts/extension with python_d.exe, it always
> complains it can't find win32api. Yes, I am using win32API to preload
> a dll, and can't really get rid of it.
>
> To try and solve this, I tried replacing the "stock" python.dll with
> my python_d, so at least VC++'s debugger would see the debug info.
> but I got the same result, of win32api not being found ...
"Everyone is getting lost to the measure of his abilities" (c)
You choosed the hard way.
> What is the best way to go about this? My extension will require a
> fair amount of native code and interacting with the Python code, so
> being able to trace into python would be invaluable.
Here what I did:
- Compile you _extension_ in debug mode. Name the output "myext.pyd".
- Call it with simple test script from dos (hopefully cmd) prompt: python
testmyext.py
import myext
stop=raw_input('connect now')
myext.run_crash_func()
-As script puses and prompt for input switch to VS and debug attach to
running process.
(Menu Tools/Debug Processes...; select your running python.exe and press
Attach)
Set appropriate breakpoints in your ext code. Continue.
-Switch to script and press Enter.
-Get breaked in C++ and enjoy debugging.
> Are my problems caused because python 2.3.3 (and possible win32all)
> were build using VC.net?
I use to debug my extensions with stock python (2.2.x & 2.3.x - both
compiled with MSVC6).
I use MSVC7.1. However I don't use FILE* between extension boundaries. No
problems so far.
> I am grateful for any help you guys can provide.
Hope this helps,
Mike
PS. If anybody is interested, there is a way to debug extension not leaving
VS at all:
In the extension solution properties set Debugging:
-Command (extenal program) python.exe
-Command Arguments: testmyext.py (or whatever your calling script is)
and just hit Run to debug your code.
More information about the Python-list
mailing list