Skip to content

Commit

Permalink
Merge branch 'main' into armcknight/fix/module-names
Browse files Browse the repository at this point in the history
  • Loading branch information
brustolin authored Jul 9, 2024
2 parents a6f125f + d26797f commit a25a487
Show file tree
Hide file tree
Showing 106 changed files with 1,197 additions and 1,852 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
Carthage/Sentry.xcframework.zip
Carthage/Sentry-Dynamic.xcframework.zip
Carthage/SentrySwiftUI.xcframework.zip
Carthage/Sentry-WihoutUIKitOrAppKit.zip
Carthage/Sentry-WithoutUIKitOrAppKit.zip
overwrite: true

job_release:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- UIKitless configurations now produce a module with a different name (#4140)
- Sentry Replay Serialized Breadcrumbs include level name ([#4141](https://github.com/getsentry/sentry-cocoa/pull/4141))

## 8.30.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down Expand Up @@ -95,7 +95,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "--io.sentry.enableContinuousProfiling"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--io.sentry.wipe-data"
Expand Down Expand Up @@ -155,7 +155,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "--disable-ui-tracing"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<EnvironmentVariables>
Expand Down
44 changes: 12 additions & 32 deletions Sentry.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Sentry.xcodeproj/xcshareddata/xcschemes/Sentry.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
<Test
Identifier = "SentrySubClassFinderTests/testActOnSubclassesOfViewController()">
</Test>
<Test
Identifier = "SentryThreadInspectorTests/testGetCurrentThreadsWithStacktrace_WithSymbolication()">
</Test>
<Test
Identifier = "SentryThreadInspectorTests/testStacktraceHasFrames_forEveryThread()">
</Test>
Expand Down
10 changes: 10 additions & 0 deletions SentryTestUtils/ArrayAccesses.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Foundation

public extension Array {
func element(at index: Int) -> Self.Element? {
guard count >= index else {
return nil
}
return self[index]
}
}
8 changes: 8 additions & 0 deletions Sources/Sentry/Public/SentryOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ NS_SWIFT_NAME(Options)
* @c SentryWatchdogTerminationTrackingIntegration would falsely report every crash as watchdog
* termination.
* @note Default value is @c YES .
* @note Crash reporting is automatically disabled if a debugger is attached.
*/
@property (nonatomic, assign) BOOL enableCrashHandler;

Expand Down Expand Up @@ -143,6 +144,7 @@ NS_SWIFT_NAME(Options)
* terminates with a crash before the SDK can send the crash event. You can look into @c beforeSend
* if you prefer a callback for every event.
* @warning It is not guaranteed that this is called on the main thread.
* @note Crash reporting is automatically disabled if a debugger is attached.
*/
@property (nullable, nonatomic, copy) SentryOnCrashedLastRunCallback onCrashedLastRun;

Expand Down Expand Up @@ -451,6 +453,7 @@ NS_SWIFT_NAME(Options)
* to profile that launch.
* @see @c tracesSampler and @c profilesSampler for more information on how they work for this
* feature.
* @note Profiling is automatically disabled if a thread sanitizer is attached.
*/
@property (nonatomic, assign) BOOL enableAppLaunchProfiling;

Expand All @@ -473,6 +476,7 @@ NS_SWIFT_NAME(Options)
* callsites where you use the API or configure launch profiling. Continuous profiling is not
* automatically started for performance transactions as was the previous version of profiling.
* @warning The new continuous profiling mode is experimental and may still contain bugs.
* @note Profiling is automatically disabled if a thread sanitizer is attached.
*/
@property (nullable, nonatomic, strong) NSNumber *profilesSampleRate;

Expand All @@ -484,6 +488,7 @@ NS_SWIFT_NAME(Options)
* @note If @c enableAppLaunchProfiling is @c YES , this function will be called during SDK start
* with @c SentrySamplingContext.forNextAppLaunch set to @c YES, and the result will be persisted to
* disk for use on the next app launch.
* @note Profiling is automatically disabled if a thread sanitizer is attached.
*/
@property (nullable, nonatomic) SentryTracesSamplerCallback profilesSampler;

Expand All @@ -495,6 +500,7 @@ NS_SWIFT_NAME(Options)
* successfully start a continuous profile.
* @returns @c YES if either @c profilesSampleRate > @c 0 and \<= @c 1 , or @c profilesSampler is
* set, otherwise @c NO.
* @note Profiling is automatically disabled if a thread sanitizer is attached.
*/
@property (nonatomic, assign, readonly) BOOL isProfilingEnabled;

Expand All @@ -505,6 +511,7 @@ NS_SWIFT_NAME(Options)
* equivalent of setting @c profilesSampleRate to @c 1.0 If @c profilesSampleRate is set, it will
* take precedence over this setting.
* @note Default is @c NO.
* @note Profiling is automatically disabled if a thread sanitizer is attached.
*/
@property (nonatomic, assign) BOOL enableProfiling DEPRECATED_MSG_ATTRIBUTE(
"Use profilesSampleRate or profilesSampler instead. This property will be removed in a future "
Expand All @@ -522,6 +529,7 @@ NS_SWIFT_NAME(Options)
* When enabled, the SDK tracks when the application stops responding for a specific amount of
* time defined by the @c appHangsTimeoutInterval option.
* @note The default is @c YES
* @note ANR tracking is automatically disabled if a debugger is attached.
*/
@property (nonatomic, assign) BOOL enableAppHangTracking;

Expand Down
162 changes: 162 additions & 0 deletions Sources/Sentry/SentryAsyncSafeLog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Adapted from: https://github.com/kstenerud/KSCrash
//
// SentryAsyncSafeLog.c
//
// Created by Karl Stenerud on 11-06-25.
//
// Copyright (c) 2011 Karl Stenerud. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall remain in place
// in this source code.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#include "SentryAsyncSafeLog.h"
#include "SentryCrashDebug.h"
#include "SentryInternalCDefines.h"

#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

// Compiler hints for "if" statements
#define likely_if(x) if (__builtin_expect(x, 1))
#define unlikely_if(x) if (__builtin_expect(x, 0))

/** Write a formatted string to the log.
*
* @param fmt The format string, followed by its arguments.
*/
static void writeFmtToLog(const char *fmt, ...);

/** Write a formatted string to the log using a vararg list.
*
* @param fmt The format string.
*
* @param args The variable arguments.
*/
static void writeFmtArgsToLog(const char *fmt, va_list args);

static inline const char *
lastPathEntry(const char *const path)
{
const char *lastFile = strrchr(path, '/');
return lastFile == 0 ? path : lastFile + 1;
}

static inline void
writeFmtToLog(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
writeFmtArgsToLog(fmt, args);
va_end(args);
}

/** The file descriptor where log entries get written. */
static int g_fd = -1;

#if SENTRY_ASYNC_SAFE_LOG_ALSO_WRITE_TO_CONSOLE
static bool g_isDebugging;
static bool g_checkedIsDebugging;
#endif // SENTRY_ASYNC_SAFE_LOG_ALSO_WRITE_TO_CONSOLE

static void
writeToLog(const char *const str)
{
if (g_fd >= 0) {
int bytesToWrite = (int)strlen(str);
const char *pos = str;
while (bytesToWrite > 0) {
int bytesWritten = (int)write(g_fd, pos, (unsigned)bytesToWrite);
unlikely_if(bytesWritten == -1) { break; }
bytesToWrite -= bytesWritten;
pos += bytesWritten;
}
}
write(STDOUT_FILENO, str, strlen(str));

#if SENTRY_ASYNC_SAFE_LOG_ALSO_WRITE_TO_CONSOLE
// if we're debugging, also write the log statements to the console; we only check once for
// performance reasons; if the debugger is attached or detached while running, it will not
// change console-based logging
if (!g_checkedIsDebugging) {
g_checkedIsDebugging = true;
g_isDebugging = sentrycrashdebug_isBeingTraced();
}
if (g_isDebugging) {
fprintf(stdout, "%s", str);
fflush(stdout);
}
#endif // SENTRY_ASYNC_SAFE_LOG_ALSO_WRITE_TO_CONSOLE
}

static inline void
writeFmtArgsToLog(const char *fmt, va_list args)
{
unlikely_if(fmt == NULL) { writeToLog("(null)"); }
else
{
char buffer[SENTRY_ASYNC_SAFE_LOG_C_BUFFER_SIZE];
vsnprintf(buffer, sizeof(buffer), fmt, args);
writeToLog(buffer);
}
}

static inline void
setLogFD(int fd)
{
if (g_fd >= 0 && g_fd != STDOUT_FILENO && g_fd != STDERR_FILENO && g_fd != STDIN_FILENO) {
close(g_fd);
}
g_fd = fd;
}

int
sentry_asyncLogSetFileName(const char *filename, bool overwrite)
{
static int fd = -1;
if (filename != NULL) {
int openMask = O_WRONLY | O_CREAT;
if (overwrite) {
openMask |= O_TRUNC;
}
fd = open(filename, openMask, 0644);
unlikely_if(fd < 0) { return 1; }
if (filename != g_logFilename) {
strncpy(g_logFilename, filename, sizeof(g_logFilename));
}
}

setLogFD(fd);
return 0;
}

void
sentry_asyncLogC(const char *const level, const char *const file, const int line,
const char *const function, const char *const fmt, ...)
{
writeFmtToLog("%s: %s (%u): %s: ", level, lastPathEntry(file), line, function);
va_list args;
va_start(args, fmt);
writeFmtArgsToLog(fmt, args);
va_end(args);
writeToLog("\n");
}
Loading

0 comments on commit a25a487

Please sign in to comment.