3

Debugging IronPython In Visual Studio

Posted December 30th, 2008 in .Net, General, Microsoft, Python and tagged , , by ryan

I’ve been getting to know IronPython a little lately and one of the first things I wanted to know was how to debug IronPython in an IDE.  Since I use Visual Studio 2008 at work, I thought it would be a good start.  I searched Google and found a text representation of the steps involved over at Harry Pierson’s blog.

I found it pretty simple to do and somewhat useful for longer scripts.  It will be nice in the future to have first class support for IronPython in Visual Studio 2010.

You should have IronPython 2.0 Final and Visual Studio 2008 Professional or Better* installed to complete this demo.

Create a python file to debug:

1
2
3
4
5
6
7
8
#debug.py
class Foo:
def __init__(self, name=None):
    self.name = name
 
if __name__ == "__main__":
    f = Foo("LVS")
    print f.name

From Visual Studio, open the IronPython executable (ipy.exe). If it doesn’t do so for you, add the ipy.exe as an existing project.

From the Solution Explorer, right-click on Properties and set the Command Arguments property.  Use “-D” to tell ipy.exe to create debugging output, “-i” to start an interactive session at the end of debugging and add the full path to the script you made before.

Properties Dialog

Properties Dialog

Click Ok.

Open the script you created earlier in Visual Studio and place breakpoints as desired.

Adding a Breakpoint

Adding a Breakpoint

Run the script in debug mode (F5).

If you added the “-i” argument in step 3, after the last breakpoint is released it will launch an interactive session for you.  You will be able to inspect your script at this point, much like the immediate window in Visual Studio.

Interactive Console

Interactive Console

* I tried this in the Visual Studio 2008 Team Developer Edition and the Visual Studio Express Edition.  The Express Editions do not work as they don’t allow you to open the ipy.exe as a solution item. Sorry “hobbyists”, we’ll see if the Express sku’s of Visual Studio 2010 will target IronPython / IronRuby.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

3 Responses so far.

  1. Gavrie says:

    It might be possible to get this to work in Visual Studio Express using the method outlined here:

    http://stewartr.blogspot.com/2006/09/debugging-nunit-in-visual-studio.html

    It works fine for NUnit, although I haven’t tried it for IronPython.

  2. Paul says:

    The idea suggested by Gavrie does work in Express 2005.
    The lines I added to the .csproj file are:
    Program
    C:\IronPython-1.1.2\ipy.exe
    -D -i “C:\Documents and Settings\Paul\My Documents\Visual Studio 2005\Projects\IronPythonPlay\IronPythonPlay\debug.py”

    Obviously you’ll have to change the above to the location of your ipy.exe and the IronPython file your trying to edit.

  3. James says:

    Hi,

    I followed all your steps, but it doesn’t seem to work. Being new to visual studio I’m not sure what to do, it seems to load the necessary *.dll files and then produces the following line: “The program ‘[5212] ipy.exe: Managed’ has exited with code 1 (0×1)”. Any help would be greatly appreciated.

    James

Leave a Reply





FireStats icon Powered by FireStats