Re: [cython-users] Re: debug cython extension in windows 7

261 views
Skip to first unread message

Robert Bradshaw

unread,
Dec 10, 2012, 8:30:32 PM12/10/12
to cython...@googlegroups.com
I'm sure it's possible, but I haven't used Windows for so long I (nor
do I have access to a Windows machine) so wouldn't have a clue how. I
know there are plenty of other Cython Windows users out there,
hopefully one of them could give some advice.

On Mon, Dec 10, 2012 at 5:07 PM, martinako <martin...@gmail.com> wrote:
> I've tried many things to get this working but without success. The nearest
> I got is to debug the c code generated by cython, but that's not human
> readable (at least not this human) so it's not much use.
> I guess I have to accept that cython debugging under windows is not possible
> using cygdb.
>
>
> On Wednesday, 10 October 2012 12:21:47 UTC+1, martinako wrote:
>>
>> Hi,
>>
>> I posted this question in stackoverflow a few days ago but I'm not getting
>> any answer. I though to try again here.
>>
>> I'm trying to debug a cython extension module. I have been following the
>> instructions inhttp://docs.cython.org/src/userguide/debugging.html As I'm
>> using windows 7 I can't do a apt-get install to get a debug build of python
>> (as indicated in the userguide). So when I run cygdb I use python instead of
>> python-dbg
>>
>> Inside gdb (with python support, ie. gdb-python27.exe) I can set a break
>> point with cy break module.function and I can run the python script that
>> uses the pyd with cy run . However, execution doesn't stop at the set
>> breakpoint, and continues until it crashes (that's what I'm trying to debug)
>> producing a traceback If I do cy step or cy bt or cy list it complains with
>> "No frame is currently selected."
>>
>> Does anybody know what's going on? I suspect it maybe I need a python
>> build with debug symbols. If that's the case does anybody know where could I
>> download such a build for windows 7?
>>
>> Thanks

Ian Bell

unread,
Dec 11, 2012, 3:25:15 AM12/11/12
to cython...@googlegroups.com
Debugging on windows is really not super possible or easy.  God forbid you need matplotlib or numpy.  If you need numpy or matplotlib you basically must debug on linux since getting debug builds of numpy is nigh impossible as far as I can tell on windows.  It is possible to build your own debug version of Python on windows using the visual studio project ( I have had to do this before), and then go through the debugging.  Honestly, I found it easier to do everything on linux as you can

a) build your own debug version of python without too much pain
b) use virtualenv to create an environment for your python debug version so it doesn't mess up your paths
c) Use gdb with Eclipse to debug

To be fair this was when my extensions were SWIG wrappers, but all the same arguments apply with cython.

Best of luck.
Ian

mark florisson

unread,
Dec 11, 2012, 5:43:03 AM12/11/12
to cython...@googlegroups.com
On 10 October 2012 12:21, martinako <martin...@gmail.com> wrote:
> Hi,
>
> I posted this question in stackoverflow a few days ago but I'm not getting
> any answer. I though to try again here.
>
> I'm trying to debug a cython extension module. I have been following the
> instructions inhttp://docs.cython.org/src/userguide/debugging.html As I'm
> using windows 7 I can't do a apt-get install to get a debug build of python
> (as indicated in the userguide). So when I run cygdb I use python instead of
> python-dbg
>
> Inside gdb (with python support, ie. gdb-python27.exe) I can set a break
> point with cy break module.function and I can run the python script that
> uses the pyd with cy run . However, execution doesn't stop at the set
> breakpoint, and continues until it crashes (that's what I'm trying to debug)
> producing a traceback If I do cy step or cy bt or cy list it complains with
> "No frame is currently selected."

Yeah, that means it really cannot find any frame. Does the process
still have a stack?

cy break really uses gdb's 'break'. What does it say? Are you using
pending breakpoints? What about using gdb's break with the mangled C
symbol?

You're right in saying you need python with debug symbols, without is
pretty hard to debug, although you can still debug your Cython
extensions if they are compiled with debug support. cygdb was never
tested on Windows I'm afraid...

martinako

unread,
Dec 11, 2012, 8:03:14 AM12/11/12
to cython...@googlegroups.com

Thanks for your replies. I've had a go again taking into account your replies but still without success.

What I've tried:

I build python_d.exe (debug version in windows) using visual studio 2008 express. However, this has the problem that this interpreter would only import *_d.pyd and I'm using many libraries, including numpy and matplotlib, so I think it's infeasible to attempt to build them all as debug versions.


So what I tried instead is to build python.exe in Release mode but disable optimizations and make sure there is debug symbols for the compile and link steps. The idea was to use it with the rest of release libraries but as the interpreter itself has debug symbols I thought there maybe a better chance to work with cygdb.py. At the end I just renamed my python.exe and drop the new compiled exe dll pdbs libs on my python installation (I tried to create a new virtualenv for a debug version and duplicate my python setup using pip frezee and pip install, but install would be able to find many packages, I guess because they were originally installed with a windows installer rather than pip).


Then I run cygdb with a python script that loads a .pyd (build with debug symbols and no optimizations, but crucially no --debug because that generates a *_d.pyd). As in my initial post, I can put a breakpoint at a function that I call in the pyd and run the script that calls my pyd. This executes fine but gdb doesn't stop at the breakpoint. Finally, if I write backtrace, up, or down I get a "No stack".


This time I realised that when I set the break point with cy break or just break it complains the function is not defined. sorry I forgot about this message. The same message happens if I try to set a break point using the mangled C++ name of the function.


Don't know what else to do. For the moment I go by debugging with print statements. Maybe I'll try to install a linux distribution after xmas and see if how it goes with it.

mark florisson

unread,
Dec 11, 2012, 9:09:28 AM12/11/12
to cython...@googlegroups.com
You need to enable pending breakpoints, although IIRC cygdb does that.
Try 'set breakpoint pending on'.

martinako

unread,
Dec 11, 2012, 11:25:32 AM12/11/12
to cython...@googlegroups.com
I've just tried 'set breakpoint pending on' after setting a break point but it still doesn't stop at the breakpoint. 
Reply all
Reply to author
Forward
0 new messages