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:
And these are just the ones I have used or am aware of. I often think that what proponents of static languages mean by "the tools aren't available" is really "I want to use Visual Studio". This is just me being cynical though.

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:
Adding JMC support makes ipydbg significantly more usable. It’s almost like a real tool now, isn’t it?

Comments

Popular posts from this blog

Extending Abobe Flash Player and AIR with Python and Ruby

Should Python Projects Support IronPython and Jython?

Further Adventures of the Debugger