Commit 2d54a08
[lldb] [debugserver] Use "full" x86_64 GPR state when available. (llvm#108663)
macOS 10.15 added a "full" x86_64 GPR thread state flavor, equivalent to
the normal one but with DS, ES, SS, and GSbase added. This flavor can
only be used with processes that install a custom LDT (functionality
that was also added in 10.15 and is used by apps like Wine to execute
32-bit code).
Along with allowing DS, ES, SS, and GSbase to be viewed/modified, using
the full flavor is necessary when debugging a thread executing 32-bit
code.
If thread_set_state() is used with the regular thread state flavor, the
kernel resets CS to the 64-bit code segment (see
[set_thread_state64()](https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/osfmk/i386/pcb.c#L723),
which makes debugging impossible.
There's no way to detect whether the full flavor is available, try to
use it and fall back to the regular one if it's not available.
A downside is that this patch exposes the DS, ES, SS, and GSbase
registers for all x86_64 processes, even though they are not populated
unless the full thread state is available.
I'm not sure if there's a way to tell LLDB that a register is
unavailable. The classic GDB `g` command [allows returning
`x`](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Packets.html#Packets)
to denote unavailable registers, but it seems like the debug server uses
newer commands like `jThreadsInfo` and I'm not sure if those have the
same support.
Fixes llvm#57591
(also filed as Apple FB11464104)
@jasonmolenda
(cherry picked from commit 7281e0c)1 parent 3215fab commit 2d54a08
File tree
3 files changed
+61
-15
lines changed- lldb/tools/debugserver/source/MacOSX/x86_64
3 files changed
+61
-15
lines changedLines changed: 53 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
| 186 | + | |
186 | 187 | | |
187 | 188 | | |
188 | | - | |
| 189 | + | |
189 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
190 | 203 | | |
191 | 204 | | |
192 | | - | |
| 205 | + | |
193 | 206 | | |
194 | 207 | | |
195 | 208 | | |
196 | 209 | | |
197 | 210 | | |
198 | | - | |
199 | | - | |
200 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
201 | 218 | | |
202 | 219 | | |
203 | 220 | | |
| |||
208 | 225 | | |
209 | 226 | | |
210 | 227 | | |
211 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
212 | 231 | | |
213 | 232 | | |
214 | 233 | | |
| |||
459 | 478 | | |
460 | 479 | | |
461 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
462 | 485 | | |
463 | | - | |
464 | | - | |
| 486 | + | |
465 | 487 | | |
466 | | - | |
| 488 | + | |
467 | 489 | | |
468 | 490 | | |
469 | | - | |
| 491 | + | |
470 | 492 | | |
471 | 493 | | |
472 | 494 | | |
473 | 495 | | |
474 | 496 | | |
475 | | - | |
476 | | - | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
477 | 501 | | |
478 | 502 | | |
479 | 503 | | |
| |||
484 | 508 | | |
485 | 509 | | |
486 | 510 | | |
487 | | - | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
488 | 514 | | |
489 | 515 | | |
490 | 516 | | |
| |||
1157 | 1183 | | |
1158 | 1184 | | |
1159 | 1185 | | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
1160 | 1190 | | |
1161 | 1191 | | |
1162 | 1192 | | |
| |||
1543 | 1573 | | |
1544 | 1574 | | |
1545 | 1575 | | |
| 1576 | + | |
1546 | 1577 | | |
1547 | 1578 | | |
1548 | 1579 | | |
| |||
1690 | 1721 | | |
1691 | 1722 | | |
1692 | 1723 | | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
1693 | 1728 | | |
1694 | 1729 | | |
1695 | 1730 | | |
| |||
2313 | 2348 | | |
2314 | 2349 | | |
2315 | 2350 | | |
| 2351 | + | |
| 2352 | + | |
2316 | 2353 | | |
2317 | 2354 | | |
2318 | 2355 | | |
| |||
2524 | 2561 | | |
2525 | 2562 | | |
2526 | 2563 | | |
| 2564 | + | |
| 2565 | + | |
2527 | 2566 | | |
2528 | 2567 | | |
2529 | 2568 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| |||
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
48 | 53 | | |
49 | 54 | | |
50 | 55 | | |
| |||
0 commit comments