<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Re: [Ironpython-users] How to watch the variables(global and local variable) value embedding in c# Code ?</title>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
body {
  margin: 5px 5px 5px 5px;
  background-color: #ffffff;
}
/* ========== Text Styles ========== */
hr { color: #000000}
body, table /* Normal text */
{
 font-size: 9pt;
 font-family: 'Courier New';
 font-style: normal;
 font-weight: normal;
 color: #000000;
 text-decoration: none;
}
span.rvts1 /* Heading */
{
 font-size: 10pt;
 font-family: 'Arial';
 font-weight: bold;
 color: #0000ff;
}
span.rvts2 /* Subheading */
{
 font-size: 10pt;
 font-family: 'Arial';
 font-weight: bold;
 color: #000080;
}
span.rvts3 /* Keywords */
{
 font-size: 10pt;
 font-family: 'Arial';
 font-style: italic;
 color: #800000;
}
a.rvts4, span.rvts4 /* Jump 1 */
{
 font-size: 10pt;
 font-family: 'Arial';
 color: #008000;
 text-decoration: underline;
}
a.rvts5, span.rvts5 /* Jump 2 */
{
 font-size: 10pt;
 font-family: 'Arial';
 color: #008000;
 text-decoration: underline;
}
span.rvts6
{
 font-size: 10pt;
 font-family: 'segoe ui';
 color: #333333;
}
a.rvts7, span.rvts7
{
 font-size: 10pt;
 font-family: 'segoe ui';
 color: #4078c0;
 text-decoration: none;
}
span.rvts8
{
 font-size: 8pt;
 font-family: 'arial';
 font-style: italic;
 color: #c0c0c0;
}
/* ========== Para Styles ========== */
p,ul,ol /* Paragraph Style */
{
 text-align: left;
 text-indent: 0px;
 padding: 0px 0px 0px 0px;
 margin: 0px 0px 0px 0px;
}
.rvps1 /* Centered */
{
 text-align: center;
}
--></style>
</head>
<body>

<p>Monday, November 16, 2015, 5:27:47 ºÎÓÎöÎ:</p>
<p><br></p>
<div><table border=0 cellpadding=1 cellspacing=2 style="background-color: #ffffff;">
<tr valign=top>
<td width=1 style="background-color: #0000ff;"><br>
</td>
<td width=703>
<p><span class=rvts6>Hi,</span></p>
<p><span class=rvts6>I'm using IronPython embedding in vs2012 with c# code. and I need to watch the Var's Value when the script is debugging? is the current Version IronPython support this ? if it suppord ,Is there any method which I can use ?or when the IronPython can support it ?</span></p>
<p><span class=rvts6>Could you please give me some help ? you can see my project there:[</span><a class=rvts7 href="https://github.com/heyxEvget/IronPython-Debugger/tree/master/SoftWare">https://github.com/heyxEvget/IronPython-Debugger/tree/master/SoftWare</a><span class=rvts6>]</span></p>
<p><span class=rvts6>I use this code:</span></p>
<p><span class=rvts6>engine.SetTrace(OnTraceback);</span></p>
<p><span class=rvts6>private void OnTraceback(TraceBackFrame frame, string result, object payload)</span></p>
<p><span class=rvts6>{</span></p>
<p><span class=rvts6>   switch (result)</span></p>
<p><span class=rvts6>   {</span></p>
<p><span class=rvts6>        case "call":</span></p>
<p><span class=rvts6>        TracebackCall();</span></p>
<p><span class=rvts6>        break;</span></p>
<p><span class=rvts6>        case "line":</span></p>
<p><span class=rvts6>        TracebackLine();</span></p>
<p><span class=rvts6>        break;</span></p>
<p><span class=rvts6>        case "return":</span></p>
<p><span class=rvts6>        TracebackReturn();</span></p>
<p><span class=rvts6>        break;</span></p>
<p><span class=rvts6>    }</span></p>
<p><span class=rvts6>}</span></p>
</td>
</tr>
</table>
</div>
<p><br></p>
<p>What you basically need is to check your variable at every line. Without peeking into the line, it's impossible to tell what it does. Of course, you can dig up the engine's assignment subroutine and set a C#-level</p>
<p>debug thingamajig on them. But that's out of cscope of IronPython's facilities.</p>
<p><br></p>
<p>It's only useful to check if the variable is in scope (in the frame's locals and globals).</p>
<p>Unless you're interested in mutations of a mutable object rather than assignings - then it might be better to set  checks on the mutation functions.</p>
<p><br></p>
<p>In addition to that, you may peek if the current line is an assignment operator</p>
<p>or includes a dictionary assignment/update and things like `vars()' result.</p>
<p>This is too much for a one-off task but looks promising in you're writing a</p>
<p>production-grade debugger.</p>
<p><br></p>
<p><span class=rvts8>-- </span></p>
<p><span class=rvts8>Regards,</span></p>
<p><span class=rvts8> Ivan Pozdeev</span></p>

</body></html>