<div dir="ltr">Using the OS atomic cmp/swp works (step over/into does not go into infinite loop):<div><br></div><div><div>#include <libkern/OSAtomic.h></div><div><br></div><div>int main(int argc, char * argv[]) {</div><div> int c = 0;</div><div> while(1) {</div><div> if(OSAtomicCompareAndSwap32(0, 1, &c)) {</div><div> break;</div><div> }</div><div> }</div><div> printf("%d\n", c);</div><div>}</div></div><div><br></div><div>This means we have a fix for our use case, but i assume that others may use the intrinsic and be surprised at LLDB's behaviour.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 11, 2014 at 10:38 AM, Mario Zechner <span dir="ltr"><<a href="mailto:badlogicgames@gmail.com" target="_blank">badlogicgames@gmail.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>we are running into a problem with the __sync_bool_compare_and_swap intrinsic on ARM. Trying to step over the call to __sync_bool_compare_and_swap will put LLDB into a sort of infinite loop.</div><div><br></div><div>This is reproduceable in the latest XCode (6.1.1 (6A2008a)). Create an iOS project with the following main function:</div><div><br></div><div><div>int main(int argc, char * argv[]) {</div><div> int c = 0;</div><div> while(1) {</div><div> if(__sync_bool_compare_and_swap(&c, 0, 1)) {</div><div> break;</div><div> }</div><div> }</div><div> printf("%d\n", c);</div><div>}</div></div><div><br></div><div>The intrinsic compiles down to:<br></div><div><br></div><div><div> 0xb7010: dmb ish</div><div> 0xb7014: movs r0, #0x1</div><div> 0xb7016: movs r1, #0x0</div><div> 0xb7018: add r2, sp, #0x14</div><div> 0xb701a: str r0, [sp, #0x10]</div><div> 0xb701c: str r1, [sp, #0xc]</div><div> 0xb701e: str r2, [sp, #0x8]</div><div>-> 0xb7020: ldr r0, [sp, #0x8]</div><div> 0xb7022: ldrex r1, [r0]</div><div> 0xb7026: ldr r2, [sp, #0xc]</div><div> 0xb7028: cmp r1, r2</div><div> 0xb702a: str r1, [sp, #0x4]</div><div> 0xb702c: bne 0xb703a ; main + 62 at main.m:15</div><div> 0xb702e: ldr r1, [sp, #0x10]</div><div> 0xb7030: ldr r2, [sp, #0x8]</div><div> 0xb7032: strex r0, r1, [r2]</div><div> 0xb7036: cmp r0, #0x0</div><div> 0xb7038: bne 0xb7020 ; main + 36 at main.m:15</div><div> 0xb703a: dmb ish</div></div><div><br></div><div>When stepping over, LLDB will first set a breakpoint on 0xb702c: bne 0xb703a. Next it executes a single step, moving PC to 0xb702e: ldr r1, [sp, #0x10] as the condition is not meet.</div><div><br></div><div>LLDB then sets a breakpoint on the next branch instruction at 0xb7038: bne 0xb7020. It single steps the instruction, the condition is meet, and we end up at 0xb7020 again.</div><div><br></div><div>The code never breaks out of this loop, LLDB will continue to set the breakpoints indefinitely.</div><div><br></div><div>Any idea how to fix this?</div><div><br></div><div>Thanks,</div><div>Mario</div>
</div>
</blockquote></div></div>