[lldb-dev] Can't step over __sync_bool_compare_and_swap on ARM
Greg Clayton
gclayton at apple.com
Thu Dec 11 11:25:43 PST 2014
Does this work if you first type:
(lldb) setting set target.use-fast-stepping false
Then step?
> On Dec 11, 2014, at 1:38 AM, Mario Zechner <badlogicgames at gmail.com> wrote:
>
> Hi,
>
> 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.
>
> This is reproduceable in the latest XCode (6.1.1 (6A2008a)). Create an iOS project with the following main function:
>
> int main(int argc, char * argv[]) {
> int c = 0;
> while(1) {
> if(__sync_bool_compare_and_swap(&c, 0, 1)) {
> break;
> }
> }
> printf("%d\n", c);
> }
>
> The intrinsic compiles down to:
>
> 0xb7010: dmb ish
> 0xb7014: movs r0, #0x1
> 0xb7016: movs r1, #0x0
> 0xb7018: add r2, sp, #0x14
> 0xb701a: str r0, [sp, #0x10]
> 0xb701c: str r1, [sp, #0xc]
> 0xb701e: str r2, [sp, #0x8]
> -> 0xb7020: ldr r0, [sp, #0x8]
> 0xb7022: ldrex r1, [r0]
> 0xb7026: ldr r2, [sp, #0xc]
> 0xb7028: cmp r1, r2
> 0xb702a: str r1, [sp, #0x4]
> 0xb702c: bne 0xb703a ; main + 62 at main.m:15
> 0xb702e: ldr r1, [sp, #0x10]
> 0xb7030: ldr r2, [sp, #0x8]
> 0xb7032: strex r0, r1, [r2]
> 0xb7036: cmp r0, #0x0
> 0xb7038: bne 0xb7020 ; main + 36 at main.m:15
> 0xb703a: dmb ish
>
> 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.
>
> 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.
>
> The code never breaks out of this loop, LLDB will continue to set the breakpoints indefinitely.
>
> Any idea how to fix this?
>
> Thanks,
> Mario
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
More information about the lldb-dev
mailing list