<div dir="ltr">I applied both patches, and the 'expr (int)printf("blah\n")' statement now works, but "n" over the printf() statement in the code still throws me somewhere else entirely. I'm on the call printf() asm instruction down below, I type "ni", and I wind up at address 0x80486f0.<div>
<br></div><div>Is this working for you?</div><div><br></div><div>And thanks for looking at this Andrew. Very cool we can call functions now in 32-bit targets...</div><div> -Mike</div><div><div class="gmail_extra"><br></div>
<div class="gmail_extra"><div class="gmail_extra">(lldb) ni</div><div class="gmail_extra">Process 18815 stopped</div><div class="gmail_extra">* thread #1: tid = 0x497f, 0x08048855 blah`main(argc=1, argv=0xff985674) + 37 at blah.cpp:29, name = 'blah, stop reason = instruction step over</div>
<div class="gmail_extra"> frame #0: 0x08048855 blah`main(argc=1, argv=0xff985674) + 37 at blah.cpp:29</div><div class="gmail_extra"> 26 </div><div class="gmail_extra"> 27 int main( int argc, char *argv[] )</div>
<div class="gmail_extra"> 28 {</div><div class="gmail_extra">-> 29 printf("hello world.\n");</div><div class="gmail_extra"> 30 </div><div class="gmail_extra"> 31 Set *foo = new Set();</div>
<div class="gmail_extra"> 32 </div><div class="gmail_extra">(lldb) disassemble </div><div class="gmail_extra">blah`main at blah.cpp:28:</div><div class="gmail_extra"> 0x8048830: push EBP</div><div class="gmail_extra">
0x8048831: mov EBP, ESP</div><div class="gmail_extra"> 0x8048833: push ESI</div><div class="gmail_extra"> 0x8048834: sub ESP, 32820</div><div class="gmail_extra"> 0x804883a: mov EAX, DWORD PTR [EBP + 12]</div>
<div class="gmail_extra"> 0x804883d: mov ECX, DWORD PTR [EBP + 8]</div><div class="gmail_extra"> 0x8048840: mov DWORD PTR [EBP - 8], 0</div><div class="gmail_extra"> 0x8048847: mov DWORD PTR [EBP - 12], ECX</div>
<div class="gmail_extra"> 0x804884a: mov DWORD PTR [EBP - 16], EAX</div><div class="gmail_extra"> 0x804884d: mov EAX, ESP</div><div class="gmail_extra"> 0x804884f: mov DWORD PTR [EAX], 134515168</div><div class="gmail_extra">
-> 0x8048855: call 0x80486f0</div><div class="gmail_extra"> 0x804885a: mov ECX, ESP</div><div class="gmail_extra"> 0x804885c: mov DWORD PTR [ECX], 1</div><div class="gmail_extra"> 0x8048862: mov DWORD PTR [EBP - 32804], EAX</div>
<div class="gmail_extra"> 0x8048868: call 0x8048700</div><div class="gmail_extra"> 0x804886d: mov ECX, EAX</div><div class="gmail_extra"> 0x804886f: mov EDX, EAX</div><div class="gmail_extra"> 0x8048871: mov ESI, ESP</div>
<div class="gmail_extra"> 0x8048873: mov DWORD PTR [ESI], EAX</div><div class="gmail_extra"> 0x8048875: mov DWORD PTR [EBP - 32808], EDX</div><div class="gmail_extra"> 0x804887b: mov DWORD PTR [EBP - 32812], ECX</div>
<div class="gmail_extra"> 0x8048881: call 0x8048800 ; Set at blah.cpp:23</div><div class="gmail_extra"> 0x8048886: jmp 0x804888b ; main + 91 at blah.cpp:31</div><div class="gmail_extra">
0x804888b: mov EAX, DWORD PTR [EBP - 32812]</div><div class="gmail_extra"> 0x8048891: mov DWORD PTR [EBP - 20], EAX</div><div class="gmail_extra"> 0x8048894: mov DWORD PTR [EBP - 32800], 0</div><div class="gmail_extra">
0x804889e: cmp DWORD PTR [EBP - 32800], 8192</div><div class="gmail_extra"> 0x80488a8: jae 0x80488ef ; main + 191 at blah.cpp:38</div><div class="gmail_extra"> 0x80488ae: call 0x8048710</div>
<div class="gmail_extra"> 0x80488b3: mov ECX, DWORD PTR [EBP - 32800]</div><div class="gmail_extra"> 0x80488b9: mov DWORD PTR [EBP + 4*ECX - 32796], EAX</div><div class="gmail_extra"> 0x80488c0: mov EAX, DWORD PTR [EBP - 32800]</div>
<div class="gmail_extra"> 0x80488c6: add EAX, 1</div><div class="gmail_extra"> 0x80488cb: mov DWORD PTR [EBP - 32800], EAX</div><div class="gmail_extra"> 0x80488d1: jmp 0x804889e ; main + 110 at blah.cpp:34</div>
<div class="gmail_extra"> 0x80488d6: mov DWORD PTR [EBP - 24], EAX</div><div class="gmail_extra"> 0x80488d9: mov DWORD PTR [EBP - 28], EDX</div><div class="gmail_extra"> 0x80488dc: mov EAX, DWORD PTR [EBP - 32808]</div>
<div class="gmail_extra"> 0x80488e2: mov DWORD PTR [ESP], EAX</div><div class="gmail_extra"> 0x80488e5: call 0x80486d0 ; symbol stub for: _Unwind_Resume</div><div class="gmail_extra"> 0x80488ea: jmp 0x80488fb ; main + 203 at blah.cpp:31</div>
<div class="gmail_extra"> 0x80488ef: mov EAX, DWORD PTR [EBP - 8]</div><div class="gmail_extra"> 0x80488f2: add ESP, 32820</div><div class="gmail_extra"> 0x80488f8: pop ESI</div><div class="gmail_extra">
0x80488f9: pop EBP</div><div class="gmail_extra"> 0x80488fa: ret </div><div class="gmail_extra"> 0x80488fb: mov EAX, DWORD PTR [EBP - 24]</div><div class="gmail_extra"> 0x80488fe: mov DWORD PTR [ESP], EAX</div>
<div class="gmail_extra"> 0x8048901: call 0x8048730</div><div class="gmail_extra">(lldb) ni</div><div class="gmail_extra">Process 18815 stopped</div><div class="gmail_extra">* thread #1: tid = 0x497f, 0x080486f0 blah, name = 'blah, stop reason = instruction step over</div>
<div class="gmail_extra"> frame #0: 0x080486f0 blah</div><div class="gmail_extra">-> 0x80486f0: jmp DWORD PTR [134520844]</div><div class="gmail_extra"> 0x80486f6: push 24</div><div class="gmail_extra"> 0x80486fb: jmp 0x80486b0 ; blah..plt + 0</div>
<div class="gmail_extra"> 0x8048700: jmp DWORD PTR [134520848]</div><div><br></div></div><div class="gmail_extra"><div class="gmail_quote">On Fri, Jul 19, 2013 at 3:34 PM, Kaylor, Andrew <span dir="ltr"><<a href="mailto:andrew.kaylor@intel.com" target="_blank">andrew.kaylor@intel.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Hi Mike,<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I think I’ve tracked down the sources of both of these problems.<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">The problem with not being able to call functions in the target seems to be a failure in the MCJIT relocation mechanism. Because LLDB is generating IR with
absolute addresses for function calls, the JITed code contains relocations with absolute values rather than symbols. This is a problem I fixed a short time ago, but it seems to have come undone again (at least in this particular case). The attached ‘reloc-fix-32.patch’
(to be applied to the LLVM repository) should fix that.<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I need to do a bit of investigation to settle some questions about why this condition came back or was specific to the 32-bit case before I commit this, but
I think this is correct.<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">The problem where you lose source after stepping seems to be a matter of incorrect stack unwinding. There were two problems lurking here.<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">First, the RegisterContext::ConvertBetweenRegisterKinds() function wasn’t making any provision for a 32-bit inferior running on a 64-bit target. The way the
x86-64 register context class is implemented it defines 64-bit registers and 32-bit registers in the same RegisterInfo structure, and there is some overlap in how these get mapped to DWARF/GDB/GCC register numbers. RegisterContext::ConvertBetweenRegisterKinds()
was just iterating through the list and returning the first match it found, which was the 64-bit register.<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I added a special case to call RegisterContext::ConvertRegisterKindToRegisterNumber() when the target kind is eRegisterKindLLDB. This invokes the RegisterContext_x86_64
overload of that method which knows how to distinguish the 32-bit and 64-bit registers. I’m not convinced that this is the best way to solve this problem, but it works.<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">The second issue was that the ABIMacOSX_i386 plug-in (which also gets used for 32-bit inferiors on Linux) was rejecting call frame addresses that weren’t 8-byte
aligned whereas, at least on Linux, 4-byte alignment is allowed. If 32-bit processes on MacOSX require 8-byte alignment then we’ll need to do some additional checking, but for now I just modified it to only check for 4-byte alignment.<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Both of the stack unwinding issues should be fixed by the attached ‘stack-fix-32.patch’ file.<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Can you try out these patches and verify that they work for you?<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Thanks,<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Andy<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><b><span style="font-size:10pt;font-family:Tahoma,sans-serif">From:</span></b><span style="font-size:10pt;font-family:Tahoma,sans-serif"> Michael Sartain [mailto:<a href="mailto:mikesart@gmail.com" target="_blank">mikesart@gmail.com</a>]
<br></span></p><div class="im">
<b>Sent:</b> Tuesday, July 16, 2013 6:14 PM<br>
<b>To:</b> Malea, Daniel; Kaylor, Andrew; Kopec, Matt; Thirumurthi, Ashok<br>
<b>Cc:</b> Matthew Sorrels<br>
</div><b>Subject:</b> Fwd: lldb test failures on 32bit<u></u><u></u><p></p><div><div class="h5">
<p class=""><u></u> <u></u></p>
<div>
<div>
<p class="">I think the below are the largest 32-bit blocking issues right now.<u></u><u></u></p>
</div>
<div>
<p class=""><u></u> <u></u></p>
</div>
<div>
<p class="">Is this something any of you have any familiarity with and have time to look at?<u></u><u></u></p>
</div>
<div>
<p class=""><u></u> <u></u></p>
</div>
<div>
<p class="">If not, let me know and I'll start investigating...<u></u><u></u></p>
</div>
<div>
<p class=""><u></u> <u></u></p>
</div>
<div>
<p class="">Thanks much!<u></u><u></u></p>
</div>
<div>
<p class=""> -Mike<u></u><u></u></p>
</div>
<div>
<p class=""><u></u> <u></u></p>
</div>
<div>
<p class="">#################################<u></u><u></u></p>
</div>
<div>
<p class="">## Can't call functions in target<u></u><u></u></p>
</div>
<div>
<p class="">#################################<u></u><u></u></p>
</div>
<div>
<p class="">mikesart@mikesart-rad:~/data/src/blah2/build$ lldb -x -- blah<u></u><u></u></p>
</div>
<div>
<p class="">Current executable set to 'blah' (i386).<u></u><u></u></p>
</div>
<div>
<p class="">(lldb) b main<u></u><u></u></p>
</div>
<div>
<p class="">Breakpoint 1: where = blah`main + 29 at blah.cpp:29, address = 0x0804884d<u></u><u></u></p>
</div>
<div>
<p class="">(lldb) r<u></u><u></u></p>
</div>
<div>
<p class="">Process 6745 launched: '/home/mikesart/data/src/blah2/build/blah' (i386)<u></u><u></u></p>
</div>
<div>
<p class="">Process 6745 stopped<u></u><u></u></p>
</div>
<div>
<p class="">* thread #1: tid = 0x1a59, 0x0804884d blah`main(argc=1, argv=0xfffc8c54) + 29 at blah.cpp:29, name = 'blah, stop reason = breakpoint 1.1<u></u><u></u></p>
</div>
<div>
<p class=""> frame #0: 0x0804884d blah`main(argc=1, argv=0xfffc8c54) + 29 at blah.cpp:29<u></u><u></u></p>
</div>
<div>
<p class=""> 26 <u></u><u></u></p>
</div>
<div>
<p class=""> 27 int main( int argc, char *argv[] )<u></u><u></u></p>
</div>
<div>
<p class=""> 28 {<u></u><u></u></p>
</div>
<div>
<p class="">-> 29 printf("hello world.\n");<u></u><u></u></p>
</div>
<div>
<p class=""> 30 <u></u><u></u></p>
</div>
<div>
<p class=""> 31 Set *foo = new Set();<u></u><u></u></p>
</div>
<div>
<p class=""> 32 <u></u><u></u></p>
</div>
<div>
<p class="">(lldb) expr (int)printf("hi there!\n");<u></u><u></u></p>
</div>
<div>
<p class="">error: Execution was interrupted, reason: invalid address (fault address: 0xeef60020).<u></u><u></u></p>
</div>
<div>
<p class="">The process has been returned to the state before expression evaluation.<u></u><u></u></p>
</div>
<div>
<p class="">(lldb) n<u></u><u></u></p>
</div>
<div>
<p class="">Process 6745 exited with status = -1 (0xffffffff) <u></u><u></u></p>
</div>
<div>
<p class=""><u></u> <u></u></p>
</div>
<div>
<p class="">#################################<u></u><u></u></p>
</div>
<div>
<p class="">## Lose source with first next command<u></u><u></u></p>
</div>
<div>
<p class="">#################################<u></u><u></u></p>
</div>
<div>
<p class="">mikesart@mikesart-rad:~/data/src/blah2/build$ lldb -x -- blah<u></u><u></u></p>
</div>
<div>
<div>
<p class="">Current executable set to 'blah' (i386).<u></u><u></u></p>
</div>
<div>
<p class="">(lldb) b main<u></u><u></u></p>
</div>
<div>
<p class="">Breakpoint 1: where = blah`main + 29 at blah.cpp:29, address = 0x0804884d<u></u><u></u></p>
</div>
<div>
<p class="">(lldb) r<u></u><u></u></p>
</div>
<div>
<p class="">Process 7471 launched: '/home/mikesart/data/src/blah2/build/blah' (i386)<u></u><u></u></p>
</div>
<div>
<p class="">Process 7471 stopped<u></u><u></u></p>
</div>
<div>
<p class="">* thread #1: tid = 0x1d2f, 0x0804884d blah`main(argc=1, argv=0xffb36464) + 29 at blah.cpp:29, name = 'blah, stop reason = breakpoint 1.1<u></u><u></u></p>
</div>
<div>
<p class=""> frame #0: 0x0804884d blah`main(argc=1, argv=0xffb36464) + 29 at blah.cpp:29<u></u><u></u></p>
</div>
<div>
<p class=""> 26 <u></u><u></u></p>
</div>
<div>
<p class=""> 27 int main( int argc, char *argv[] )<u></u><u></u></p>
</div>
<div>
<p class=""> 28 {<u></u><u></u></p>
</div>
<div>
<p class="">-> 29 printf("hello world.\n");<u></u><u></u></p>
</div>
<div>
<p class=""> 30 <u></u><u></u></p>
</div>
<div>
<p class=""> 31 Set *foo = new Set();<u></u><u></u></p>
</div>
<div>
<p class=""> 32 <u></u><u></u></p>
</div>
<div>
<p class="">(lldb) n<u></u><u></u></p>
</div>
<div>
<p class="">Process 7471 stopped<u></u><u></u></p>
</div>
<div>
<p class="">* thread #1: tid = 0x1d2f, 0x080486f0 blah, name = 'blah, stop reason = step over<u></u><u></u></p>
</div>
<div>
<p class=""> frame #0: 0x080486f0 blah<u></u><u></u></p>
</div>
<div>
<p class="">-> 0x80486f0: jmpl *134520844<u></u><u></u></p>
</div>
<div>
<p class=""> 0x80486f6: pushl $24<u></u><u></u></p>
</div>
<div>
<p class=""> 0x80486fb: jmp 0x80486b0 ; blah..plt + 0<u></u><u></u></p>
</div>
<div>
<p class=""> 0x8048700: jmpl *134520848<u></u><u></u></p>
</div>
<div>
<p class="">(lldb) <u></u><u></u></p>
</div>
</div>
</div>
</div></div></div>
</div>
</blockquote></div><br></div></div></div>