<div dir="ltr"><div>Hi.</div><div><br></div><div>In Pharo we have special logic to debug failure code of primitives. When debugger detects named prim it tries to create same prim method but without failure code. Then if it fails debugger step into primitive failure code.</div><div><br></div><div>To create such cleaned primitive method Pharo uses template method like this:</div><div><br></div><div>tryNamedPrimitiveTemplate</div><div><span class="" style="white-space:pre">        </span>&quot;This method is a template that the Smalltalk simulator uses to </div><div><span class="" style="white-space:pre">        </span>execute primitives. See Object documentation whatIsAPrimitive.&quot;</div><div><span class="" style="white-space:pre">        </span>&lt;primitive:&#39; module:&#39; error: errorCode&gt;</div><div><span class="" style="white-space:pre">        </span>^ Context primitiveFailTokenFor: errorCode</div><div><br></div><div>Then it changes arguments count to be like given method:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>theMethod := self class tryNamedPrimitiveTemplateMethod.</div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>theMethod prepareForSimulationWith: arguments size.</div></div><div>self setNamedPrimitiveInformationFrom: <b>aCompiledMethod</b> toMethod: theMethod.<br></div></blockquote><div><div><span class="" style="white-space:pre"><br></span></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><span style="white-space:pre">CompiledMethod&gt;&gt;prepareForSimulationWith: numArgs</span></div></div><div><div><span class="" style="white-space:pre">        &quot;This method changes the argument count of a CompiledMethod header to numArgs, its temporary count to numArgs + 1 and change the code handling primitive error to store the error code in the unique temporary of the method&quot;</span></div></div><div><div><span class="" style="white-space:pre">                        </span></div></div><div><div><span class="" style="white-space:pre">        | newHeader xpc |</span></div></div><div><div><span class="" style="white-space:pre">        newHeader := (((self header bitAnd: 2r01110000000000111111111111111111) </span></div></div><div><div><span class="" style="white-space:pre">                        bitOr: (numArgs bitShift: 24))</span></div></div><div><div><span class="" style="white-space:pre">                        bitOr: (numArgs + 1 bitShift: 18)).</span></div></div><div><div><span class="" style="white-space:pre">        newHeader := newHeader + (self class headerFlagForEncoder: self encoderClass).</span></div></div><div><div><span class="" style="white-space:pre">        self objectAt: 1 put: newHeader.</span></div></div><div><div><span class="" style="white-space:pre">        </span></div></div><div><div><span class="" style="white-space:pre">        xpc := self initialPC.</span></div></div><div><div><span class="" style="white-space:pre">        &quot;long store temp&quot;</span></div></div><div><div><span class="" style="white-space:pre">        (self at: xpc) = 129 </span></div></div><div><div><span class="" style="white-space:pre">                ifTrue: [</span></div></div><div><div><span class="" style="white-space:pre">                        self at: xpc + 1 put: (16r40 + numArgs).</span></div></div><div><div><span class="" style="white-space:pre">                        self at: xpc + 3 put: (16r10 + numArgs)]</span></div></div></blockquote><div><div><span class="" style="white-space:pre"><br></span></div><div><span class="" style="white-space:pre"><br></span></div><div><span class="" style="white-space:pre">Then method executed by:        </span></div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>theMethod flushCache</div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>theMethod valueWithReceiver: aReceiver arguments: arguments</div></div></blockquote><br><div>This approach works correctly on Cog and not working in Spur.</div><div>In Spur result of theMethod execution become wrong when given method has arguments.</div><div>Which means that changing method arguments of CompiledMethod is incorrect for Spur.</div><div><br></div><div>Is there any solution to make it working?</div><div><br></div></div>