Writing an IronPython Debugger
One of the things that programmers in static languages complain about working with dynamic languages is the lack of tools. Many of them are unaware of the tools that are available for languages like Python:
For IronPython the story is genuinely not so good. IronPython doesn't have Python stack frames; a performance optimisation that reduces the function calling overhead which is very high in the C implementation of Python (CPython). Unfortunately this means that core APIs in the sys module, particularly settrace and setprofile, are unavailable in IronPython.
You can use both IronPython Studio and Visual Studio to debug IronPython code, but the 'traditional Python tools' for debugging and profiling don't work. Because IronPython classes, objects and scopes have a different representation to .NET objects created in C# or VB.NET the debugging experience even in Visual Studio is not as good as it could be (although still useful).
The good news is that Dino Veihland (core developer) says that Python stack frames, along with sys.settrace and at least some of its friends, will be coming to IronPython soon. As there is a performance cost (~10% in general Dino estimates) it will be optional, but you will be able to enable it when you need debugging support or for compatibility reasons.
In the meantime, Harry Pierson (Microsoft PM for IronPython) has been experimenting with creating a custom debugger for IronPython built on top of the .NET debugging tools and APIs. He is basing his work on the .NET command line debugger MDbg for which the sourcecode is available. He has also had some assistance from Mike Stall, something of a guru in .NET debugging.
One of Harry's goals with ipydbg, is to make it Just My Code aware so that he can usefully set breakpoints step through Python code and skip all the uninteresting DLR stack frames that exist when IronPython is executing. He has made good progress (which you can download and try for yourself of course), and these blog entries chart what he has done and still has left to do:
- A plethora of Python IDEs and editors exist; with good support for syntax highlighting, autocomplete (intellisense), call-tips and all the features you expect from an IDE. Good ones include:
- Wingware Wing IDE (which includes a very powerful debugger)
- Activestate Komodo IDE
- Eclipse with PyDev
- Stani's Python Editor (free with integrated debugger)
- Netbeans and Python
- Many more including the old warhorses Emacs and Vim; beloved as lightweight companions to lightweight languages (and easy to integrate with the other tools listed here)
- Code coverage tools: coverage.py
- The debugger included with Python: pdb
- The profiling tools included with Python: profile library
- Refactoring tools: rope, Bicycle Repair Man
- Code quality tools: PyFlakes (fast), pylint (comprehensive), pychecker (in between)
- Measuring complexity: Python cyclomatic
- As for test frameworks and mocking libraries: take your pick!
For IronPython the story is genuinely not so good. IronPython doesn't have Python stack frames; a performance optimisation that reduces the function calling overhead which is very high in the C implementation of Python (CPython). Unfortunately this means that core APIs in the sys module, particularly settrace and setprofile, are unavailable in IronPython.
You can use both IronPython Studio and Visual Studio to debug IronPython code, but the 'traditional Python tools' for debugging and profiling don't work. Because IronPython classes, objects and scopes have a different representation to .NET objects created in C# or VB.NET the debugging experience even in Visual Studio is not as good as it could be (although still useful).
The good news is that Dino Veihland (core developer) says that Python stack frames, along with sys.settrace and at least some of its friends, will be coming to IronPython soon. As there is a performance cost (~10% in general Dino estimates) it will be optional, but you will be able to enable it when you need debugging support or for compatibility reasons.
In the meantime, Harry Pierson (Microsoft PM for IronPython) has been experimenting with creating a custom debugger for IronPython built on top of the .NET debugging tools and APIs. He is basing his work on the .NET command line debugger MDbg for which the sourcecode is available. He has also had some assistance from Mike Stall, something of a guru in .NET debugging.
One of Harry's goals with ipydbg, is to make it Just My Code aware so that he can usefully set breakpoints step through Python code and skip all the uninteresting DLR stack frames that exist when IronPython is executing. He has made good progress (which you can download and try for yourself of course), and these blog entries chart what he has done and still has left to do:
- Writing an IronPython Debugger: Introduction
- MDbg 101
- Hello, Debugger!
- Setting a Breakpoint
- Adding Interactivity
- Dynamic Stack Trace
- devhawk_ipy (the downloads!)
- Refactoring
- Stepping Thru Code
- Debugging Just My Code (JMC)
Adding JMC support makes ipydbg significantly more usable. It’s almost like a real tool now, isn’t it?
Comments
Post a Comment