[Ironpython-users] Debugging IronPython

Keith Rome rome at Wintellect.com
Thu May 31 18:48:14 CEST 2012

Since you are using WPF, I recommend the ActiPro SyntaxEditor control for the editor itself. They have a pre-defined language lexer for python that makes it really easy to get the syntax highlighting part of your debugging environment up and working quickly. Their control has hooks to support all of the other features you would want in your integrated debugger, but you will have to write them and plug them in. We have successfully implemented all of the features you have listed, as well as an Immediate REPL window pane, Intelliprompt completion providers, auto locals and custom watches, error "squiggles", and general code editor conveniences like comment toggling, line numbers and formatted copy/paste and printing.

The main thing you will need to interact with is the frame trace callback mechanism. This will be invoked for each line of code executed, and also for each execution scope that is entered or exited. Your code in there will do things like updating your call stack tracking, refreshing locals/watches expressions, and detecting breakpoints. The tricky part will be when you identify that a breakpoint has been reached, because you will want to allow the UI to continue handling events while the python code is "suspended". I have found that the best way to do that is to use the WPF Dispatcher to manually pump the window message queue until the user has clicked a "resume" or "step" function in the debugger UI.

You will probably also want to intercept the IO streams for the python runtime, which will allow you to get notified when code makes a call to the "print()" statement among other things. This is extremely useful for driving an "Output" window or an "Immediate" REPL window.

The other parts of the debugger become a matter of inspecting the current contents of the script scope (runtime variables), and potentially exploring deeper nested structures within. You will probably want to be smart about that - only expanding the inspection to sub-members when the user has actually expanded the corresponding node in your variable inspector for example. You will likely also want to do other optimizations like attempting to convert members to an IDictionary/IEnumerable first before falling back to IDMOP interfaces which are much slower. Also, if you choose to use the SyntaxEditor control I suggested above, you will want to enable "ambient parsing" for performance reasons, but this also means that you will need to make sure that your code compilation used to drive error squiggles / error list UI is thread-safe since the ambient parse is initiated by the editor on a background thread.

So yes, it is certainly possible to do what you want. But the coding effort is relative to the feature set you want to expose. There are several people on the mailing list like myself who have done similar implementations who I am sure would have problem helping you through some of the hurdles.

Keith Rome
Senior Consultant and Architect
Wintellect | 770.617.4016 | krome at wintellect.com<mailto:rome at wintellect.com>

From: ironpython-users-bounces+rome=wintellect.com at python.org [mailto:ironpython-users-bounces+rome=wintellect.com at python.org] On Behalf Of David, Al
Sent: Thursday, May 31, 2012 10:04 AM
To: ironpython-users at python.org
Subject: [Ironpython-users] Debugging IronPython

We're developing a C#, WPF, .NET application.  And the purpose of this application is to communicate with and control custom hardware (circuit boards) as well as instrumentation (oscilloscopes, power supplies, etc).

This application contains several panels/windows/screens.  And as part of this application, I need to implement another panel/window/screen for a scripting environment.  Ideally through this additional scripting panel/window/screen, the user will be able to write, run, as well as debug IronPython scripts.  And when I say debug, I am referring to having the ability to set breakpoints, view and modify variables, see the stack, etc, etc.

We've tried embedding SharpDevelop into our application but found this is not possible because SharpDevelop requires being the "main window".  And in my scenario, the "main window" is our application.

Is there any way at all to accomplish what I've stated above, and without a major coding effort?  If so, would you be able to refer us to any coding examples that may give us a jump start?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20120531/4d6fe975/attachment.html>

More information about the Ironpython-users mailing list