Symbolicate a macOS crash in Bugsink

When your macOS app crashes, Bugsink can show the Swift function and the line that crashed. It needs the dSYM from that build to turn stack addresses into file names and line numbers. Upload a source bundle as well and you can read the code around the crash in Bugsink.

Create a project in Bugsink and copy its DSN. The quickstart guide shows where to find it. You’ll need Xcode and Sentry CLI 4 on the machine that builds your app. The PyPI package installs the sentry command.

Add the SDK and set your DSN

In Xcode, use File → Add Package Dependencies with https://github.com/getsentry/sentry-cocoa.git and add the SentrySPM product to your app target. Start the SDK on the main thread as your app launches. Pass the DSN from your app’s configuration. This command-line example reads it from the environment.

import Foundation
import SentrySwift

SentrySDK.start { options in
    options.dsn = ProcessInfo.processInfo.environment["SENTRY_DSN"]
}

Set SENTRY_DSN to the DSN from your Bugsink project before running the app.

export SENTRY_DSN=https://key@bugsink.example/1

Before you build, add a temporary crash to a code path you can run. In this example, looking up an unknown product calls abort().

@inline(never)
func reserveProduct(_ sku: String) {
    let inventory = ["coffee": 12, "tea": 8]
    guard let stock = inventory[sku] else {
        abort()
    }
    print("Reserved one \(sku). Remaining: \(stock - 1)")
}

A short-lived command-line app needs to stay open long enough to send the report. This is how the example does it after handling the argument.

reserveProduct(CommandLine.arguments.dropFirst().first ?? "coffee")

// A command-line process needs to give crash reports from the previous launch time to send.
RunLoop.main.run(until: Date(timeIntervalSinceNow: 1))
SentrySDK.flush(timeout: 10)

Build and upload the debug files

In Xcode, set Debug Information Format to DWARF with dSYM File for the configuration you distribute. Use the dSYM from the same archive as the app you ship. Keep it with that build so you can resolve crashes from older releases.

For a Swift package executable, build it and run dsymutil while the build objects are still available. Here the executable is InventoryReport.

swift build
binary="$(swift build --show-bin-path)/InventoryReport"
xcrun dsymutil "$binary" -o InventoryReport.dSYM

Run the upload while the source files referenced by the dSYM are still in the checkout. Create a Bugsink API token with debug-files:upload access and set it as SENTRY_AUTH_TOKEN in your shell or build job. Use the base URL of your Bugsink instance and the slug of the same project you used for the DSN.

sentry debug-files bundle-sources --output InventoryReport.src.zip \
    InventoryReport.dSYM/Contents/Resources/DWARF/InventoryReport
SENTRY_URL=https://bugsink.example sentry debug-files upload \
    --org bugsink --project your-project-slug \
    --wait InventoryReport.dSYM InventoryReport.src.zip

Send a test crash

Run the app outside the debugger, trigger the crash, then open it again. The SDK sends the saved report on the next launch. If you’re following along with the command-line example, pass missing to crash and coffee on the second run.

"$binary" missing
"$binary" coffee

See the crash in Bugsink

Open the new crash in your project and expand the reserveProduct frame. Bugsink shows main.swift, line 9, with the abort() call highlighted.

Bugsink preview

If you see addresses instead, run xcrun dwarfdump --uuid "$binary" InventoryReport.dSYM and check that the UUIDs match for the architecture you ran.

Remove the deliberate crash once you’ve confirmed the stack. For future builds, upload the matching dSYM and source bundle as part of your release build.