Skip to content

Commit 5585179

Browse files
author
Robert Bartoszewski
committed
Fixed formatting
1 parent 11a9797 commit 5585179

33 files changed

+526
-488
lines changed

Samples/Common/Sources/LibraryBridge/InstallBridge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class InstallBridge: ObservableObject {
7878
config = .init()
7979
config.crashNotifyCallback = { (writer, requiresAsyncSafety) -> Void in
8080
Self.logger.info("User callback has requireAsyncSafety value: \(String(requiresAsyncSafety))")
81-
}
81+
}
8282

8383
$basePath
8484
.removeDuplicates()

Samples/Tests/Core/PartialCrashReport.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct PartialCrashReport: Decodable {
8989
var address: UInt64?
9090
var type: String?
9191
}
92-
92+
9393
var index: Int
9494
var state: String
9595
var crashed: Bool

Samples/Tests/IntegrationTests.swift

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -93,54 +93,55 @@ final class CppTests: IntegrationTestBase {
9393

9494
#if !os(watchOS)
9595

96-
final class SignalTests: IntegrationTestBase {
97-
func testAbort() throws {
98-
try launchAndCrash(.signal_abort)
96+
final class SignalTests: IntegrationTestBase {
97+
func testAbort() throws {
98+
try launchAndCrash(.signal_abort)
9999

100-
let rawReport = try readPartialCrashReport()
101-
try rawReport.validate()
102-
XCTAssertEqual(rawReport.crash?.error?.type, "signal")
103-
XCTAssertEqual(rawReport.crash?.error?.signal?.name, "SIGABRT")
100+
let rawReport = try readPartialCrashReport()
101+
try rawReport.validate()
102+
XCTAssertEqual(rawReport.crash?.error?.type, "signal")
103+
XCTAssertEqual(rawReport.crash?.error?.signal?.name, "SIGABRT")
104104

105-
let appleReport = try launchAndReportCrash()
106-
XCTAssertTrue(appleReport.contains("SIGABRT"))
107-
}
105+
let appleReport = try launchAndReportCrash()
106+
XCTAssertTrue(appleReport.contains("SIGABRT"))
107+
}
108108

109-
func testTermination() throws {
110-
// Default (termination monitoring disabled)
111-
try launchAndInstall()
112-
try terminate()
109+
func testTermination() throws {
110+
// Default (termination monitoring disabled)
111+
try launchAndInstall()
112+
try terminate()
113113

114-
XCTAssertFalse(try hasCrashReport())
114+
XCTAssertFalse(try hasCrashReport())
115115

116-
// With termination monitoring enabled
117-
try launchAndInstall { config in
118-
config.isSigTermMonitoringEnabled = true
119-
}
120-
try terminate()
116+
// With termination monitoring enabled
117+
try launchAndInstall { config in
118+
config.isSigTermMonitoringEnabled = true
119+
}
120+
try terminate()
121121

122-
let rawReport = try readPartialCrashReport()
123-
try rawReport.validate()
124-
XCTAssertEqual(rawReport.crash?.error?.signal?.name, "SIGTERM")
122+
let rawReport = try readPartialCrashReport()
123+
try rawReport.validate()
124+
XCTAssertEqual(rawReport.crash?.error?.signal?.name, "SIGTERM")
125125

126-
let appleReport = try launchAndReportCrash()
127-
print(appleReport)
128-
XCTAssertTrue(appleReport.contains("SIGTERM"))
129-
}
130-
131-
func testTerminationWithMemoryIntrospection() throws {
132-
try launchAndInstall { config in
133-
config.isSigTermMonitoringEnabled = true
134-
config.isMemoryIntrospectionEnabled = true
126+
let appleReport = try launchAndReportCrash()
127+
print(appleReport)
128+
XCTAssertTrue(appleReport.contains("SIGTERM"))
135129
}
136-
try terminate()
137130

138-
let rawReport = try readPartialCrashReport()
139-
try rawReport.validate()
140-
XCTAssertNotNil(rawReport.crash?.threads?.first?.notable_addresses)
141-
XCTAssertTrue(rawReport.crash?.threads?.first?.notable_addresses?.keys.contains { $0.hasPrefix("stack@0x") } ?? false)
131+
func testTerminationWithMemoryIntrospection() throws {
132+
try launchAndInstall { config in
133+
config.isSigTermMonitoringEnabled = true
134+
config.isMemoryIntrospectionEnabled = true
135+
}
136+
try terminate()
137+
138+
let rawReport = try readPartialCrashReport()
139+
try rawReport.validate()
140+
XCTAssertNotNil(rawReport.crash?.threads?.first?.notable_addresses)
141+
XCTAssertTrue(
142+
rawReport.crash?.threads?.first?.notable_addresses?.keys.contains { $0.hasPrefix("stack@0x") } ?? false)
143+
}
142144
}
143-
}
144145

145146
#endif
146147

@@ -156,9 +157,11 @@ final class OtherTests: IntegrationTestBase {
156157
})
157158
XCTAssertNotNil(expectedFrame)
158159

159-
let threadStates = ["TH_STATE_RUNNING", "TH_STATE_STOPPED", "TH_STATE_WAITING",
160-
"TH_STATE_UNINTERRUPTIBLE", "TH_STATE_HALTED"]
161-
for thread in rawReport.crash?.threads ?? [] {
160+
let threadStates = [
161+
"TH_STATE_RUNNING", "TH_STATE_STOPPED", "TH_STATE_WAITING",
162+
"TH_STATE_UNINTERRUPTIBLE", "TH_STATE_HALTED",
163+
]
164+
for thread in rawReport.crash?.threads ?? [] {
162165
XCTAssertTrue(threadStates.contains(thread.state))
163166
}
164167

Sources/KSCrashDiscSpaceMonitor/KSCrashMonitor_DiscSpace.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ static uint64_t getStorageSize(void)
4747

4848
static uint64_t getFreeStorageSize(void)
4949
{
50-
NSNumber *freeStorageSize = [[[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil]
51-
objectForKey:NSFileSystemFreeSize];
50+
NSNumber *freeStorageSize =
51+
[[[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory()
52+
error:nil] objectForKey:NSFileSystemFreeSize];
5253
return freeStorageSize.unsignedLongLongValue;
5354
}
5455

Sources/KSCrashFilters/KSCrashReportFilterAlert.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ - (void)startWithTitle:(NSString *)title
5656
yesAnswer:(NSString *)yesAnswer
5757
noAnswer:(NSString *)noAnswer
5858
reports:(NSArray<id<KSCrashReport>> *)reports
59-
onCompletion:(KSCrashReportFilterCompletion)onCompletion NS_EXTENSION_UNAVAILABLE_IOS("Alert Filter requires NSApplication, which is unavailable on watchOS extensions");
59+
onCompletion:(KSCrashReportFilterCompletion)onCompletion
60+
NS_EXTENSION_UNAVAILABLE_IOS("Alert Filter requires NSApplication, which is unavailable on watchOS extensions");
6061

6162
@end
6263

Sources/KSCrashInstallations/KSCrashInstallation.m

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
#import "KSCrashReportFilterBasic.h"
3535
#import "KSCrashReportFilterDemangle.h"
3636
#import "KSCrashReportFilterDoctor.h"
37+
#import "KSDynamicLinker.h"
3738
#import "KSJSONCodecObjC.h"
3839
#import "KSLogger.h"
3940
#import "KSNSErrorHelper.h"
40-
#import "KSDynamicLinker.h"
4141

4242
/** Max number of properties that can be defined for writing to the report */
4343
#define kMaxProperties 500
@@ -240,21 +240,22 @@ - (BOOL)installWithConfiguration:(KSCrashConfiguration *)configuration error:(NS
240240
g_crashHandlerData = self.crashHandlerData;
241241
ksdl_binary_images_initialize();
242242

243-
configuration.crashNotifyCallback = ^(const struct KSCrashReportWriter *_Nonnull writer, bool requiresAsyncSafety) {
244-
CrashHandlerData *crashHandlerData = g_crashHandlerData;
245-
if (crashHandlerData == NULL) {
246-
return;
247-
}
248-
for (int i = 0; i < crashHandlerData->reportFieldsCount; i++) {
249-
ReportField *field = crashHandlerData->reportFields[i];
250-
if (field->key != NULL && field->value != NULL) {
251-
writer->addJSONElement(writer, field->key, field->value, true);
243+
configuration.crashNotifyCallback =
244+
^(const struct KSCrashReportWriter *_Nonnull writer, bool requiresAsyncSafety) {
245+
CrashHandlerData *crashHandlerData = g_crashHandlerData;
246+
if (crashHandlerData == NULL) {
247+
return;
248+
}
249+
for (int i = 0; i < crashHandlerData->reportFieldsCount; i++) {
250+
ReportField *field = crashHandlerData->reportFields[i];
251+
if (field->key != NULL && field->value != NULL) {
252+
writer->addJSONElement(writer, field->key, field->value, true);
253+
}
254+
}
255+
if (crashHandlerData->userCrashCallback != NULL) {
256+
crashHandlerData->userCrashCallback(writer, requiresAsyncSafety);
252257
}
253-
}
254-
if (crashHandlerData->userCrashCallback != NULL) {
255-
crashHandlerData->userCrashCallback(writer, requiresAsyncSafety);
256-
}
257-
};
258+
};
258259

259260
NSError *installError = nil;
260261
BOOL success = [handler installWithConfiguration:configuration error:&installError];

Sources/KSCrashInstallations/include/KSCrashInstallation.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ NS_SWIFT_NAME(CrashInstallation)
116116
- (void)addConditionalAlertWithTitle:(NSString *)title
117117
message:(nullable NSString *)message
118118
yesAnswer:(NSString *)yesAnswer
119-
noAnswer:(nullable NSString *)noAnswer NS_EXTENSION_UNAVAILABLE_IOS("Alert Filter requires NSApplication, which is unavailable on watchOS extensions");
119+
noAnswer:(nullable NSString *)noAnswer
120+
NS_EXTENSION_UNAVAILABLE_IOS("Alert Filter requires NSApplication, which is unavailable on watchOS extensions");
120121

121122
/** Show an alert before sending any reports. Reports will be unconditionally sent
122123
* when the alert is dismissed.
@@ -127,7 +128,8 @@ NS_SWIFT_NAME(CrashInstallation)
127128
*/
128129
- (void)addUnconditionalAlertWithTitle:(NSString *)title
129130
message:(nullable NSString *)message
130-
dismissButtonText:(NSString *)dismissButtonText NS_EXTENSION_UNAVAILABLE_IOS("Alert Filter requires NSApplication, which is unavailable on watchOS extensions");
131+
dismissButtonText:(NSString *)dismissButtonText
132+
NS_EXTENSION_UNAVAILABLE_IOS("Alert Filter requires NSApplication, which is unavailable on watchOS extensions");
131133

132134
/** Validates properties of installation.
133135
*

Sources/KSCrashRecording/KSCrash.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
#import "KSCrashMonitor_System.h"
3737
#import "KSCrashReport.h"
3838
#import "KSCrashReportFields.h"
39+
#import "KSDynamicLinker.h"
3940
#import "KSJSONCodecObjC.h"
4041
#import "KSNSErrorHelper.h"
4142
#import "KSSystemCapabilities.h"
42-
#import "KSDynamicLinker.h"
4343

4444
// #define KSLogger_LocalLevel TRACE
4545
#import "KSLogger.h"
@@ -52,7 +52,6 @@
5252
#import <AppKit/AppKit.h>
5353
#endif
5454

55-
5655
// ============================================================================
5756
#pragma mark - Globals -
5857
// ============================================================================
@@ -229,7 +228,7 @@ - (NSDictionary *)systemInfo
229228
COPY_PRIMITIVE(parentProcessID);
230229
COPY_STRING(deviceAppHash);
231230
COPY_STRING(buildType);
232-
COPY_PRIMITIVE(storageSize); // this field is populated in an optional monitor
231+
COPY_PRIMITIVE(storageSize); // this field is populated in an optional monitor
233232
COPY_PRIMITIVE(freeStorageSize); // this field is populated in an optional monitor
234233
COPY_PRIMITIVE(memorySize);
235234
COPY_PRIMITIVE(freeMemory);

Sources/KSCrashRecording/KSCrashReportC.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
#include "KSStackCursor_Backtrace.h"
5353
#include "KSStackCursor_MachineContext.h"
5454
#include "KSString.h"
55+
#include "KSStringConversion.h"
5556
#include "KSSystemCapabilities.h"
5657
#include "KSThread.h"
5758
#include "KSThreadCache.h"
58-
#include "KSStringConversion.h"
5959

6060
// #define KSLogger_LocalLevel TRACE
6161
#include <errno.h>
@@ -1058,7 +1058,7 @@ static void writeThread(const KSCrashReportWriter *const writer, const char *con
10581058

10591059
KSStackCursor stackCursor;
10601060
bool hasBacktrace = getStackCursor(crash, machineContext, &stackCursor);
1061-
const char* state = ksthread_state_name(threadState);
1061+
const char *state = ksthread_state_name(threadState);
10621062

10631063
writer->beginObject(writer, key);
10641064
{
@@ -1076,8 +1076,9 @@ static void writeThread(const KSCrashReportWriter *const writer, const char *con
10761076
// pthread_getname_np() acquires no locks if passed pthread_self() as
10771077
// of libpthread-330.201.1 (macOS 10.14 / iOS 12)
10781078
bool isSelfThread = thread == ksthread_self();
1079-
char threadName[64] = {0};
1080-
if (isSelfThread && !pthread_getname_np(pthread_self(), threadName, sizeof(threadName)) && threadName[0] != 0) {
1079+
char threadName[64] = { 0 };
1080+
if (isSelfThread && !pthread_getname_np(pthread_self(), threadName, sizeof(threadName)) &&
1081+
threadName[0] != 0) {
10811082
writer->addStringElement(writer, KSCrashField_Name, threadName);
10821083
}
10831084
}
@@ -1235,7 +1236,7 @@ static void writeError(const KSCrashReportWriter *const writer, const char *cons
12351236
#if KSCRASH_HOST_APPLE
12361237
writer->beginObject(writer, KSCrashField_Mach);
12371238
{
1238-
char buffer[20] = {0};
1239+
char buffer[20] = { 0 };
12391240
const char *machExceptionName = ksmach_exceptionName(crash->mach.type);
12401241
const char *machCodeName = crash->mach.code == 0 ? NULL : ksmach_kernelReturnCodeName(crash->mach.code);
12411242
writer->addUIntegerElement(writer, KSCrashField_Exception, (unsigned)crash->mach.type);
@@ -1722,7 +1723,8 @@ void kscrashreport_setUserSectionWriteCallback(const KSReportWriteCallback userS
17221723
g_userSectionWriteCallback = userSectionWriteCallback;
17231724
}
17241725

1725-
void kscrashreport_setThreadTracingEnabled(bool threadTracingEnabled) {
1726+
void kscrashreport_setThreadTracingEnabled(bool threadTracingEnabled)
1727+
{
17261728
#if KSCRASH_HAS_THREADS_API
17271729
g_shouldRecordThreads = threadTracingEnabled;
17281730
#else

Sources/KSCrashRecording/KSCrashReportC.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ void kscrashreport_setUserSectionWriteCallback(const KSReportWriteCallback userS
8181

8282
/** Decide if all threads will be written to a report.
8383
*
84-
* @param threadTracingEnabled true if all threads should be recorded, if false, only the offending thread will be recorded.
84+
* @param threadTracingEnabled true if all threads should be recorded, if false, only the offending thread will be
85+
* recorded.
8586
*/
8687
void kscrashreport_setThreadTracingEnabled(bool threadTracingEnabled);
8788

0 commit comments

Comments
 (0)