What's New / Storage, System & Virtualization

What's new in CrashReportExtension

+5 NewiOS · macOS

CrashReportExtension is for building app extensions that receive and process crash reports. The API exposes report contents: binary image metadata, the crash reason, and symbolicated stack frames.

The 27 SDK adds 5 types, with no deprecations or removals. The CrashReporterExtension protocol defines the extension entry point. Three structs carry report data: BinaryImageInfo, CrashReason, and SymbolicatedFrame.

New

5
struct

BinaryImageInfo

NewiOSmacOS
public struct BinaryImageInfo : Codable, Sendable

A type that represents a binary image loaded in the crashed process.

Declaration
public struct BinaryImageInfo : Codable, Sendable {

    /// The path to the binary image.
    public let path: String

    /// The UUID of the binary image.
    public let uuid: UUID?

    /// The base address of the binary image.
    public let baseAddress: UInt64

    /// The size of the binary image.
    public let size: UInt64

    /// The binary image's CPU type.
    public let cpuType: cpu_type_t

    /// The binary image's CPU subtype.
    public let cpuSubType: cpu_subtype_t

    /// Creates a binary image info instance.
    /// - Parameters:
    ///   - path: The path to the binary image.
    ///   - uuid: The UUID of the binary image.
    ///   - baseAddress: The base address of the binary image.
    ///   - size: The size of the binary image.
    ///   - cpuType: The binary image's CPU type.
    ///   - cpuSubType: The binary image's CPU subtype.
    public init(path: String, uuid: UUID?, baseAddress: UInt64, size: UInt64, cpuType: cpu_type_t, cpuSubType: cpu_subtype_t)

    /// Encodes this value into the given encoder.
    ///
    /// If the value fails to encode anything, `encoder` will encode an empty
    /// keyed container in its place.
    ///
    /// This function throws an error if any values are invalid for the given
    /// encoder's format.
    ///
    /// - Parameter encoder: The encoder to write data to.
    public func encode(to encoder: any Encoder) throws

    /// Creates a new instance by decoding from the given decoder.
    ///
    /// This initializer throws an error if reading from the decoder fails, or
    /// if the data read is corrupted or otherwise invalid.
    ///
    /// - Parameter decoder: The decoder to read data from.
    public init(from decoder: any Decoder) throws
}
struct

CrashReason

NewiOSmacOS
public struct CrashReason

Context information about the crash being reported

Declaration
public struct CrashReason {

    /// The Mach exception type.
    ///
    /// Possible values of this property include `EXC_BAD_ACCESS` and `EXC_CRASH`.
    public let exception: Int32

    /// An array of exception-specific codes providing additional details.
    public let codes: [UInt64]

    /// Creates a crash reason instance with the given parameters.
    /// - Parameters:
    ///   - exception: The Mach exception type.
    ///   - codes: An array of exception-specific codes providing additional details.
    public init(exception: Int32, codes: [UInt64])
}
protocol

CrashReporterExtension

NewiOSmacOS
public protocol CrashReporterExtension : AppExtension

The base type for crash reporter extensions.

Conform to this protocol and implement processCrashReport(process:) to create a crash reporter. Your extension runs in its own process, separate from the crashed app.

The following example shows an implementation that accesses the crashed process's corpsePort and binaryImages for use in generating a crash report.

@main
struct MyCrashExtension: CrashReporterExtension {
    func processCrashReport(process: CrashedProcess) {
        let corpsePort = process.corpsePort
        let images = process.binaryImages
        // Generate your crash report...
    }
}

After collecting the needed information from the crashed process, you can persist your crash report or send it back to a server you control.

Declaration
public protocol CrashReporterExtension : AppExtension {

    /// A method the system calls when a crash report is ready to be processed.
    ///
    /// Implement this method by inspecting the ``CrashedProcess`` object to prepare a crash report.
    /// You can then persist this report or send it back to your own server.
    /// - Parameter process: Client for accessing crash data (corpse port, symbolication, etc.)
    func processCrashReport(process: CrashedProcess)
}
extension

CrashReporterExtension

NewiOSmacOS
extension CrashReporterExtension
Declaration
extension CrashReporterExtension {

    public var configuration: some AppExtensionConfiguration { get }
}
struct

SymbolicatedFrame

NewiOSmacOS
public struct SymbolicatedFrame : Codable, Sendable

A type that represents a single symbolicated stack frame.

Declaration
public struct SymbolicatedFrame : Codable, Sendable {

    /// The symbol associated with the stack frame.
    public let symbol: String

    /// The symbol offset within the frame.
    public let symbolOffset: UInt64

    /// The name of the source file, if available.
    public let sourceFile: String?

    /// The line number within the source file, if available.
    public let sourceLine: Int?

    /// A flag that indicates if the stack frame is inline.
    public let isInline: Bool

    public init(symbol: String, symbolOffset: UInt64, sourceFile: String?, sourceLine: Int?, isInline: Bool)

    /// Encodes this value into the given encoder.
    ///
    /// If the value fails to encode anything, `encoder` will encode an empty
    /// keyed container in its place.
    ///
    /// This function throws an error if any values are invalid for the given
    /// encoder's format.
    ///
    /// - Parameter encoder: The encoder to write data to.
    public func encode(to encoder: any Encoder) throws

    /// Creates a new instance by decoding from the given decoder.
    ///
    /// This initializer throws an error if reading from the decoder fails, or
    /// if the data read is corrupted or otherwise invalid.
    ///
    /// - Parameter decoder: The decoder to read data from.
    public init(from decoder: any Decoder) throws
}

No APIs match your filter.

← More in Storage, System & Virtualization