Commit 384f280
committed
[lldb] Change swift unwind heuristic for Q funclets
Q funclets have an ambiguity region where the debugger doesn't know what
the meaning of the x22 register is. Today, it works around this by
sacrificing the ability to unwind recursive async functions. This patch
changes the heuristic to, instead, sacrifice unwinding in a few
instructions after the prologue, and before any branches. Such
instructions should never be hit in the course of stepping or setting
breakpoints, a user would need to go out of their way to stop in one of
them.
The new approach is:
1. If we are inside the prologue, or the first instruction after the
prologue, assume x22 contains the indirect context.
2. Otherwise, assume it is the direct context.
This approach fails for the few instructions shown below.
This is what the assembly looks like for Q funclets in x86, with the
first non-prologue instruction indicated by the arrow:
```
0x100004140 <+0>: orq 0x3ee9(%rip), %rbp ; (void *)0x1000000000000000
0x100004147 <+7>: pushq %rbp
0x100004148 <+8>: pushq %r14
0x10000414a <+10>: leaq 0x8(%rsp), %rbp
0x10000414f <+15>: subq $0x38, %rsp
-> 0x100004153 <+19>: movq (%r14), %rax
0x100004156 <+22>: movq %rax, -0x30(%rbp) << Fail zone start, inclusive
0x10000415a <+26>: movq %rbp, %rcx
0x10000415d <+29>: subq $0x8, %rcx
0x100004161 <+33>: movq %rax, (%rcx) << Fail zone end, inclusive
0x100004164 <+36>: movq 0x50(%rax), %rdi
0x100004168 <+40>: movq (%r14), %rcx
0x10000416b <+43>: movq %rbp, %rdx
0x10000416e <+46>: subq $0x8, %rdx
0x100004172 <+50>: movq %rcx, (%rdx)
0x100004175 <+53>: movq %rcx, 0x30(%rax)
0x100004179 <+57>: callq 0x100006036 ; symbol stub for: swift_task_dealloc
...
```
The same assembly for arm:
```
0x100000c54 <+0>: orr x29, x29, #0x1000000000000000
0x100000c58 <+4>: sub sp, sp, #0x40
0x100000c5c <+8>: stp x29, x30, [sp, #0x30]
0x100000c60 <+12>: str x22, [sp, #0x28]
0x100000c64 <+16>: add x29, sp, #0x30
-> 0x100000c68 <+20>: ldr x9, [x22]
0x100000c6c <+24>: str x9, [sp] << Fail zone start, inclusive
0x100000c70 <+28>: mov x8, x29
0x100000c74 <+32>: sub x8, x8, #0x8
0x100000c78 <+36>: str x9, [x8] << Fail zone end, inclusive
0x100000c7c <+40>: ldr x0, [x9, #0x50]
0x100000c80 <+44>: ldr x8, [x22]
0x100000c84 <+48>: mov x10, x29
0x100000c88 <+52>: sub x10, x10, #0x8
0x100000c8c <+56>: str x8, [x10]
0x100000c90 <+60>: str x8, [x9, #0x30]
0x100000c94 <+64>: bl 0x100001cf4 ; symbol stub for: swift_task_dealloc
...
```
As a result, TestSwiftAsyncUnwindAllInstructions.py was changed to
accept failure in those regions. A new test is added, showcasing a step
operation that previously failed because of bad unwinding; it sets a
breakpoint in a Q funclet and then step over. This is _not_ an
artificially created situation, as a `step out` operation always takes
the user to a Q funclet; being able to step-over from that point is
crucial.1 parent 745ab81 commit 384f280
File tree
5 files changed
+152
-20
lines changed- lldb
- source/Plugins/LanguageRuntime/Swift
- test/API/lang/swift/async/unwind
- unwind_in_all_instructions
- unwind_recursive_q_funclets
5 files changed
+152
-20
lines changedLines changed: 18 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2559 | 2559 | | |
2560 | 2560 | | |
2561 | 2561 | | |
2562 | | - | |
2563 | | - | |
2564 | | - | |
2565 | | - | |
2566 | | - | |
| 2562 | + | |
| 2563 | + | |
| 2564 | + | |
2567 | 2565 | | |
2568 | 2566 | | |
2569 | | - | |
2570 | | - | |
| 2567 | + | |
2571 | 2568 | | |
2572 | 2569 | | |
2573 | 2570 | | |
2574 | 2571 | | |
2575 | | - | |
2576 | | - | |
2577 | | - | |
2578 | | - | |
2579 | | - | |
2580 | | - | |
2581 | | - | |
2582 | | - | |
2583 | | - | |
2584 | | - | |
2585 | | - | |
2586 | | - | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
| 2577 | + | |
| 2578 | + | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
2587 | 2585 | | |
2588 | 2586 | | |
2589 | 2587 | | |
| |||
2653 | 2651 | | |
2654 | 2652 | | |
2655 | 2653 | | |
2656 | | - | |
| 2654 | + | |
2657 | 2655 | | |
2658 | 2656 | | |
2659 | 2657 | | |
| |||
Lines changed: 73 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
65 | 136 | | |
| 137 | + | |
| 138 | + | |
66 | 139 | | |
67 | 140 | | |
68 | 141 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
Lines changed: 44 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments