Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bd5c3d824c3db63ffd9226c15941e6ad > files > 1577

mozart-1.4.0-1mdv2010.0.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>4 Sample Debugging Session</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node3.html#chapter.gui">&lt;&lt; Prev</A></TD><TD><A href="index.html">- Up -</A></TD><TD><A href="node5.html#chapter.control">Next &gt;&gt;</A></TD></TR></TABLE><DIV id="chapter.sample"><H1><A name="chapter.sample">4 Sample Debugging Session</A></H1><P> In the following, we will perform a first sample session to get a feeling of how threads behave under the control of Ozcar. For this, we'll use the following small program: </P><BLOCKQUOTE class="code"><CODE><SPAN class="keyword">local</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;S&nbsp;=&nbsp;<SPAN class="string">'hello'</SPAN>&nbsp;<BR><SPAN class="keyword">in</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;{Show&nbsp;S<SPAN class="keyword">#</SPAN><SPAN class="string">'&nbsp;world!'</SPAN>}<BR><SPAN class="keyword">end</SPAN></CODE></BLOCKQUOTE><P> </P><DIV class="apropos"><P class="margin">Attaching the Thread</P><P> Let's check how this code is executed - step by step. By default, Ozcar attaches all threads created by feeding code in the OPI, so this is what we're going to do, for example using <CODE>oz-feed-paragraph</CODE> (<SPAN class="key">C-. C-p</SPAN>). Ozcar responds as shown in <A href="node4.html#picture.hello">Picture&nbsp;4.1</A>. </P><DIV class="picture" id="picture.hello"><HR><P><A name="picture.hello"></A></P><P></P><DIV align="center"><IMG alt="" src="ozcar-hello.gif"></DIV><P> </P><P class="caption"><STRONG>Picture&nbsp;4.1:</STRONG> The Main Window after Feeding the Program</P><HR></DIV><P> The status line informs us that a new thread with ID 53 has been attached, and it was immediately selected. Accordingly, the thread forest contains a singleton tree with a node labeled 53 and marked with an asterisk. </P></DIV><DIV class="apropos"><P class="margin">Stack and Environment</P><P> The thread has been stopped immediately after its creation, so the Stack View displays a single frame, containing the first application in the program, <CODE>S&nbsp;=&nbsp;<SPAN class="string">'hello'</SPAN></CODE>, which, expressed in Oz core syntax, corresponds to <CODE>{Value<SPAN class="keyword">.</SPAN><SPAN class="string">'='</SPAN>&nbsp;_&nbsp;hello}</CODE>. Instead of the variable name the variable's value is displayed in the Stack View (where the underscore stands for a logic variable). If we explicitly needed to check what the value of <CODE>S</CODE> is, we could look it up in the Local Variables View. </P></DIV><DIV class="apropos"><P class="margin">Source View</P><P> If we look over to Emacs, we'll find that the source line which corresponds to <CODE>{Value<SPAN class="keyword">.</SPAN><SPAN class="string">'='</SPAN>&nbsp;_&nbsp;hello}</CODE> is highlighted, as shown in <A href="node4.html#picture.hello-emacs">Picture&nbsp;4.2</A>. </P><DIV class="picture" id="picture.hello-emacs"><HR><P><A name="picture.hello-emacs"></A></P><P></P><DIV align="center"><IMG alt="" src="ozcar-hello-emacs.gif"></DIV><P> </P><P class="caption"><STRONG>Picture&nbsp;4.2:</STRONG> Emacs Showing the Position of the Stopped Thread</P><HR></DIV><P> </P></DIV><DIV class="apropos"><P class="margin">Single-Stepping</P><P> The right arrow at the beginning of the current stack frame means: We are about to apply the function, but we haven't yet! One way to do this is to use the Step Into (<IMG alt="" src="step.gif">) action, which continues execution, but only until the next stop within the body of the applied procedure. In this case, <CODE>Value<SPAN class="keyword">.</SPAN><SPAN class="string">'='</SPAN></CODE> is a primitive procedure, which is why execution only stops when the application returns, indicated by the arrow in the stack frame turning into a left arrow. Note also that the arguments of the procedure have been updated. </P></DIV><DIV class="apropos"><P class="margin">Detaching the Thread</P><P> Performing the Step Into action another two times, we also evaluate the application of the primitive procedure <CODE>Show</CODE>, after which the stack becomes empty, and the thread terminates. Accordingly, the thread's node in the thread forest turns gray. We'll now detach this thread using the Detach (<IMG alt="" src="detach.gif">) action. </P></DIV></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node3.html#chapter.gui">&lt;&lt; Prev</A></TD><TD><A href="index.html">- Up -</A></TD><TD><A href="node5.html#chapter.control">Next &gt;&gt;</A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~lorenz/">Benjamin&nbsp;Lorenz</A> and&nbsp;<A href="http://www.ps.uni-sb.de/~kornstae/">Leif&nbsp;Kornstaedt</A><BR><SPAN class="version">Version 1.4.0 (20090610)</SPAN></ADDRESS></BODY></HTML>