<div dir="ltr">Hi Ben,<div><br></div><div>Hopefully Chris Cunnigton was doing a tutorial video on the simulator to help. There is one blog post from Eliot on machine code simulation for x86 in his blog (Simulating out of the Bochs or something like that).</div><div><br></div><div>The REPL image expects chunk format. Hence you need to write &quot;3 + 4 !&quot;</div><div><br></div><div>Your script looks nice.</div><div><br></div><div>I have 3 main workflows with the simulator:</div><div>1) in-image compilation: I change the way the JIT generate machine code, use in-image compilation to check the machine code generated is as I wanted, put halt in the JIT code and debug it as Smalltalk code while JIT compilation. For that I use the scripts in &quot;In-image compilation&quot; workspace.</div><div>2) Ensuring my VM changes are correct: I start the simulator and check there are no assertion failure / error before the display kicks in, sometimes I try to run some code too using my VM changes by writing it in the REPL .</div><div>3) Debugging a VM error: I start the simulator with a REPL image, then enter the code triggering the VM crash, and try to figure out what&#39;s going on.</div><div><br></div><div>In the menu, there are in order:</div><div>1) toggle Transcript (toggle between simulator and external Transcript the output stream)</div><div>clone VM (clone the simulator, to have guinea pigs to reproduce bugs, typically bugs hard to reproduce once you&#39;ve reproduced them once or GC bugs)</div><div>2) things related to the stacks.</div><div>&#39;printcallStack&#39; is the main one which prints the current stack.</div><div>&#39;print ext head frame&#39; prints the current stack frame, very useful too.</div><div>These 2 are the most useful. Other entries are situational.</div><div>3) &#39;printOop:&#39; expects parameter in hex, printing an oop, if non immediate the header and all the fields.</div><div>disassemble entries are very useful to disassemble where the VM has crashed or disassemble a method that looks suspicious based on its address.</div><div>4) inspect objectMemory or interpreter to look into the variables value, if crash in GC or interpreter</div><div>Or run the leak checked to look for memory leaks.</div><div>Or inspect cogit if a bug happened during JIT compilation </div><div>Or inspect the method zone, typically useful to analyze it</div><div>5) print cog methods and trampoline (similar to disassemble, used for debugging the machine code)</div><div>All the *break* things stop execution on a specific selector / pc / block / ..<br></div><div>If single stepping is enabled (you need to do that only on small portion of code, the machine code gets dog slow), then you can report recent instructions to see the register state at each machine instructions, etc).</div><div><br></div><div>To get warmed-up:</div><div>1) Inspect the object memory, then look for the first class table page instance variable. It&#39;s an oop referencing an array, try in the simulator to &quot;printOop:&quot; the address of the first class table page that you found. It should print it in the Transcript, the first entries are immediate, in Spur32 SmallInteger/Character/SmallInteger.</div><div>2) print the active stack, look for the method&#39;s address. Try to print it as an oop, and if it tells you &quot;address in the machine code zone&quot;, print the cog method and its machine code instead.</div><div><br></div><div>Have fun.</div><div><br></div><div>I&#39;ll try to answer further questions as I like to see people hacking the VM, but I am quite busy :-)</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 23, 2016 at 6:06 PM, Ben Coman <span dir="ltr">&lt;<a href="mailto:btc@openinworld.com" target="_blank">btc@openinworld.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On Mon, May 23, 2016 at 3:14 AM, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; On May 22, 2016, at 9:43 AM, Ben Coman &lt;<a href="mailto:btc@openinworld.com">btc@openinworld.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt; On Sat, May 21, 2016 at 4:44 AM, Clément Bera &lt;<a href="mailto:bera.clement@gmail.com">bera.clement@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On Fri, May 20, 2016 at 7:29 PM, Ben Coman &lt;<a href="mailto:btc@openinworld.com">btc@openinworld.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On Fri, May 20, 2016 at 8:44 PM, Clément Bera &lt;<a href="mailto:bera.clement@gmail.com">bera.clement@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Normally if you build a cog development image:<br>
&gt;&gt;&gt; $ svn co <a href="http://www.squeakvm.org/svn/squeak/branches/Cog/image" rel="noreferrer" target="_blank">http://www.squeakvm.org/svn/squeak/branches/Cog/image</a><br>
&gt;&gt;&gt; $ cd ./image<br>
&gt;&gt;&gt; $ ./buildsqueaktrunkvmmakerimage.sh<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; You have multiple scripts available with comments to run the simulator that work out of the box. It should take a couple minutes to get it working. Then the easiest is to simulate a REPL image to easily debug what you want.<br>
&gt;&gt;<br>
&gt;&gt; Hi Clement,<br>
&gt;&gt;<br>
&gt;&gt; Could you point me to such a REPL image?<br>
&gt;&gt;<br>
&gt;&gt; cheers -ben<br>
<br>
&gt;<br>
&gt; Hi Ben,<br>
&gt;<br>
&gt;     see buildspurreaderimage.sh, or it may be buildspurtrunkreaderimage.sh, in the image directory.<br>
<br>
Thanks Eliot.  I now have an &quot;Input please&quot; window.  I presume I<br>
should type Smalltalk expressions in there.  For a while it was<br>
confusing that I could see no effect entering...<br>
   3+4<br>
or...<br>
  Transcript show:&#39;hello&#39;<br>
<br>
Nothing moving in the Simulator&#39;s trace pane, nor the Transcript<br>
within the simulation, nor the host&#39;s Transcript, but after selecting<br>
menu item &quot;print instructions each instruction&quot; I see 3+4 produce a<br>
stream of instructions in the host transcript.<br>
<br>
With such a long list of menu items, I expect now I&#39;ll bug everyone to<br>
discover what they all are.  I&#39;ll use this thread to log random things<br>
I discover for posterity for myself and other VM newcomers.  There<br>
doesn&#39;t seem a lot of info out there on the simulator and maybe some<br>
will spark some short comments, but I don&#39;t expect feedback on<br>
everything.<br>
<br>
But first, what are a few important menu or workflow items a VM<br>
newcomer working with the REPL image would find useful?<br>
<br>
cheers -ben<br>
<br>
P.S. After running ./buildspurtrunkreaderimage.sh<br>
this is the code I ran in the host image...<br>
| cos |<br>
cos := CogVMSimulator newWithOptions: #(Cogit<br>
StackToRegisterMappingCogit &quot;SimpleStackBasedCogit&quot;<br>
ObjectMemory Spur32BitCoMemoryManager<br>
&quot;ISA ARMv5&quot; &quot;ISA IA32&quot;).<br>
&quot;cos initializeThreadSupport.&quot;<br>
cos desiredNumStackPages: 8.<br>
cos openOn: &#39;spurreader.image&#39;.<br>
cos openAsMorph; run<br>
</blockquote></div><br></div>