Hi folks, <br><br>In Pharo mailing list, there are people trying to fix the known bug when debugging with FFI. The bug report is this: <a href="http://bugs.squeak.org/view.php?id=6436" target="_blank">http://bugs.squeak.org/view.php?id=6436</a><br>
<br>Javier has done an excellent job and here is his last post. Can someone read what he found and see if we can fix this annoying bug?<br><br>Thanks,<br><br>Mariano<br><br><br><div class="gmail_quote">---------- Forwarded message ----------<br>
From: <b class="gmail_sendername">Javier Pimás</b> <span dir="ltr">&lt;<a href="mailto:elpochodelagente@gmail.com">elpochodelagente@gmail.com</a>&gt;</span><br>Date: 2009/8/2<br>Subject: Re: [Pharo-project] Debbuging problems, FFI<br>
To: <a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br><br><br>I Think I found where the problem lies, it&#39;s just sitting there waiting to be resolved.<br><br>To see what was happening I debugged the debuger, which was really weird. I found the answer when I broke into the step over button by adding a self break in OTCmdOverDebugger&gt;&gt;execute. After catching it I removed the break and stepped into everything to see how step over worked. The intresting part is in MethodContext(ContextPart)&gt;&gt;step, which sends interpretNextInstructionFor: self. The idea is this, instead of advancing the vm program counter within the vm code, the debugger simulates the execution cycle, step by step. It not so hard as it seems but also not very simple. The problem comes when the debugger tryies to simulate primitive calls. When the simulator detects a primitive, it issues a  MethodContext(ContextPart)&gt;&gt;doPrimitive:method:receiver:args:, here you can see the detection:<br>


<br>tryPrimitiveFor: method receiver: receiver args: arguments <br>    &quot;...&quot;<br>    | primIndex |<br>    (primIndex := method primitive) = 0 ifTrue: [^ PrimitiveFailToken].<br>    ^ self doPrimitive: primIndex method: method receiver: receiver args: arguments<br>


<br>well, the problem is that doPrimitive doesn&#39;t seem to implement all primitives (I recomend you to look it&#39;s code), but just a few ones. Also, as far as I can see, it calls primitive 19, which i found is (by looking vm C code) primitiveFail, and that primitive just sets a flag that says that something failed.<br>


<br>Then, if my calculations are correct, the problem is that the FFI Call primitive needs to be handled by hand. I tryied adding this to ContextPart&gt;&gt;doPrimitive:method:receiver:args:<br><br>primitiveIndex = 120 ifTrue: &quot;Calling an FFI method, just evaluate it and return&quot;<br>


        [ meth valueWithReceiver: receiver arguments: arguments . ^self].<br><br>just before <br><br>    arguments size &gt; 6 ifTrue: [^PrimitiveFailToken].<br><br>which I think almost worked. I think the primitive was executed, but this doesn&#39;t handle the execution context that is being simulated, and the stack gets corrupted. Somebody with more experience in ContextPart, MethodContext, etc. may give us a hand here, I think the fix is almost there.<br>


<br>Bye,<br>      Javier.<br><br><div class="gmail_quote">2009/7/31 Mariano Martinez Peck <span dir="ltr">&lt;<a href="mailto:marianopeck@gmail.com" target="_blank">marianopeck@gmail.com</a>&gt;</span><div><div></div><div class="h5">
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br><br><div class="gmail_quote">2009/7/31 Javier Pimás <span dir="ltr">&lt;<a href="mailto:elpochodelagente@gmail.com" target="_blank">elpochodelagente@gmail.com</a>&gt;</span><div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">



Does anybody know if the problem occurs just in Windows or in any OS? this can give a clue of the problem...<div><div></div><div><br></div></div></blockquote></div><div><br>I don&#39;t remember debugging in Windows, but in Linux I have this problem for sure.<br>



 </div><div><div></div><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div><br><div class="gmail_quote">On Thu, Jul 30, 2009 at 11:28 PM, Javier Pimás <span dir="ltr">&lt;<a href="mailto:elpochodelagente@gmail.com" target="_blank">elpochodelagente@gmail.com</a>&gt;</span> wrote:<br>





<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Well, at least I feel better that I&#39;m not crazy, (or not the only one...). Maybe if someone could give us a clue about it, we could spot where the problem is. Do you think it is a vm problem or something related to the smalltalk code?<br>






<br><div class="gmail_quote">2009/7/30 Mariano Martinez Peck <span dir="ltr">&lt;<a href="mailto:marianopeck@gmail.com" target="_blank">marianopeck@gmail.com</a>&gt;</span><div><div></div><div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">






Yes. This is really annoying for me. I am writing a C library plugin since a year and a half and this is very frustrated :(<br>You cannot debug when using FFI. I mean, you cannot get advantages of one of the best Smalltalk features! What I do is to write a self break before and after the call and use &quot;proceed&quot; but I don&#39;t like it at all. <br>







<br>Once I tried to see what the problem was, but I was to difficult to me to understand it and fix it. We need a guru here I think hahaha.<br><br>Best,<br><br>Mariano<br><br><div class="gmail_quote">2009/7/30 Javier Pimás <span dir="ltr">&lt;<a href="mailto:elpochodelagente@gmail.com" target="_blank">elpochodelagente@gmail.com</a>&gt;</span><br>







<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div>Hi, I&#39;m having problems with the debugger. Every time I try to debug code that uses FFI, if I step over a message that internally does an FFI call, I get an externalCallFailed error and then I land in MethodContext(ContextPart)&gt;&gt;runUntilErrorOrReturnFrom:  <br>









If I run the code without debugging, then I have no problems at all.<br>
<br>I&#39;m using SqueakPharo v3.11.2 with pharo0.1-10373web09.07.2.<br><br>To reproduce it you can try this: <br><br>ScriptLoader loadFFI.<br>then load latest GLMorphic from squeaksource, and uncomment the &quot;self break.&quot; in <br>










GLCanvas&gt;&gt;displayString:from:to:at:strikeFont:kern:<br clear="all"><br> doit<br>World fullDrawOn: GLDisplayScreen testCanvas<br>hit debug and step over until you reach <br>ogl glTexImage2D: GLTexture2d with:...<br>









<br>also you&#39;ll see wrong values for local vars, like aPoint which will look as #(nil nil nil nil nil) when it&#39;ll actually have a point.<br><br>Is there any other way to set up a break point instead of adding self break to the code??<br>









<br>Thanks,<br>       Javier.<br><font color="#888888"><br>-- <br>Javier Pimás<br>Ciudad de Buenos Aires<br>
</font><br></div></div><div>_______________________________________________<br>
Pharo-project mailing list<br>
<a href="mailto:Pharo-project@lists.gforge.inria.fr" target="_blank">Pharo-project@lists.gforge.inria.fr</a><br>
<a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a><br></div></blockquote></div><br>
<br>_______________________________________________<br>
Pharo-project mailing list<br>
<a href="mailto:Pharo-project@lists.gforge.inria.fr" target="_blank">Pharo-project@lists.gforge.inria.fr</a><br>
<a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a><br></blockquote></div></div></div><div><div></div><div>





<br><br clear="all"><br>-- <br>Javier Pimás<br>
Ciudad de Buenos Aires<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Javier Pimás<br>Ciudad de Buenos Aires<br>
</div></div><br>_______________________________________________<br>
Pharo-project mailing list<br>
<a href="mailto:Pharo-project@lists.gforge.inria.fr" target="_blank">Pharo-project@lists.gforge.inria.fr</a><br>
<a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a><br></blockquote></div></div></div><br>
<br>_______________________________________________<br>
Pharo-project mailing list<br>
<a href="mailto:Pharo-project@lists.gforge.inria.fr" target="_blank">Pharo-project@lists.gforge.inria.fr</a><br>
<a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a><br></blockquote></div></div></div><div><div></div><div class="h5">
<br><br clear="all"><br>-- <br>Javier Pimás<br>

Ciudad de Buenos Aires<br>
</div></div><br>_______________________________________________<br>
Pharo-project mailing list<br>
<a href="mailto:Pharo-project@lists.gforge.inria.fr">Pharo-project@lists.gforge.inria.fr</a><br>
<a href="http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project" target="_blank">http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project</a><br></div><br>