Skip to content

Commit ccc646e

Browse files
authored
Merge pull request #67429 from al45tair/eng/PR-112534548
2 parents 8091744 + c3b925c commit ccc646e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

stdlib/public/Backtracing/Elf.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,11 @@ class ElfImage<SomeImageSource: ImageSource,
16801680
done = true
16811681
}
16821682

1683-
prevState = state
1683+
if state.endSequence {
1684+
prevState = nil
1685+
} else {
1686+
prevState = state
1687+
}
16841688
}
16851689
}
16861690

stdlib/public/Backtracing/FramePointerUnwinder.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public struct FramePointerUnwinder<C: Context, M: MemoryReader>: Sequence, Itera
2727
var asyncContext: Address
2828
var first: Bool
2929
var isAsync: Bool
30+
var done: Bool
3031

3132
#if os(Linux)
3233
var elf32Cache: [Int:Elf32Image<FileImageSource>] = [:]
@@ -44,6 +45,7 @@ public struct FramePointerUnwinder<C: Context, M: MemoryReader>: Sequence, Itera
4445
fp = Address(context.framePointer)
4546
first = true
4647
isAsync = false
48+
done = false
4749
asyncContext = 0
4850
reader = memoryReader
4951

@@ -134,6 +136,10 @@ public struct FramePointerUnwinder<C: Context, M: MemoryReader>: Sequence, Itera
134136
}
135137

136138
public mutating func next() -> Backtrace.Frame? {
139+
if done {
140+
return nil
141+
}
142+
137143
if first {
138144
first = false
139145
pc = stripPtrAuth(pc)
@@ -149,6 +155,7 @@ public struct FramePointerUnwinder<C: Context, M: MemoryReader>: Sequence, Itera
149155
if strippedFp == 0
150156
|| !Context.isAlignedForStack(framePointer:
151157
Context.Address(strippedFp)) {
158+
done = true
152159
return nil
153160
}
154161

@@ -158,10 +165,12 @@ public struct FramePointerUnwinder<C: Context, M: MemoryReader>: Sequence, Itera
158165
as: Address.self))
159166
next = try reader.fetch(from: Address(strippedFp), as: Address.self)
160167
} catch {
168+
done = true
161169
return nil
162170
}
163171

164172
if next <= fp || pc == 0 {
173+
done = true
165174
return nil
166175
}
167176

@@ -173,6 +182,7 @@ public struct FramePointerUnwinder<C: Context, M: MemoryReader>: Sequence, Itera
173182

174183
isAsync = true
175184
if !fetchAsyncContext() {
185+
done = true
176186
return nil
177187
}
178188
}
@@ -183,6 +193,7 @@ public struct FramePointerUnwinder<C: Context, M: MemoryReader>: Sequence, Itera
183193
let strippedCtx = stripPtrAuth(asyncContext)
184194

185195
if strippedCtx == 0 {
196+
done = true
186197
return nil
187198
}
188199

@@ -197,6 +208,7 @@ public struct FramePointerUnwinder<C: Context, M: MemoryReader>: Sequence, Itera
197208
next = Address(next32)
198209
pc = stripPtrAuth(Address(pc32))
199210
} catch {
211+
done = true
200212
return nil
201213
}
202214
#else
@@ -206,6 +218,7 @@ public struct FramePointerUnwinder<C: Context, M: MemoryReader>: Sequence, Itera
206218
next = try reader.fetch(from: strippedCtx, as: Address.self)
207219
pc = stripPtrAuth(try reader.fetch(from: strippedCtx + 8, as: Address.self))
208220
} catch {
221+
done = true
209222
return nil
210223
}
211224

0 commit comments

Comments
 (0)