SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Matt Ward

Debugging IronPython Code in SharpDevelop

With SharpDevelop 3.1 you can now debug IronPython code with the IronPython Interpreter (ipy.exe).

Before you start make sure the debugger is set to use the Just My Code feature. From the Tools menu select Options and then click the Debugging category.

Debugger options for debugging IronPython code

Ensure that the Just My Code feature is checked and that the Step over code without symbols is not checked. If the Step over code without symbols option is selected then stepping will not work properly and lines of code will be skipped over.

There are two ways to debug your code. You can use the Python menu or modify the project options. We will look at both of these alternatives. First open your IronPython project into SharpDevelop. Open your main file and make sure it is the active text editor window. Set a breakpoint somewhere in your code. Then from the Python menu select Run.

Python menu option to run with debugger

This will start ipy.exe which will run your code and the debugger should stop the execution at the breakpoint.

Debugging IronPython code

From this point you can do the usual debugging activities such as stepping through your code, viewing the callstack, adding items to the watch window, etc.

If you want to use a different ipy.exe then this can be specified in the Python Options dialog (Tools menu | Options).

Python options dialog

To enable debugging when you press F5 or select the Debug Run menu option you can modify the project options. From the Projects menu select Project Options and then open the Debug tab. Here you should change the Start Action to Start external program and use the browse button to locate ipy.exe. In the Start Options add the following command line arguments, changing the name of your main file as required.

-D ${ProjectDir}\Program.py

Once these changes are saved you can then press F5 and ipy.exe will be run under the debugger instead of running the compiled executable.3

Issues

  • No support for debugging the executable produced by the IronPython compiler since it does not produce debug symbols (i.e. .pdb files).
  • When using ipy.exe you need to add references to .NET assemblies explicitly in your code except for System which is included by default. For example:
    import clr 
    clr.AddReference("System.Windows.Forms")

Thanks

Thanks to David Srbecky, SharpDevelop's debugger expert and maintainer, for reviewing the code changes I wanted to make to the debugger and making sure nothing was broken. Adding support for debugging IronPython was straightforward and required 10-15 lines of new code thanks to the code already written by David.

Thanks also to Harry Pierson (IronPython Program Manager at Microsoft) who has written a great set of blog posts on creating an IronPython debugger in IronPython which gave me the reason why SharpDevelop's debugger was not working when debugging IronPython code.

Published May 30 2009, 01:40 PM by MattWard
Filed under: ,

Comments

 

djlawler said:

This is extremely cool as there is no other IDE with anything near working debugging for IronPython.  However, I notice that when I try to debug a project that has a splash screen on another thread that the debugger stops working and then the debugging session just ends.  Is this expected behavior or is there a setting somewhere that would make this work?

Thanks VERY much!

David

June 1, 2009 3:27 PM
 

djlawler said:

Arg!  Why do I find these things a few moments AFTER I submit a comment.  The problem was with my application.  Normally the current working directory is where my application lives.  However, when SharpDevelop runs it changes the current working directory to where the IronPython executable lives.  I just had to specifically set the current working directory in my application to the proper place and the exception that was happenning (that I think my application cleverly was hiding), does not happen anymore.  I seem to be able to set breakpoints and have them get 'hit'.  So please ignore my earlier comment (though it might help others to know about the current working directory)?

You rock!

David

June 1, 2009 4:17 PM
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.