@@ -27,14 +27,10 @@ import Swift
27
27
public struct Backtrace : CustomStringConvertible , Sendable {
28
28
/// The type of an address.
29
29
///
30
- /// This will be `UInt32` or `UInt64` on current platforms.
31
- #if arch(x86_64) || arch(arm64)
32
- public typealias Address = UInt64
33
- #elseif arch(i386) || arch(arm)
34
- public typealias Address = UInt32
35
- #else
36
- #error("You need to fill this in for your architecture.")
37
- #endif
30
+ /// This is intentionally _not_ a pointer, because you shouldn't be
31
+ /// dereferencing them; they may refer to some other process, for
32
+ /// example.
33
+ public typealias Address = UInt
38
34
39
35
/// The unwind algorithm to use.
40
36
public enum UnwindAlgorithm {
@@ -55,20 +51,27 @@ public struct Backtrace: CustomStringConvertible, Sendable {
55
51
56
52
/// Represents an individual frame in a backtrace.
57
53
public enum Frame : CustomStringConvertible , Sendable {
58
- /// An accurate program counter.
54
+ /// A program counter value .
59
55
///
60
56
/// This might come from a signal handler, or an exception or some
61
57
/// other situation in which we have captured the actual program counter.
58
+ ///
59
+ /// These can be directly symbolicated, as-is, with no adjustment.
62
60
case programCounter( Address )
63
61
64
62
/// A return address.
65
63
///
66
64
/// Corresponds to a normal function call.
65
+ ///
66
+ /// Requires adjustment when symbolicating for a backtrace, because it
67
+ /// points at the address after the one that triggered the child frame.
67
68
case returnAddress( Address )
68
69
69
70
/// An async resume point.
70
71
///
71
72
/// Corresponds to an `await` in an async task.
73
+ ///
74
+ /// Can be directly symbolicated, as-is.
72
75
case asyncResumePoint( Address )
73
76
74
77
/// Indicates a discontinuity in the backtrace.
@@ -174,7 +177,7 @@ public struct Backtrace: CustomStringConvertible, Sendable {
174
177
///
175
178
/// Some backtracing algorithms may require this information, in which case
176
179
/// it will be filled in by the `capture()` method. Other algorithms may
177
- /// not, in which case it will be empty and you can capture an image list
180
+ /// not, in which case it will be `nil` and you can capture an image list
178
181
/// separately yourself using `captureImages()`.
179
182
public var images : [ Image ] ?
180
183
@@ -249,7 +252,7 @@ public struct Backtrace: CustomStringConvertible, Sendable {
249
252
. dropFirst ( offset)
250
253
251
254
if let limit = limit {
252
- if limit = = 0 {
255
+ if limit < = 0 {
253
256
return Backtrace ( frames: [ . truncated] )
254
257
}
255
258
@@ -356,7 +359,7 @@ public struct Backtrace: CustomStringConvertible, Sendable {
356
359
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
357
360
let task = process as! task_t
358
361
359
- withDyldProcessInfo ( for: task) { dyldInfo in
362
+ withDyldProcessInfo ( for: task) { dyldInfo in
360
363
_dyld_process_info_for_each_image ( dyldInfo) {
361
364
( machHeaderAddress, uuid, path) in
362
365
@@ -375,7 +378,7 @@ public struct Backtrace: CustomStringConvertible, Sendable {
375
378
// Find the end of the __TEXT segment
376
379
var endOfText = machHeaderAddress + 4096
377
380
378
- _dyld_process_info_for_each_segment ( dyldInfo, machHeaderAddress) {
381
+ _dyld_process_info_for_each_segment ( dyldInfo, machHeaderAddress) {
379
382
address, size, name in
380
383
381
384
if let name = String ( validatingUTF8: name!) , name == " __TEXT " {
@@ -386,8 +389,8 @@ public struct Backtrace: CustomStringConvertible, Sendable {
386
389
images. append ( Image ( name: name,
387
390
path: pathString,
388
391
buildID: theUUID,
389
- baseAddress: machHeaderAddress,
390
- endOfText: endOfText) )
392
+ baseAddress: Address ( machHeaderAddress) ,
393
+ endOfText: Address ( endOfText) ) )
391
394
}
392
395
}
393
396
}
@@ -411,15 +414,15 @@ public struct Backtrace: CustomStringConvertible, Sendable {
411
414
public static func captureSharedCacheInfo( for t: Any ) -> SharedCacheInfo ? {
412
415
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
413
416
let task = t as! task_t
414
- return withDyldProcessInfo ( for: task) { dyldInfo in
417
+ return withDyldProcessInfo ( for: task) { dyldInfo in
415
418
var cacheInfo = dyld_process_cache_info ( )
416
419
_dyld_process_info_get_cache ( dyldInfo, & cacheInfo)
417
- let theUUID = withUnsafePointer ( to: cacheInfo. cacheUUID) {
420
+ let theUUID = withUnsafePointer ( to: cacheInfo. cacheUUID) {
418
421
Array ( UnsafeRawBufferPointer ( start: $0,
419
422
count: MemoryLayout< uuid_t> . size) )
420
423
}
421
424
return SharedCacheInfo ( uuid: theUUID,
422
- baseAddress: cacheInfo. cacheBaseAddress,
425
+ baseAddress: Address ( cacheInfo. cacheBaseAddress) ,
423
426
noCache: cacheInfo. noCache)
424
427
}
425
428
#else // !os(Darwin)
0 commit comments