13 Commits

Author SHA1 Message Date
Tim Condon f01e3400ae Update README.md for archiving 2024-10-28 14:16:39 +00:00
Franz Busch 7277ee0e03 Merge pull request #73 from euanh/do-not-build-demangle-after-5.9
Do not build Demangle on Swift 5.9 or above
2024-06-17 11:33:03 +02:00
Euan Harris d4f33e71ca Do not build Demangle on Swift 5.9 or above
Pull request #68 prevents Backtrace from being built on Swift 5.9 and above,
but Demangle is still built and fails when the importing project uses musl.
2024-06-13 17:51:30 +01:00
Konrad `ktoso` Malawski 525d45046b Merge pull request #70 from yim-lee/ci-5.10 2024-06-14 00:34:35 +09:00
Yim Lee adc931806e fix ruby version too old error 2024-01-22 14:22:24 -08:00
Yim Lee defae63094 Add CI for Swift 5.10 2024-01-22 13:06:44 -08:00
Alastair Houghton 80746bdd0a Disable this library for Swift 5.9 and above. (#68) 2023-09-05 06:47:22 -07:00
Yim Lee 2cfddd6892 Update CI (#66)
- Add docker-compose file for Swift 5.8 and 5.9
- Update docker image for Swift 5.7
- Update `main` to Ubuntu 22.04
2023-04-04 14:31:55 -07:00
Yim Lee e9cffd432c Add .spi.yml for Swift Package Index DocC support (#63) 2022-12-05 11:35:05 -08:00
Yim Lee 9f43812fb5 Merge pull request #62 from yim-lee/docc
DocC setup
2022-08-11 10:43:55 -07:00
Yim Lee 9cc8c17785 Fix formatting 2022-08-10 21:56:25 -07:00
Yim Lee a0bfe70c1b Add manifest for Swift 5.0 2022-08-10 21:55:36 -07:00
Yim Lee 1809e7963b DocC setup 2022-08-10 21:53:01 -07:00
25 changed files with 358 additions and 33 deletions
+4
View File
@@ -0,0 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [Backtrace]
+6 -4
View File
@@ -1,4 +1,4 @@
// swift-tools-version:5.0
// swift-tools-version:5.6
import PackageDescription
@@ -10,14 +10,16 @@ let package = Package(
targets: ["Backtrace"]
),
],
dependencies: [],
dependencies: [
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(name: "Backtrace",
dependencies: ["CBacktrace"]),
.target(name: "CBacktrace",
dependencies: []),
.target(name: "Sample",
dependencies: ["Backtrace"]),
.executableTarget(name: "Sample",
dependencies: ["Backtrace"]),
.testTarget(name: "BacktraceTests",
dependencies: ["Backtrace"]),
]
+24
View File
@@ -0,0 +1,24 @@
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "swift-backtrace",
products: [
.library(
name: "Backtrace",
targets: ["Backtrace"]
),
],
dependencies: [],
targets: [
.target(name: "Backtrace",
dependencies: ["CBacktrace"]),
.target(name: "CBacktrace",
dependencies: []),
.target(name: "Sample",
dependencies: ["Backtrace"]),
.testTarget(name: "BacktraceTests",
dependencies: ["Backtrace"]),
]
)
+24
View File
@@ -0,0 +1,24 @@
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "swift-backtrace",
products: [
.library(
name: "Backtrace",
targets: ["Backtrace"]
),
],
dependencies: [],
targets: [
.target(name: "Backtrace",
dependencies: ["CBacktrace"]),
.target(name: "CBacktrace",
dependencies: []),
.target(name: "Sample",
dependencies: ["Backtrace"]),
.testTarget(name: "BacktraceTests",
dependencies: ["Backtrace"]),
]
)
+24
View File
@@ -0,0 +1,24 @@
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "swift-backtrace",
products: [
.library(
name: "Backtrace",
targets: ["Backtrace"]
),
],
dependencies: [],
targets: [
.target(name: "Backtrace",
dependencies: ["CBacktrace"]),
.target(name: "CBacktrace",
dependencies: []),
.target(name: "Sample",
dependencies: ["Backtrace"]),
.testTarget(name: "BacktraceTests",
dependencies: ["Backtrace"]),
]
)
+24
View File
@@ -0,0 +1,24 @@
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "swift-backtrace",
products: [
.library(
name: "Backtrace",
targets: ["Backtrace"]
),
],
dependencies: [],
targets: [
.target(name: "Backtrace",
dependencies: ["CBacktrace"]),
.target(name: "CBacktrace",
dependencies: []),
.target(name: "Sample",
dependencies: ["Backtrace"]),
.testTarget(name: "BacktraceTests",
dependencies: ["Backtrace"]),
]
)
+24
View File
@@ -0,0 +1,24 @@
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "swift-backtrace",
products: [
.library(
name: "Backtrace",
targets: ["Backtrace"]
),
],
dependencies: [],
targets: [
.target(name: "Backtrace",
dependencies: ["CBacktrace"]),
.target(name: "CBacktrace",
dependencies: []),
.target(name: "Sample",
dependencies: ["Backtrace"]),
.testTarget(name: "BacktraceTests",
dependencies: ["Backtrace"]),
]
)
+24
View File
@@ -0,0 +1,24 @@
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "swift-backtrace",
products: [
.library(
name: "Backtrace",
targets: ["Backtrace"]
),
],
dependencies: [],
targets: [
.target(name: "Backtrace",
dependencies: ["CBacktrace"]),
.target(name: "CBacktrace",
dependencies: []),
.target(name: "Sample",
dependencies: ["Backtrace"]),
.testTarget(name: "BacktraceTests",
dependencies: ["Backtrace"]),
]
)
+5 -2
View File
@@ -1,3 +1,6 @@
> [!IMPORTANT]
> This library is now archived as backtracing is built into Swift 5.9+
# Backtrace
This Swift package provides support for automatically printing crash backtraces of Swift programs.
@@ -7,8 +10,8 @@ When this gap is closed at the language runtime level, this library will become
## Usage
When building web-services and daemons, direct usage of this library is discouraged.
Instead, use [swift-service-lifecycle](https://github.com/swift-server/swift-service-lifecycle) which helps manage the application lifecycle including setting up backtraces hooks when needed.
**Note**: You do not need this library on Linux as of Swift 5.9, which has
built-in backtracing support.
Add `https://github.com/swift-server/swift-backtrace.git` as a dependency in your `Package.swift`.
+20 -2
View File
@@ -2,7 +2,7 @@
//
// This source file is part of the SwiftLinuxBacktrace open source project
//
// Copyright (c) 2019-2020 Apple Inc. and the SwiftLinuxBacktrace project authors
// Copyright (c) 2019-2022 Apple Inc. and the SwiftLinuxBacktrace project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
@@ -12,7 +12,21 @@
//
//===----------------------------------------------------------------------===//
#if os(Linux)
// Swift 5.9 has its own built-in backtracing support in the runtime;
// we don't want to activate this library if we're using 5.9 or above.
#if swift(>=5.9) && !os(Windows)
public enum Backtrace {
@available(*, deprecated, message: "This is no longer needed in Swift 5.9")
public static func install() {}
@available(*, deprecated, message: "This is no longer needed in Swift 5.9")
public static func install(signals: [CInt]) {}
@available(*, deprecated, message: "This method will be removed in the next major version.")
public static func print() {}
}
#elseif os(Linux)
import CBacktrace
import Glibc
@@ -124,11 +138,13 @@ public enum Backtrace {
#endif
}
/// Signal selection unavailable on Windows. Use ``install()-484jy``.
@available(*, deprecated, message: "signal selection unavailable on Windows")
public static func install(signals: [CInt]) {
Backtrace.install()
}
/// Install the backtrace handler on default signals.
public static func install() {
// Install a last-chance vectored exception handler to capture the error
// before the termination and report the stack trace. It is unlikely
@@ -264,8 +280,10 @@ public enum Backtrace {
#else
public enum Backtrace {
/// Install the backtrace handler on default signals. Available on Windows and Linux only.
public static func install() {}
/// Install the backtrace handler on specific signals. Available on Linux only.
public static func install(signals: [CInt]) {}
@available(*, deprecated, message: "This method will be removed in the next major version.")
+6
View File
@@ -12,6 +12,10 @@
//
//===----------------------------------------------------------------------===//
// Swift 5.9 has its own built-in backtracing support in the runtime;
// we don't want to activate this library if we're using 5.9 or above.
#if !(swift(>=5.9) && !os(Windows))
#if os(Linux)
import Glibc
#elseif os(Windows)
@@ -55,3 +59,5 @@ internal func _stdlib_demangleName(_ mangledName: String) -> String {
}
}
#endif
#endif
+34
View File
@@ -0,0 +1,34 @@
# ``Backtrace``
Provides support for automatically printing crash backtraces of Swift programs.
## Overview
The Backtrace library is designed to fill a gap in backtraces support for Swift on non-Darwin platforms.
When this gap is closed at the language runtime level, this library will become redundant and be deprecated.
## Getting started
When building web-services and daemons, direct usage of this library is discouraged.
Instead, use [swift-service-lifecycle](https://github.com/swift-server/swift-service-lifecycle) which helps manage the application lifecycle including setting up backtraces hooks when needed.
Add `https://github.com/swift-server/swift-backtrace.git` as a dependency in your `Package.swift`.
### Crash backtraces
In your `main.swift`, do:
```swift
import Backtrace
// Do this first
Backtrace.install()
```
Finally, for Swift < 5.2, make sure you build your application with debug symbols enabled. Debug symbols are automatically included for Swift 5.2 and above.
```
$ swift build -c release -Xswiftc -g
```
When your app crashes, a stacktrace will be printed to `stderr`.
+5 -1
View File
@@ -15,11 +15,15 @@
import Backtrace
#if canImport(Darwin)
import Darwin
#elseif os(Linux)
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#endif
#if swift(<5.9) || os(Windows)
Backtrace.install()
#endif
func raiseSignal(_ signal: Int32) {
raise(signal)
+20
View File
@@ -20,6 +20,10 @@ public final class BacktraceTests: XCTestCase {
try XCTSkipIf(true, "test is only supported on Linux")
#endif
#if swift(>=5.9)
try XCTSkipIf(true, "test is not supported on Swift 5.9")
#endif
let expectedError = UUID().uuidString
let stderr = try runSample(reason: expectedError)
print(stderr)
@@ -34,6 +38,10 @@ public final class BacktraceTests: XCTestCase {
try XCTSkipIf(true, "test is only supported on Linux")
#endif
#if swift(>=5.9)
try XCTSkipIf(true, "test is not supported on Swift 5.9")
#endif
let stderr = try runSample(reason: "SIGILL")
print(stderr)
@@ -46,6 +54,10 @@ public final class BacktraceTests: XCTestCase {
try XCTSkipIf(true, "test is only supported on Linux")
#endif
#if swift(>=5.9)
try XCTSkipIf(true, "test is not supported on Swift 5.9")
#endif
let stderr = try runSample(reason: "SIGSEGV")
print(stderr)
@@ -58,6 +70,10 @@ public final class BacktraceTests: XCTestCase {
try XCTSkipIf(true, "test is only supported on Linux")
#endif
#if swift(>=5.9)
try XCTSkipIf(true, "test is not supported on Swift 5.9")
#endif
let stderr = try runSample(reason: "SIGBUS")
print(stderr)
@@ -70,6 +86,10 @@ public final class BacktraceTests: XCTestCase {
try XCTSkipIf(true, "test is only supported on Linux")
#endif
#if swift(>=5.9)
try XCTSkipIf(true, "test is not supported on Swift 5.9")
#endif
let stderr = try runSample(reason: "SIGFPE")
print(stderr)
+2 -2
View File
@@ -19,8 +19,8 @@ RUN apt-get update && apt-get install -y lsof dnsutils netcat-openbsd net-tools
# ruby and jazzy for docs generation
RUN apt-get update && apt-get install -y ruby ruby-dev libsqlite3-dev build-essential
# jazzy no longer works on older version of ubuntu as ruby is too old.
RUN if [ "${ubuntu_version}" = "focal" ] ; then echo "gem: --no-document" > ~/.gemrc ; fi
RUN if [ "${ubuntu_version}" = "focal" ] ; then gem install jazzy ; fi
RUN if [ "${ubuntu_version}" = "jammy" ] ; then echo "gem: --no-document" > ~/.gemrc ; fi
RUN if [ "${ubuntu_version}" = "jammy" ] ; then gem install jazzy ; fi
# tools
RUN mkdir -p $HOME/.tools
+2
View File
@@ -11,6 +11,8 @@ services:
test:
image: swift-linux-backtrace:20.04-5.6
environment:
- FORCE_TEST_DISCOVERY=--enable-test-discovery
shell:
image: swift-linux-backtrace:20.04-5.6
+4 -1
View File
@@ -6,10 +6,13 @@ services:
image: swift-linux-backtrace:20.04-5.7
build:
args:
base_image: "swiftlang/swift:nightly-main-focal"
ubuntu_version: "focal"
swift_version: "5.7"
test:
image: swift-linux-backtrace:20.04-5.7
environment:
- FORCE_TEST_DISCOVERY=--enable-test-discovery
shell:
image: swift-linux-backtrace:20.04-5.7
-15
View File
@@ -1,15 +0,0 @@
version: "3"
services:
runtime-setup:
image: swift-linux-backtrace:20.04-main
build:
args:
base_image: "swiftlang/swift:nightly-main-focal"
test:
image: swift-linux-backtrace:20.04-main
shell:
image: swift-linux-backtrace:20.04-main
+17
View File
@@ -0,0 +1,17 @@
version: "3"
services:
runtime-setup:
image: swift-linux-backtrace:22.04-5.10
build:
args:
base_image: "swiftlang/swift:nightly-5.10-jammy"
test:
image: swift-linux-backtrace:22.04-5.10
environment:
- FORCE_TEST_DISCOVERY=--enable-test-discovery
shell:
image: swift-linux-backtrace:22.04-5.10
+18
View File
@@ -0,0 +1,18 @@
version: "3"
services:
runtime-setup:
image: swift-linux-backtrace:22.04-5.8
build:
args:
ubuntu_version: "jammy"
swift_version: "5.8"
test:
image: swift-linux-backtrace:22.04-5.8
environment:
- FORCE_TEST_DISCOVERY=--enable-test-discovery
shell:
image: swift-linux-backtrace:22.04-5.8
+18
View File
@@ -0,0 +1,18 @@
version: "3"
services:
runtime-setup:
image: swift-linux-backtrace:22.04-5.9
build:
args:
ubuntu_version: "jammy"
swift_version: "5.9"
test:
image: swift-linux-backtrace:22.04-5.9
environment:
- FORCE_TEST_DISCOVERY=--enable-test-discovery
shell:
image: swift-linux-backtrace:22.04-5.9
+17
View File
@@ -0,0 +1,17 @@
version: "3"
services:
runtime-setup:
image: swift-linux-backtrace:22.04-main
build:
args:
base_image: "swiftlang/swift:nightly-main-jammy"
test:
image: swift-linux-backtrace:22.04-main
environment:
- FORCE_TEST_DISCOVERY=--enable-test-discovery
shell:
image: swift-linux-backtrace:22.04-main
+3 -3
View File
@@ -22,13 +22,13 @@ services:
- CAP_NET_RAW
- CAP_NET_BIND_SERVICE
sanity:
soundness:
<<: *common
command: /bin/bash -cl "./scripts/sanity.sh"
command: /bin/bash -cl "./scripts/soundness.sh"
test:
<<: *common
command: /bin/bash -cl "swift test -c release -Xswiftc -g -Xswiftc -warnings-as-errors $${SANITIZER_ARG-}"
command: /bin/bash -cl "swift test -c release -Xswiftc -g -Xswiftc -warnings-as-errors $${FORCE_TEST_DISCOVERY-} $${SANITIZER_ARG-}"
# util
+30
View File
@@ -0,0 +1,30 @@
#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftLinuxBacktrace open source project
##
## Copyright (c) 2022 Apple Inc. and the SwiftLinuxBacktrace project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftLinuxBacktrace project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift Distributed Actors open source project
##
## Copyright (c) 2018-2019 Apple Inc. and the Swift Distributed Actors project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.md for the list of Swift Distributed Actors project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
swift package --disable-sandbox preview-documentation --target $1
+3 -3
View File
@@ -3,7 +3,7 @@
##
## This source file is part of the SwiftLinuxBacktrace open source project
##
## Copyright (c) 2017-2018 Apple Inc. and the SwiftLinuxBacktrace project authors
## Copyright (c) 2017-2022 Apple Inc. and the SwiftLinuxBacktrace project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
@@ -19,7 +19,7 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function replace_acceptable_years() {
# this needs to replace all acceptable forms with 'YEARS'
sed -e 's/2017-2018/YEARS/' -e 's/2019-2020/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/'
sed -e 's/20[12][78901]-20[12][89012]/YEARS/' -e 's/2019/YEARS/' -e 's/202[012]/YEARS/'
}
printf "=> Checking linux tests... "
@@ -57,7 +57,7 @@ for language in swift-or-c bash dtrace; do
matching_files=( -name '*' )
case "$language" in
swift-or-c)
exceptions=( -name Package.swift -o -path './Sources/CBacktrace/*' )
exceptions=( -name Package.swift -o -name 'Package@*.swift' -o -path './Sources/CBacktrace/*' )
matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' )
cat > "$tmp" <<"EOF"
//===----------------------------------------------------------------------===//