<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">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 &#8220;squiggles&#8221;, and general code editor conveniences like comment toggling, line numbers and formatted copy/paste and printing.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">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 &#8220;suspended&#8221;. 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 &#8220;resume&#8221; or &#8220;step&#8221; function in the debugger UI.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">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 &#8220;print()&#8221; statement among other things. This is extremely useful
 for driving an &#8220;Output&#8221; window or an &#8220;Immediate&#8221; REPL window.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">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 &#8211; 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 &#8220;ambient parsing&#8221; 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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<div>
<p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:14.0pt;color:#1F497D">Keith Rome<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;color:#1F497D">Senior Consultant and Architect<o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="font-size:10.0pt;color:#1F497D">MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;color:#1F497D">Wintellect | 770.617.4016 |
<a href="mailto:rome@wintellect.com">krome@wintellect.com</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;color:#1F497D"><a href="http://www.wintellect.com/">www.wintellect.com</a><o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> ironpython-users-bounces&#43;rome=wintellect.com@python.org [mailto:ironpython-users-bounces&#43;rome=wintellect.com@python.org]
<b>On Behalf Of </b>David, Al<br>
<b>Sent:</b> Thursday, May 31, 2012 10:04 AM<br>
<b>To:</b> ironpython-users@python.org<br>
<b>Subject:</b> [Ironpython-users] Debugging IronPython<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">We&#8217;re developing a C#, WPF, .NET application.&nbsp; And the purpose of this application is to communicate with and control custom hardware (circuit boards) as well as instrumentation (oscilloscopes, power supplies, etc).<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">This application contains several panels/windows/screens.&nbsp; And as part of this application, I need to implement another panel/window/screen for a scripting environment.&nbsp; Ideally through this additional scripting panel/window/screen, the
 user will be able to write, run, as well as debug IronPython scripts.&nbsp; And when I say debug, I am referring to having the ability to set breakpoints, view and modify variables, see the stack, etc, etc.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">We&#8217;ve tried embedding SharpDevelop into our application but found this is not possible because SharpDevelop requires being the &#8220;main window&#8221;.&nbsp; And in my scenario, the &#8220;main window&#8221; is our application.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Is there any way at all to accomplish what I&#8217;ve stated above, and without a major coding effort?&nbsp; If so, would you be able to refer us to any coding examples that may give us a jump start?<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Al<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body>
</html>