<div dir="ltr"><div><br></div><br><div><blockquote type="cite"><div>On Nov 14, 2017, at 4:34 PM, Ben Coman <<a href="mailto:btc@openinworld.com" target="_blank">btc@openinworld.com</a>> wrote:</div><br class="gmail-m_570401440190338197Apple-interchange-newline"><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 15 November 2017 at 00:07, Todd Blanchard <span dir="ltr"><<a href="mailto:tblanchard@mac.com" target="_blank">tblanchard@mac.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">I've got it loaded, have fixed up the library path and fixed the test for version (built in lib returns very different version string).<div><br></div><div>I have many tests green.  However, as before, tests involving CXSourceRange that return CXSourceLocations return all zero'd data.  The CXSourceRange struct looks sane.</div><div><br></div><div>The calls to <span style="font-family:Menlo;font-size:11px">CXSourceLocation clang_getRangeStart(CXSourceRa<wbr>nge range);</span></div><div><br></div><div>and its twin RangeEnd result in zero'd structs.</div><div><br></div><div>Any idea on where I can look to try to figure out where this is going wrong?  </div><div><br></div><div>I have compiled little C programs and verified that both struct sizes agree in FFI and native code (24 bytes each).</div><div><br></div><div>Not sure what to try next.</div><span class="gmail-m_570401440190338197gmail-HOEnZb"><font color="#888888"><div> c</div><div>-Todd Blanchard</div></font></span></div></blockquote><div><br></div><div>Compile your own debug-VM** and make a little C wrapper MyCXSourceRange to forward to Clang's CXSourceRange, and set a gdb a breakpoint in MyCXSourceRange and compare 64 bit and 32 bit versions.  </div><div><br></div><div>That still leaves differences in the callout before your breakpoint in MyCXSourceRange is reached, so just do two callouts in a row and trace from the first to the second. </div></div><br></div><div class="gmail_extra">** <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/tree/Cog/build.linux64x64/pharo.cog.spur/build.debug" target="_blank">https://github.com/<wbr>OpenSmalltalk/opensmalltalk-<wbr>vm/tree/Cog/build.linux64x64/<wbr>pharo.cog.spur/build.debug</a><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">cheers -ben</div></div></div></blockquote></div><div><br></div><div>On 17 November 2017 at 14:57, Todd Blanchard <span dir="ltr"><<a href="mailto:tblanchard@mac.com" target="_blank">tblanchard@mac.com</a>></span> wrote:<br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">Right, so I have my own debug VM (64 bit Pharo Cog) and a debug version of libclang. </div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>I can attach with lldb and set a breakpoint on <span style="font-family:Menlo;font-size:11px;background-color:rgb(255,255,255)">clang_getRangeStart</span></div><div><br></div><div>Then I debug the test that gets diagnostics and I see that the CXSourceRange has data.  Then I step into 'range start' and I land in my breakpoint for clang_getRangeStart and I can see that the argument to the function - supposedly a CXSourceRange passed by value - is all zero'd memory.</div><div><br></div><div>So it appears that in the 64bit VM, structs passed by value doesn't work right.</div><div><br></div><div>I've traced back up the stack and I confess the marshaling code is totally beyond my comprehension.  This is what I was able to get:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">Process 1126 stopped</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 2.1</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #0: 0x000000011e33136b libclang.dylib`::clang_<wbr>getRangeStart(range=<wbr>CXSourceRange @ 0x00007fff55f4e380) at CXSourceLocation.cpp:89</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   86  <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">       </span>  </span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   87  <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">        </span>CXSourceLocation clang_getRangeStart(<wbr>CXSourceRange range) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   88  <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">     </span>  // Special decoding for CXSourceLocations for CXLoadedDiagnostics.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">-> 89  <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">     </span>  if ((uintptr_t)</span><span style="text-decoration:underline;font-variant-ligatures:no-common-ligatures">r</span><span style="font-variant-ligatures:no-common-ligatures">ange.ptr_data[0] & 0x1) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   90  <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">     </span>    CXSourceLocation Result = { { range.ptr_data[0], nullptr }, 0 };</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   91  <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">     </span>    return Result;    </span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   92  <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap"> </span>  }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">Target 0: (Pharo) stopped.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(169,169,169)">(lldb) </span><span style="font-variant-ligatures:no-common-ligatures">p range</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">(CXSourceRange) $0 = {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">  ptr_data = ([0] = 0x0000000000000000, [1] = 0x0000000000000000)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">  begin_int_data = 0</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">  end_int_data = 0</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(169,169,169);background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">(lldb) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">bt</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 2.1</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">  * frame #0: 0x000000011e33136b libclang.dylib`::clang_<wbr>getRangeStart(range=<wbr>CXSourceRange @ 0x00007fff55f4e380) at CXSourceLocation.cpp:89</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #1: 0x0000000109e20b5a Pharo`primitiveCalloutWithArgs at X64SysVFFIPlugin.c:6041</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #2: 0x0000000109cb964c Pharo`primitiveExternalCall at gcc3x-cointerp.c:77188</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #3: 0x0000000109cb1629 Pharo`<wbr>interpretMethodFromMachineCode at gcc3x-cointerp.c:19719</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #4: 0x0000000109cb77fc Pharo`ceSendsupertonumArgs(<wbr>selector=4713336760, superNormalBar=0, rcvr=<a href="tel:(469)%20246-6872" value="+14692466872" target="_blank">4692466872</a>, numArgs=1) at gcc3x-cointerp.c:17767</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #5: 0x000000011774a135</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #6: 0x0000000109c76227 Pharo`interpret at gcc3x-cointerp.c:2703</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #7: 0x0000000109dbbf31 Pharo`-[<wbr>sqSqueakMainApplication runSqueak](self=<wbr>0x00006080000d7370, _cmd="runSqueak") at sqSqueakMainApplication.m:201</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #8: 0x00007fff81e5a8dd Foundation`__<wbr>NSFirePerformWithOrder + 368</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #9: 0x00007fff803b1d37 CoreFoundation`__CFRUNLOOP_IS_<wbr>CALLING_OUT_TO_AN_OBSERVER_<wbr>CALLBACK_FUNCTION__ + 23</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #10: 0x00007fff803b1ca7 CoreFoundation`__<wbr>CFRunLoopDoObservers + 391</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #11: 0x00007fff803926d9 CoreFoundation`__CFRunLoopRun + 873</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #12: 0x00007fff80392114 CoreFoundation`<wbr>CFRunLoopRunSpecific + 420</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #13: 0x00007fff7f8f2ebc HIToolbox`<wbr>RunCurrentEventLoopInMode + 240</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #14: 0x00007fff7f8f2bf9 HIToolbox`<wbr>ReceiveNextEventCommon + 184</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #15: 0x00007fff7f8f2b26 HIToolbox`_<wbr>BlockUntilNextEventMatchingLis<wbr>tInModeWithFilter + 71</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #16: 0x00007fff7de89a54 AppKit`_DPSNextEvent + 1120</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #17: 0x00007fff7e6057ee AppKit`-[NSApplication(<wbr>NSEvent) _nextEventMatchingEventMask:<wbr>untilDate:inMode:dequeue:] + 2796</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #18: 0x00007fff7de7e3db AppKit`-[NSApplication run] + 926</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #19: 0x00007fff7de48e0e AppKit`NSApplicationMain + 1237</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #20: 0x0000000109db5baf Pharo`main(argc=1, argv=0x00007fff55f8bca8, envp=0x00007fff55f8bcb8) at main.m:52</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #21: 0x00007fff95b18235 libdyld.dylib`start + 1</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">    frame #22: 0x00007fff95b18235 libdyld.dylib`start + 1</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(169,169,169);background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">(lldb) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">up</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">frame #1: 0x0000000109e20b5a Pharo`primitiveCalloutWithArgs at X64SysVFFIPlugin.c:6041</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   6038<span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">                 </span>result2 = floatObjectOf(floatRet1);</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   6039<span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">                 </span>goto l14;</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   6040<span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">           </span>}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">-> 6041<span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">          </span>intRet1 = </span><span style="text-decoration:underline;font-variant-ligatures:no-common-ligatures">d</span><span style="font-variant-ligatures:no-common-ligatures">ispatchFunctionPointerwithwit<wbr>hwithwithwithwith(((<wbr>SixteenByteReturn (*)(sqIntptr_t, sqIntptr_t, sqIntptr_t, sqIntptr_t, sqIntptr_t, sqIntptr_t)) (((void *) address2))), ((calloutState1-><wbr>integerRegisters))[0], ((calloutState1-><wbr>integerRegisters))[1], ((calloutState1-><wbr>integerRegisters))[2], ((calloutState1-><wbr>integerRegisters))[3], ((calloutState1-><wbr>integerRegisters))[4], ((calloutState1-><wbr>integerRegisters))[5]);</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   6042<span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">         </span>/* begin maybeOwnVM:threadIndex: */</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   6043<span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">         </span></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">   6044<span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">    </span>#  if COGMTVM</span></div></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">The struct that should have shown up appears in Pharo as </span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><div>"CXSourceRangeStruct ( </div><div>ptr_data1: <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">       </span>(void*)@ 16r7FDF356C77B0</div><div>ptr_data2: <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">   </span>(void*)@ 16r7FDF356D0C70</div><div>begin_int_data: <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">      </span>21</div><div>end_int_data: <span class="gmail-m_570401440190338197Apple-tab-span" style="white-space:pre-wrap">      </span>28</div><div>)"</div></span></div><div><br></div><div>Open to ideas at this point but I think to progress I would require deep knowledge of Intel calling conventions and I don't really know where to go next.</div><div><br></div><div>Try to isolate the functions into a little dynamic lib and file a bug?</div></div></blockquote><div><br></div><div><div>As you say, to minimize confounding factors the next step would be to try to reproduce the "structs passed by value" problem in a minimal library,</div><div>and also someone trying to reproduce it doesn't need to compile the whole libclang </div></div><div><br></div><div>Also now is a good time to move discussion to vm-dev.</div><div><br></div><div>cheers -ben</div><div><br></div><div> </div></div></div></div>