Skip to content

Commit 3dc1185

Browse files
authored
Open Sourcing FirebaseCrashlytics (#4610)
1 parent aebfb27 commit 3dc1185

File tree

252 files changed

+29131
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

252 files changed

+29131
-0
lines changed

Crashlytics/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# v4.0.0-beta.1
2+
3+
This Firebase Crashlytics version includes the initial beta release of the Firebase Crashlytics SDK:
4+
5+
- [feature] The SDK is now open-sourced. Take a look in our [GitHub repository](https://github.com/firebase/firebase-ios-sdk/tree/master/Crashlytics).
6+
- [feature] Added support for Catalyst (note that Crashlytics still supports tvOS and macOS).
7+
- [feature] Added new APIs that are more consistent with other Firebase SDKs and more intuitive to use. The new APIs also give your users more control over how you collect their data.
8+
- [removed] Removed the Fabric API Key. Now, Crashlytics uses the GoogleService-Info.plist file to associate your app with your project. If you linked your app from Fabric and want to upgrade to the new SDK, remove the Fabric API key from your `run` and `upload-symbols` scripts. We also recommend removing the Fabric section from your app's Info.plist (when you upgrade, Crashlytics uses the new configuration you set up in Firebase).
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright 2019 Google
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#import <Foundation/Foundation.h>
16+
#if CLS_TARGET_OS_HAS_UIKIT
17+
#import <UIKit/UIKit.h>
18+
#endif
19+
20+
__BEGIN_DECLS
21+
22+
#define FIRCLSApplicationActivityDefault \
23+
(NSActivitySuddenTerminationDisabled | NSActivityAutomaticTerminationDisabled)
24+
25+
/**
26+
* Type to indicate application installation source
27+
*/
28+
typedef NS_ENUM(NSInteger, FIRCLSApplicationInstallationSourceType) {
29+
FIRCLSApplicationInstallationSourceTypeDeveloperInstall = 1,
30+
// 2 and 3 are reserved for legacy values.
31+
FIRCLSApplicationInstallationSourceTypeAppStore = 4
32+
};
33+
34+
/**
35+
* Returns the application bundle identifier with occurences of "/" replaced by "_"
36+
*/
37+
NSString* FIRCLSApplicationGetBundleIdentifier(void);
38+
39+
/**
40+
* Returns the SDK's bundle ID
41+
*/
42+
NSString* FIRCLSApplicationGetSDKBundleID(void);
43+
44+
/**
45+
* Returns the platform identifier, either: ios, mac, or tvos.
46+
* Catalyst apps are treated as mac.
47+
*/
48+
NSString* FIRCLSApplicationGetPlatform(void);
49+
50+
/**
51+
* Returns the user-facing app name
52+
*/
53+
NSString* FIRCLSApplicationGetName(void);
54+
55+
/**
56+
* Returns the build number
57+
*/
58+
NSString* FIRCLSApplicationGetBundleVersion(void);
59+
60+
/**
61+
* Returns the human-readable build version
62+
*/
63+
NSString* FIRCLSApplicationGetShortBundleVersion(void);
64+
65+
/**
66+
* Returns a number to indicate how the app has been installed: Developer / App Store
67+
*/
68+
FIRCLSApplicationInstallationSourceType FIRCLSApplicationInstallationSource(void);
69+
70+
BOOL FIRCLSApplicationIsExtension(void);
71+
NSString* FIRCLSApplicationExtensionPointIdentifier(void);
72+
73+
#if CLS_TARGET_OS_HAS_UIKIT
74+
UIApplication* FIRCLSApplicationSharedInstance(void);
75+
#else
76+
id FIRCLSApplicationSharedInstance(void);
77+
#endif
78+
79+
void FIRCLSApplicationOpenURL(NSURL* url,
80+
NSExtensionContext* extensionContext,
81+
void (^completionBlock)(BOOL success));
82+
83+
id<NSObject> FIRCLSApplicationBeginActivity(NSActivityOptions options, NSString* reason);
84+
void FIRCLSApplicationEndActivity(id<NSObject> activity);
85+
86+
void FIRCLSApplicationActivity(NSActivityOptions options, NSString* reason, void (^block)(void));
87+
88+
__END_DECLS
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
// Copyright 2019 Google
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#import "FIRCLSApplication.h"
16+
17+
#import "FIRCLSHost.h"
18+
#import "FIRCLSUtility.h"
19+
20+
#if CLS_TARGET_OS_OSX
21+
#import <AppKit/AppKit.h>
22+
#endif
23+
24+
#if CLS_TARGET_OS_HAS_UIKIT
25+
#import <UIKit/UIKit.h>
26+
#endif
27+
28+
NSString* FIRCLSApplicationGetBundleIdentifier(void) {
29+
return [[[NSBundle mainBundle] bundleIdentifier] stringByReplacingOccurrencesOfString:@"/"
30+
withString:@"_"];
31+
}
32+
33+
NSString* FIRCLSApplicationGetSDKBundleID(void) {
34+
return
35+
[@"com.google.firebase.crashlytics." stringByAppendingString:FIRCLSApplicationGetPlatform()];
36+
}
37+
38+
NSString* FIRCLSApplicationGetPlatform(void) {
39+
#if defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST
40+
return @"mac";
41+
#elif TARGET_OS_IOS
42+
return @"ios";
43+
#elif TARGET_OS_OSX
44+
return @"mac";
45+
#elif TARGET_OS_TV
46+
return @"tvos";
47+
#endif
48+
}
49+
50+
// these defaults match the FIRCLSInfoPlist helper in FIRCLSIDEFoundation
51+
NSString* FIRCLSApplicationGetBundleVersion(void) {
52+
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
53+
}
54+
55+
NSString* FIRCLSApplicationGetShortBundleVersion(void) {
56+
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
57+
}
58+
59+
NSString* FIRCLSApplicationGetName(void) {
60+
NSString* name;
61+
NSBundle* mainBundle;
62+
63+
mainBundle = [NSBundle mainBundle];
64+
65+
name = [mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
66+
if (name) {
67+
return name;
68+
}
69+
70+
name = [mainBundle objectForInfoDictionaryKey:@"CFBundleName"];
71+
if (name) {
72+
return name;
73+
}
74+
75+
return FIRCLSApplicationGetBundleVersion();
76+
}
77+
78+
BOOL FIRCLSApplicationHasAppStoreReceipt(void) {
79+
NSURL* url = NSBundle.mainBundle.appStoreReceiptURL;
80+
return [NSFileManager.defaultManager fileExistsAtPath:[url path]];
81+
}
82+
83+
FIRCLSApplicationInstallationSourceType FIRCLSApplicationInstallationSource(void) {
84+
if (FIRCLSApplicationHasAppStoreReceipt()) {
85+
return FIRCLSApplicationInstallationSourceTypeAppStore;
86+
}
87+
88+
return FIRCLSApplicationInstallationSourceTypeDeveloperInstall;
89+
}
90+
91+
BOOL FIRCLSApplicationIsExtension(void) {
92+
return FIRCLSApplicationExtensionPointIdentifier() != nil;
93+
}
94+
95+
NSString* FIRCLSApplicationExtensionPointIdentifier(void) {
96+
id extensionDict = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"NSExtension"];
97+
98+
if (!extensionDict) {
99+
return nil;
100+
}
101+
102+
if (![extensionDict isKindOfClass:[NSDictionary class]]) {
103+
FIRCLSSDKLog("Error: NSExtension Info.plist entry is mal-formed\n");
104+
return nil;
105+
}
106+
107+
id typeValue = [(NSDictionary*)extensionDict objectForKey:@"NSExtensionPointIdentifier"];
108+
109+
if (![typeValue isKindOfClass:[NSString class]]) {
110+
FIRCLSSDKLog("Error: NSExtensionPointIdentifier Info.plist entry is mal-formed\n");
111+
return nil;
112+
}
113+
114+
return typeValue;
115+
}
116+
117+
#if CLS_TARGET_OS_HAS_UIKIT
118+
UIApplication* FIRCLSApplicationSharedInstance(void) {
119+
if (FIRCLSApplicationIsExtension()) {
120+
return nil;
121+
}
122+
123+
return [[UIApplication class] performSelector:@selector(sharedApplication)];
124+
}
125+
#elif CLS_TARGET_OS_OSX
126+
id FIRCLSApplicationSharedInstance(void) {
127+
return [NSClassFromString(@"NSApplication") sharedApplication];
128+
}
129+
#else
130+
id FIRCLSApplicationSharedInstance(void) {
131+
return nil; // FIXME: what do we actually return for watch?
132+
}
133+
#endif
134+
135+
void FIRCLSApplicationOpenURL(NSURL* url,
136+
NSExtensionContext* extensionContext,
137+
void (^completionBlock)(BOOL success)) {
138+
if (extensionContext) {
139+
[extensionContext openURL:url completionHandler:completionBlock];
140+
return;
141+
}
142+
143+
BOOL result = NO;
144+
145+
#if TARGET_OS_IOS
146+
// What's going on here is the value returned is a scalar, but we really need an object to
147+
// call this dynamically. Hoops must be jumped.
148+
NSInvocationOperation* op =
149+
[[NSInvocationOperation alloc] initWithTarget:FIRCLSApplicationSharedInstance()
150+
selector:@selector(openURL:)
151+
object:url];
152+
[op start];
153+
[op.result getValue:&result];
154+
#elif CLS_TARGET_OS_OSX
155+
result = [[NSClassFromString(@"NSWorkspace") sharedWorkspace] openURL:url];
156+
#endif
157+
158+
completionBlock(result);
159+
}
160+
161+
id<NSObject> FIRCLSApplicationBeginActivity(NSActivityOptions options, NSString* reason) {
162+
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(beginActivityWithOptions:
163+
reason:)]) {
164+
return [[NSProcessInfo processInfo] beginActivityWithOptions:options reason:reason];
165+
}
166+
167+
#if CLS_TARGET_OS_OSX
168+
if (options & NSActivitySuddenTerminationDisabled) {
169+
[[NSProcessInfo processInfo] disableSuddenTermination];
170+
}
171+
172+
if (options & NSActivityAutomaticTerminationDisabled) {
173+
[[NSProcessInfo processInfo] disableAutomaticTermination:reason];
174+
}
175+
#endif
176+
177+
// encode the options, so we can undo our work later
178+
return @{@"options" : @(options), @"reason" : reason};
179+
}
180+
181+
void FIRCLSApplicationEndActivity(id<NSObject> activity) {
182+
if (!activity) {
183+
return;
184+
}
185+
186+
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(endActivity:)]) {
187+
[[NSProcessInfo processInfo] endActivity:activity];
188+
return;
189+
}
190+
191+
#if CLS_TARGET_OS_OSX
192+
NSInteger options = [[(NSDictionary*)activity objectForKey:@"options"] integerValue];
193+
194+
if (options & NSActivitySuddenTerminationDisabled) {
195+
[[NSProcessInfo processInfo] enableSuddenTermination];
196+
}
197+
198+
if (options & NSActivityAutomaticTerminationDisabled) {
199+
[[NSProcessInfo processInfo]
200+
enableAutomaticTermination:[(NSDictionary*)activity objectForKey:@"reason"]];
201+
}
202+
#endif
203+
}
204+
205+
void FIRCLSApplicationActivity(NSActivityOptions options, NSString* reason, void (^block)(void)) {
206+
id<NSObject> activity = FIRCLSApplicationBeginActivity(options, reason);
207+
208+
block();
209+
210+
FIRCLSApplicationEndActivity(activity);
211+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2019 Google
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include "FIRCLSFeatures.h"
18+
#include "FIRCLSFile.h"
19+
#include "FIRCLSMachO.h"
20+
21+
#include <stdbool.h>
22+
#include <stdint.h>
23+
24+
__BEGIN_DECLS
25+
26+
// Typically, apps seem to have ~300 binary images loaded
27+
#define CLS_BINARY_IMAGE_RUNTIME_NODE_COUNT (512)
28+
#define CLS_BINARY_IMAGE_RUNTIME_NODE_NAME_SIZE (32)
29+
#define CLS_BINARY_IMAGE_RUNTIME_NODE_RECORD_NAME 0
30+
31+
#define FIRCLSUUIDStringLength (33)
32+
33+
typedef struct {
34+
_Atomic(void*) volatile baseAddress;
35+
uint64_t size;
36+
#if CLS_DWARF_UNWINDING_SUPPORTED
37+
const void* ehFrame;
38+
#endif
39+
#if CLS_COMPACT_UNWINDING_SUPPORTED
40+
const void* unwindInfo;
41+
#endif
42+
const void* crashInfo;
43+
#if CLS_BINARY_IMAGE_RUNTIME_NODE_RECORD_NAME
44+
char name[CLS_BINARY_IMAGE_RUNTIME_NODE_NAME_SIZE];
45+
#endif
46+
} FIRCLSBinaryImageRuntimeNode;
47+
48+
typedef struct {
49+
char uuidString[FIRCLSUUIDStringLength];
50+
bool encrypted;
51+
FIRCLSMachOVersion builtSDK;
52+
FIRCLSMachOVersion minSDK;
53+
FIRCLSBinaryImageRuntimeNode node;
54+
struct FIRCLSMachOSlice slice;
55+
intptr_t vmaddr_slide;
56+
} FIRCLSBinaryImageDetails;
57+
58+
typedef struct {
59+
const char* path;
60+
} FIRCLSBinaryImageReadOnlyContext;
61+
62+
typedef struct {
63+
FIRCLSFile file;
64+
FIRCLSBinaryImageRuntimeNode nodes[CLS_BINARY_IMAGE_RUNTIME_NODE_COUNT];
65+
} FIRCLSBinaryImageReadWriteContext;
66+
67+
void FIRCLSBinaryImageInit(FIRCLSBinaryImageReadOnlyContext* roContext,
68+
FIRCLSBinaryImageReadWriteContext* rwContext);
69+
70+
#if CLS_COMPACT_UNWINDING_SUPPORTED
71+
bool FIRCLSBinaryImageSafeFindImageForAddress(uintptr_t address,
72+
FIRCLSBinaryImageRuntimeNode* image);
73+
bool FIRCLSBinaryImageSafeHasUnwindInfo(FIRCLSBinaryImageRuntimeNode* image);
74+
#endif
75+
76+
bool FIRCLSBinaryImageFindImageForUUID(const char* uuidString,
77+
FIRCLSBinaryImageDetails* imageDetails);
78+
79+
bool FIRCLSBinaryImageRecordMainExecutable(FIRCLSFile* file);
80+
81+
__END_DECLS

0 commit comments

Comments
 (0)