Debugging Cython code

48 views
Skip to first unread message

Raniere Gaia Silva

unread,
Nov 12, 2012, 1:26:37 PM11/12/12
to sage-...@googlegroups.com
Hi,
how is the easy way to debug a Cython code?

Thanks,
Raniere

Jason Grout

unread,
Nov 12, 2012, 3:08:04 PM11/12/12
to sage-...@googlegroups.com
On 11/12/12 12:26 PM, Raniere Gaia Silva wrote:
> Hi,
> how is the easy way to debug a Cython code?

I insert print statements, think really hard, insert more print
statements, etc.

I think you can also use gdb; it seems I've done it once before, at least.

Thanks,

Jason


Robert Bradshaw

unread,
Nov 12, 2012, 3:29:40 PM11/12/12
to sage-...@googlegroups.com
On Mon, Nov 12, 2012 at 12:08 PM, Jason Grout
<jason...@creativetrax.com> wrote:
> On 11/12/12 12:26 PM, Raniere Gaia Silva wrote:
>>
>> Hi,
>> how is the easy way to debug a Cython code?
>
>
> I insert print statements, think really hard, insert more print statements,
> etc.

This is what I typically do.

> I think you can also use gdb; it seems I've done it once before, at least.

See http://wiki.cython.org/DebuggingTechniques and
http://docs.cython.org/src/userguide/debugging.html too.

- Robert

Nils Bruin

unread,
Nov 12, 2012, 3:33:45 PM11/12/12
to sage-devel
On Nov 12, 12:08 pm, Jason Grout <jason-s...@creativetrax.com> wrote:
> I think you can also use gdb; it seems I've done it once before, at least.

I have used gdb for stack examination after a segfault. For "C-like"
pieces of Cython it works quite well. For "Python-like" pieces it's
horrible, because python objects are virtually impossible to
investigate with gdb (i.e., C-level). There is the added problem that
gdb will happily give you the source context, but that will refer to
the C that cython produced, not the original ".pyx". That means you
have to deal with mangled identifier names too (which isn't too bad
for C-like cython, which allows an almost 1-1 translation to C).

A thing that would make gdb-debugging of cython immensely more useful
would be if one could set breakpoints in a sensible way. I haven't
used it, but gdb allows setting breakpoints by filename and
linenumber. Those would be ".c" filename and linenumber, though. If we
could somehow have a convenient translation tool from ".pyx" filename
+linenumber to ".c" filename+linenumber, setting breakpoints would be
much more doable. Is this something the cython people have thought
about? Does this need a "cydb" wrapper around gdb or does gdb have its
own customization options that allow something along these lines?

People tend to say that debuggers provide a more efficient
investigation tool than print-and-recompile, but I doubt this is
presently true for cython. Perhaps this can be improved?

Nils Bruin

unread,
Nov 12, 2012, 3:37:03 PM11/12/12
to sage-devel
On Nov 12, 12:33 pm, Nils Bruin <nbr...@sfu.ca> wrote:
> Does this need a "cydb" wrapper around gdb or does gdb have its
> own customization options that allow something along these lines?

I should have googled before I replied:

http://docs.cython.org/src/userguide/debugging.html

It would be great if someone would check and report if and how this
can be used for sage and if it works well.

Raniere Gaia Silva

unread,
Nov 13, 2012, 6:12:54 AM11/13/12
to sage-...@googlegroups.com
Thanks for all the reply.

I hope that anyone know a good way to debug cython "Python-like" code
without using insert print statements.

> I should have googled before I replied:
>
> http://docs.cython.org/src/userguide/debugging.html

Before I post the question I had take a look it the link above but
have not succeeded.

Best regards,
Raniere
Reply all
Reply to author
Forward
0 new messages