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

feat: iOS Support #436

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ jobs:
- uses: actions/checkout@v2
- run: make style

build-ios:
name: Xcode Build for iOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
- run: |
cmake -B sentry-native-xcode -GXcode -DCMAKE_SYSTEM_NAME=iOS
xcodebuild build -project sentry-native-xcode/Sentry-Native.xcodeproj

test:
strategy:
fail-fast: false
Expand Down
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ endif()

if(WIN32)
set(SENTRY_DEFAULT_TRANSPORT "winhttp")
elseif(APPLE OR LINUX)
elseif((APPLE AND NOT IOS) OR LINUX) # TODO: iOS needs its own transport
set(SENTRY_DEFAULT_TRANSPORT "curl")
else()
set(SENTRY_DEFAULT_TRANSPORT "none")
Expand Down Expand Up @@ -399,11 +399,15 @@ if(SENTRY_BACKEND_CRASHPAD)
$<BUILD_INTERFACE:crashpad::client>
$<INSTALL_INTERFACE:sentry_crashpad::client>
)
install(EXPORT crashpad_export NAMESPACE sentry_crashpad:: FILE sentry_crashpad-targets.cmake
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
)
if(NOT IOS) # TODO: figure out whats going on here
install(EXPORT crashpad_export NAMESPACE sentry_crashpad:: FILE sentry_crashpad-targets.cmake
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
)
endif()
endif()
if(NOT IOS)
add_dependencies(sentry crashpad::handler)
endif()
add_dependencies(sentry crashpad::handler)
elseif(SENTRY_BACKEND_BREAKPAD)
option(SENTRY_BREAKPAD_SYSTEM "Use system breakpad" OFF)
if(SENTRY_BREAKPAD_SYSTEM)
Expand Down
2 changes: 1 addition & 1 deletion external/crashpad
Submodule crashpad updated 37 files
+0 −13 BUILD.gn
+2 −2 DEPS
+0 −1 build/ios/setup_ios_gn.py
+0 −2 minidump/BUILD.gn
+18 −13 minidump/minidump_exception_writer_test.cc
+32 −33 minidump/minidump_handle_writer_test.cc
+20 −11 minidump/minidump_memory_info_writer_test.cc
+17 −10 minidump/minidump_misc_info_writer_test.cc
+56 −39 minidump/minidump_module_writer_test.cc
+15 −8 minidump/minidump_system_info_writer_test.cc
+28 −20 minidump/minidump_thread_writer_test.cc
+13 −5 minidump/test/minidump_memory_writer_test_util.cc
+2 −2 snapshot/BUILD.gn
+1 −1 snapshot/linux/debug_rendezvous.h
+39 −5 snapshot/linux/debug_rendezvous_test.cc
+11 −212 snapshot/linux/process_reader_linux_test.cc
+262 −0 snapshot/linux/test_modules.cc
+37 −0 snapshot/linux/test_modules.h
+1 −1 snapshot/minidump/process_snapshot_minidump.cc
+2 −0 snapshot/snapshot_test.gyp
+3 −0 test/fuchsia_crashpad_tests.cmx
+2 −2 third_party/edo/BUILD.gn
+0 −1 third_party/googletest/BUILD.gn
+1 −1 third_party/lss/README.crashpad
+1 −1 third_party/mini_chromium/mini_chromium
+1 −2 util/BUILD.gn
+6 −1 util/CMakeLists.txt
+8 −6 util/file/file_io.cc
+2 −1 util/linux/initial_signal_dispositions.cc
+57 −53 util/linux/ptrace_broker.cc
+3 −10 util/linux/ptrace_broker.h
+29 −14 util/linux/scoped_ptrace_attach.cc
+18 −0 util/linux/scoped_ptrace_attach.h
+1 −1 util/net/http_transport_socket.cc
+58 −13 util/posix/scoped_mmap.cc
+5 −1 util/posix/scoped_mmap.h
+1 −1 util/stdlib/aligned_allocator.h
7 changes: 6 additions & 1 deletion include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ extern "C" {
#ifdef _WIN32
# define SENTRY_PLATFORM_WINDOWS
#elif defined(__APPLE__)
# define SENTRY_PLATFORM_MACOS
# include <TargetConditionals.h>
# if defined(TARGET_OS_OSX) && TARGET_OS_OSX
# define SENTRY_PLATFORM_MACOS
# elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
# define SENTRY_PLATFORM_IOS
# endif
# define SENTRY_PLATFORM_DARWIN
# define SENTRY_PLATFORM_UNIX
#elif defined(__ANDROID__)
Expand Down
12 changes: 9 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ endif()
# backends
if(SENTRY_BACKEND_CRASHPAD)
target_compile_definitions(sentry PRIVATE SENTRY_BACKEND_CRASHPAD)
sentry_target_sources_cwd(sentry
backends/sentry_backend_crashpad.cpp
)
if(IOS)
sentry_target_sources_cwd(sentry
backends/sentry_backend_crashpad_ios.cpp
)
else()
sentry_target_sources_cwd(sentry
backends/sentry_backend_crashpad.cpp
)
endif()
elseif(SENTRY_BACKEND_BREAKPAD)
target_compile_definitions(sentry PRIVATE SENTRY_BACKEND_BREAKPAD)
sentry_target_sources_cwd(sentry
Expand Down
49 changes: 49 additions & 0 deletions src/backends/sentry_backend_crashpad_ios.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
extern "C" {
#include "sentry_boot.h"

#include "sentry_alloc.h"
#include "sentry_backend.h"
#include "sentry_core.h"
}

#include <map>
#include <vector>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#pragma GCC diagnostic ignored "-Wfour-char-constants"

#include "client/crashpad_client.h"

#pragma GCC diagnostic pop

extern "C" {

static int
sentry__crashpad_backend_startup(
sentry_backend_t *UNUSED(backend), const sentry_options_t *UNUSED(options))
{
SENTRY_TRACE("starting crashpad inprocess handler");

crashpad::CrashpadClient client;
client.StartCrashpadInProcessHandler();

return 0;
}

sentry_backend_t *
sentry__backend_new(void)
{
sentry_backend_t *backend = SENTRY_MAKE(sentry_backend_t);
if (!backend) {
return NULL;
}
memset(backend, 0, sizeof(sentry_backend_t));

backend->startup_func = sentry__crashpad_backend_startup;
backend->can_capture_after_shutdown = true;

return backend;
}
}
4 changes: 2 additions & 2 deletions src/path/sentry_path_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ sentry__path_filename_matches(const sentry_path_t *path, const char *filename)
bool
sentry__path_ends_with(const sentry_path_t *path, const char *suffix)
{
int pathlen = strlen(path->path);
int suffixlen = strlen(suffix);
size_t pathlen = strlen(path->path);
size_t suffixlen = strlen(suffix);
if (suffixlen > pathlen) {
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ sentry_user_consent_get(void)
{
sentry_user_consent_t rv = SENTRY_USER_CONSENT_UNKNOWN;
SENTRY_WITH_OPTIONS (options) {
rv = sentry__atomic_fetch((long *)&options->user_consent);
rv = (sentry_user_consent_t)sentry__atomic_fetch(
(long *)&options->user_consent);
}
return rv;
}
Expand Down
8 changes: 4 additions & 4 deletions src/sentry_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ sentry__url_parse(sentry_url_t *url_out, const char *url)
SKIP_WHILE_NOT(tmp, '/');
aux_buf = sentry__string_clonen(ptr, tmp - ptr);
char *end;
url_out->port = strtol(aux_buf, &end, 10);
url_out->port = (int)strtol(aux_buf, &end, 10);
if (end != aux_buf + strlen(aux_buf)) {
goto error;
}
Expand Down Expand Up @@ -434,7 +434,7 @@ sentry__iso8601_to_msec(const char *iso)
// forwards to `stdtod`, but it does not define `vsnprintf_l` sadly. This means
// if Android ever adds locale support in NDK we will have to revisit this code
// to ensure the C locale is also used there.
#ifndef SENTRY_PLATFORM_ANDROID
#if !defined(SENTRY_PLATFORM_ANDROID) && !defined(SENTRY_PLATFORM_IOS)
static sentry__locale_t
c_locale()
{
Expand All @@ -457,7 +457,7 @@ sentry__strtod_c(const char *ptr, char **endptr)
{
#ifdef SENTRY_PLATFORM_WINDOWS
return _strtod_l(ptr, endptr, c_locale());
#elif defined(SENTRY_PLATFORM_ANDROID)
#elif defined(SENTRY_PLATFORM_ANDROID) || defined(SENTRY_PLATFORM_IOS)
return strtod(ptr, endptr);
#else
return strtod_l(ptr, endptr, c_locale());
Expand All @@ -473,7 +473,7 @@ sentry__snprintf_c(char *buf, size_t buf_size, const char *fmt, ...)
int rv;
#ifdef SENTRY_PLATFORM_WINDOWS
rv = _vsnprintf_l(buf, buf_size, fmt, c_locale(), args);
#elif defined(SENTRY_PLATFORM_ANDROID)
#elif defined(SENTRY_PLATFORM_ANDROID) || defined(SENTRY_PLATFORM_IOS)
rv = vsnprintf(buf, buf_size, fmt, args);
#elif defined(SENTRY_PLATFORM_MACOS)
rv = vsnprintf_l(buf, buf_size, c_locale(), fmt, args);
Expand Down
4 changes: 2 additions & 2 deletions src/unwinder/sentry_unwinder_libbacktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ sentry__unwind_stack_libbacktrace(
if (addr) {
#if defined(SENTRY_PLATFORM_MACOS) && __has_builtin(__builtin_available)
if (__builtin_available(macOS 10.14, *))
return backtrace_from_fp(addr, ptrs, max_frames);
return (size_t)backtrace_from_fp(addr, ptrs, (int)max_frames);
#endif
return 0;
} else if (uctx) {
return 0;
} else {
return backtrace(ptrs, max_frames);
return (size_t)backtrace(ptrs, (int)max_frames);
}
}