<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Ken,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 28, 2022 at 1:20 PM <<a href="mailto:ken.dickey@whidbey.com">ken.dickey@whidbey.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"> Greetings,<br>
<br>
I am trying to gain runtime info for use of Alien on a RiscV64 Linux <br>
system, but [A] I have barely used gdb in the last couple of decades and <br>
[B] have hardly used Squeak in a decade or so, and [C] never used Alien.<br>
<br>
With that confession out of the way.. my proximate problem is trying to <br>
set a breakpoint in a thunk to capture where things are going into the <br>
weeds.<br>
<br>
The attached file has the gritty details.  I am trying <br>
Alien>>exampleCqsort<br>
<br>
The Smalltalk setup code is copying a hand assembled byteVector into an <br>
Alien.  I am catching the copy operation in gdb in IA32ABI.c: <br>
primAlianReplace to get the code address, then trying to set a <br>
breakpoint there -- which seems to fail.  Get SIGILL (illegal <br>
instruction) when the PC gets to the start of the thunk.<br>
<br>
So:<br>
   [A] How do I find out if the thunk memory is properly Executable?<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">If, when the processor executes the call instruction to the thunk, it generates a SIGBUS, SIGILL or SIGSEGV then it's not executable. I think it'll be SIGBUS, but these categories are a little fluid.  Is it an illegal instruction, or a bus error, or a segmentation violation to call instructions in non-executable memory?  I don't know :-)</div><div class="gmail_default" style="font-size:small"></div><div class="gmail_default" style="font-size:small">Note that platforms/Cross/plugins/IA32ABI/riscv64abicc.c:allocateExecutablePage does the work.  SO putting a breakpoint in that and checking that the call to mprotect succeeds is a first step.  (And I would delete all the alternative guff for defined(MAP_JIT) & defined(_MSC_VER) || defined(__MINGW32__) unless RISCV is actually being used for MacOS or win32.  So I guess that means just delete the defined(MAP_JIT)<span class="gmail-Apple-converted-space"> option.</span></div><div class="gmail_default" style="font-size:small"><span class="gmail-Apple-converted-space"><br></span></div><div class="gmail_default" style="font-size:small"><span class="gmail-Apple-converted-space">And note that the first thunk allocated should be towards the start of the first result of </span>allocateExecutablePage.  So</div><div class="gmail_default" style="font-size:small">- put a breakpoint in allocateExecutablePage</div><div class="gmail_default" style="font-size:small">- run until that is hit, "finish" and see what it returns.</div><div class="gmail_default" style="font-size:small">- put a breakpoint in the FFI callout</div><div class="gmail_default" style="font-size:small">- continue</div><div class="gmail_default" style="font-size:small">- now you're at a breakpoint in the callout and you know the address of the first allocateExecutablePage, so you can disassemble at that address and check if the thunk code looks correct and set a breakpoint in it if you want to step through thunk invocation</div><div class="gmail_default" style="font-size:small"><span class="gmail-Apple-converted-space"><br></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
   [B] RiscV64 is little-endian.  Are the bytes correctly ordered?<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">You'll be able to tell by disassembling a thunk. e.g.</div><div class="gmail_default" style="font-size:small">gdb$ x/10i 0x12345678</div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
   [C] Is the math right for accessing the primEntryThunkAddress at <br>
thunkStart+0x28 ?<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">You'll have to work that out yourself.</div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Any help appreciated.<br>
<br>
Thanks a bunch,<br>
-KenD<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">HTH</div></div><div><br></div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div>