Skip to content

Commit 4c47540

Browse files
committed
[Backtracer][macOS] Fix crashing thread index when Rosetta is in use.
If you're using Rosetta 2, there are ARM64 threads in your process as well, which the backtracer skips. Unfortunately doing that messed up the crashing thread index, so the backtracer might have crashed or told you that a different thread was crashing than the one you thought. This only affects running x86-64 code on an Apple Silicon Mac. rdar://135787913
1 parent 4bdf601 commit 4c47540

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

stdlib/public/libexec/swift-backtrace/TargetMacOS.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,12 @@ class Target {
249249

250250
if info.thread_id == crashingThread {
251251
ctx = HostContext.fromHostMContext(mcontext)
252-
crashingThreadNdx = Int(ndx)
252+
crashingThreadNdx = threads.count
253253
} else {
254254
guard let threadCtx = HostContext.fromHostThread(ports[Int(ndx)]) else {
255255
// This can happen legitimately, e.g. when looking at a Rosetta 2
256256
// process, where there are ARM64 threads AS WELL AS the x86_64 ones.
257+
mach_port_deallocate(mach_task_self_, ports[Int(ndx)])
257258
continue
258259
}
259260
ctx = threadCtx

0 commit comments

Comments
 (0)