Hello,

There currently is no proper debugger available to debug Cython code.
The current way we debug Cython code is:
- the print statement
- a C debugger
- pdb

None of the aforementioned methods is very powerful and time effective
at the same time. For instance, 'print' requires recompilation and is
not so powerful, pdb doesn't provide access to anything C-level and
gdb often requires a lot of digging through generated C code. This is
why I feel that there is a need to a proper Cython debugger.

This debugger should have, for starters, the following features:
- Cython variable/type/function name correspondence (the ability to
set breakpoints for Cython function/method names, the ability to
inspect variables by their Cython name (be it C or Python variables),
etc)
- A line number and source code correspondence with the Cython code
(ability to view the code at the C and Cython abstraction levels)
- Be able to inspect Python code, print python backtraces, etc
(there's already Misc/gdbinit in the Python source distribution and
there is the EasierPythonDebugging project)

Such a debugger would need some kind of information, namely it would need:
- a mapping from Cython line numbers to a range of C line numbers
- a mapping from Cython names to mangled C names
- naming information with regard to scope

My plan is to extend GDB with Python and introduce new Cython commands
that would deal with these issues. It would use the information
exported by the Cython compiler to realize this (the easiest and most
portable way would probably be to write it to a separate file in some
format (xml or json come to mind)).

So I have a few questions for cython-dev.
First of all, all the scope and naming information is in the AST, so I
think the easiest way would be to traverse the AST and generate a
similar tree where nodes contain information such as:
- C name
- Cython name
- Line number
- C object or Python object

I think this code could be called from the 'parse' closure in
Cython.Compiler.Main.create_parse() just before returning 'tree'. What
do you think?

The line number correspondence is a little harder, because I believe
that no code is currently saving Cython line number information when
generating C code. Seeing that CCodeWriter (and StringIOTree) have
these Insertion Points I think line number information would have to
be saved there, and all the code dealing with that would have to be
adjusted. Does that sound right or do you think there is an easier way
to implement this?

Another question is, if I would create a patch for Cython to have
Cython emit this kind of debugger information, would it be accepted if
accompanied by tests and according to the rules etc? I would be
willing to maintain the code at least. And what is your general
opinion of this debugger? What else would you see as an essential
feature of such a Cython debugger? And do you think the actual
debugger should be an external project or should it be part of Cython
(if it's mature)? I think the former option would allow a more
flexible release schedule.

Kind regards,

Mark
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to