/swift-backtrace

💥 Backtraces for Swift on Linux

Primary LanguageCApache License 2.0Apache-2.0

Backtrace

This Swift package provides support for automatically printing crash backtraces of Swift programs.

Usage

Add https://github.com/swift-server/swift-backtrace.git as a dependency in your Package.swift.

Crash backtraces

In your main.swift, do:

import Backtrace

// Do this first
Backtrace.install()

Finally, make sure you build your application with debug symbols enabled:

$ swift build -c release -Xswiftc -g

When your app crashes, a stacktrace will be printed to stderr.

Integrating Backtrace with swift-service-lifecycle

If you are using swift-service-lifecycle https://github.com/swift-server/swift-service-lifecycle, using the Backtrace.install() command will interfere with the shutdown lifecycle. Instead, add Backtrace.print to your lifecycle:

import Backtrace

lifecycle.registerShutdown(label: "backtrace",.sync(Backtrace.print))

Acknowledgements

Ian Partridge (GitHub, Twitter) the original author of this package.

Johannes Weiss (GitHub, Twitter) for the signal handling code.