Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move demangle filter to an optional module #540

Merged
merged 18 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Sources/KSCrashRecordingCore/KSObjCApple.h
Sources/KSCrashRecordingCore/llvm/*
Sources/KSCrashRecordingCore/llvm/*/*
Sources/KSCrashRecordingCore/swift/*
Sources/KSCrashRecordingCore/swift/*/*
Sources/KSCrashDemangleFilter/llvm/*
Sources/KSCrashDemangleFilter/llvm/*/*
Sources/KSCrashDemangleFilter/swift/*
Sources/KSCrashDemangleFilter/swift/*/*
24 changes: 24 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/KSCrash-Package.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DemangleFilter"
BuildableName = "DemangleFilter"
BlueprintName = "DemangleFilter"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down Expand Up @@ -204,6 +218,16 @@
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "KSCrashDemangleFilterTests"
BuildableName = "KSCrashDemangleFilterTests"
BlueprintName = "KSCrashDemangleFilterTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
7 changes: 7 additions & 0 deletions KSCrash.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Pod::Spec.new do |s|
installations.dependency 'KSCrash/Filters'
installations.dependency 'KSCrash/Sinks'
installations.dependency 'KSCrash/Recording'
installations.dependency 'KSCrash/DemangleFilter'

configure_subspec.call(installations)
end
Expand All @@ -72,6 +73,12 @@ Pod::Spec.new do |s|
configure_subspec.call(disc_space_monitor)
end

s.subspec 'DemangleFilter' do |demangle_filter|
demangle_filter.dependency 'KSCrash/Recording'

configure_subspec.call(demangle_filter)
end

s.subspec 'ReportingCore' do |reporting_core|
reporting_core.dependency 'KSCrash/Core'
reporting_core.ios.frameworks = 'SystemConfiguration'
Expand Down
39 changes: 31 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ let package = Package(
name: "BootTimeMonitor",
targets: [Targets.bootTimeMonitor]
),
.library(
name: "DemangleFilter",
targets: [Targets.demangleFilter]
),
],
targets: [
.target(
Expand Down Expand Up @@ -112,6 +116,7 @@ let package = Package(
.target(name: Targets.filters),
.target(name: Targets.sinks),
.target(name: Targets.recording),
.target(name: Targets.demangleFilter),
],
resources: [
.copy("Resources/PrivacyInfo.xcprivacy")
Expand All @@ -134,14 +139,6 @@ let package = Package(
],
resources: [
.copy("Resources/PrivacyInfo.xcprivacy")
],
cSettings: [
.headerSearchPath("swift"),
.headerSearchPath("swift/Basic"),
.headerSearchPath("llvm"),
.headerSearchPath("llvm/ADT"),
.headerSearchPath("llvm/Config"),
.headerSearchPath("llvm/Support"),
]
),
.testTarget(
Expand Down Expand Up @@ -217,6 +214,31 @@ let package = Package(
]
),

.target(
bamx23 marked this conversation as resolved.
Show resolved Hide resolved
name: Targets.demangleFilter,
dependencies: [
.target(name: Targets.recording),
],
resources: [
.copy("Resources/PrivacyInfo.xcprivacy")
],
cSettings: [
.headerSearchPath("swift"),
.headerSearchPath("swift/Basic"),
.headerSearchPath("llvm"),
.headerSearchPath("llvm/ADT"),
.headerSearchPath("llvm/Config"),
.headerSearchPath("llvm/Support"),
]
),
.testTarget(
name: Targets.demangleFilter.tests,
dependencies: [
.target(name: Targets.demangleFilter),
.target(name: Targets.recording),
]
),

.target(
name: Targets.testTools,
dependencies: [
Expand All @@ -237,6 +259,7 @@ enum Targets {
static let core = "KSCrashCore"
static let discSpaceMonitor = "KSCrashDiscSpaceMonitor"
static let bootTimeMonitor = "KSCrashBootTimeMonitor"
static let demangleFilter = "KSCrashDemangleFilter"
static let testTools = "KSCrashTestTools"
}

Expand Down
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ installation.sendAllReports { reports, completed, error in
}
```

### Optional Modules
### Optional Monitors

KSCrash includes two optional modules: `BootTimeMonitor` and `DiscSpaceMonitor`. These modules are not included by default and must be explicitly added if needed. They contain privacy-concerning APIs that require showing crash reports to the user before sending this information off the device.
KSCrash includes two optional monitor modules: `BootTimeMonitor` and `DiscSpaceMonitor`. These modules are not included by default and must be explicitly added if needed. They contain privacy-concerning APIs that require showing crash reports to the user before sending this information off the device.

To include these modules:

Expand All @@ -199,6 +199,26 @@ If these modules are linked, they act automatically and require no additional se

For more information, see Apple's documentation on [Disk space APIs](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api#4278397) and [System boot time APIs](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api#4278394).

### Optional Demangling

KSCrash has an optional module that provides demangling for both C++ and Swift symbols: `DemangleFilter`. This module contains a KSCrash filter (`CrashReportFilterDemangle`) that can be used for demangling symbols in crash reports during the `sendAllReports` call *(if this filter is added to the filters pipeline)*.

This module is used automatically if you use the `Installations` API. If you want to avoid demangling, you can set `isDemangleEnabled` in the `CrashInstallation` instance to `false`.

If you don't use the `Installations` API, you can include this module manually:

- With CocoaPods:
```ruby
pod 'KSCrash/DemangleFilter'
```

- With SPM, add to your target dependencies:
```swift
.product(name: "DemangleFilter", package: "KSCrash"),
```

The `CrashReportFilterDemangle` class also has a static API that you can use yourself in case you need to demangle a C++ or Swift symbol.

## What's New?

### Out-of-Memory Crash Detection
Expand Down Expand Up @@ -292,6 +312,7 @@ KSCrash is structured into several modules, divided into public and private APIs

- **DiscSpaceMonitor**: `KSCrashDiscSpaceMonitor` - Monitors available disk space.
- **BootTimeMonitor**: `KSCrashBootTimeMonitor` - Tracks device boot time.
- **DemangleFilter**: `KSCrashDemangleFilter` - Demangle symbols in crashes as part of reporing pipeline.

### Private API Modules

Expand Down
1 change: 1 addition & 0 deletions Samples/Common/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ let package = Package(
dependencies: [
.product(name: "Recording", package: "KSCrash"),
.product(name: "Reporting", package: "KSCrash"),
.product(name: "DemangleFilter", package: "KSCrash"),
.product(name: "Logging", package: "swift-log"),
]
),
Expand Down
11 changes: 10 additions & 1 deletion Samples/Common/Sources/CrashTriggers/KSCrashTriggersList.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
#import <signal.h>
#import <stdexcept>

namespace sample_namespace
{
class Report
{
public:
static void crash() { throw std::runtime_error("C++ exception"); }
};
} // namespace sample_namespace

@implementation KSCrashTriggersList

+ (void)trigger_nsException_genericNSException
Expand All @@ -46,7 +55,7 @@ + (void)trigger_nsException_nsArrayOutOfBounds

+ (void)trigger_cpp_runtimeException
{
throw std::runtime_error("C++ exception");
sample_namespace::Report::crash();
}

+ (void)trigger_mach_badAccess
Expand Down
2 changes: 2 additions & 0 deletions Samples/Common/Sources/LibraryBridge/ReportingSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Foundation
import KSCrashRecording
import KSCrashFilters
import KSCrashSinks
import KSCrashDemangleFilter
import Logging

public class ReportingSample {
Expand Down Expand Up @@ -58,6 +59,7 @@ public class ReportingSample {

public static func sampleLogToConsole() {
KSCrash.shared.sink = CrashReportFilterPipeline(filtersArray: [
CrashReportFilterDemangle(),
SampleFilter(),
SampleSink(),
])
Expand Down
Loading
Loading