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

Fix missing line numbers in CaptureMessage stacktraces in IL2CPP builds #1567

Draft
wants to merge 7 commits into
base: main
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
2 changes: 1 addition & 1 deletion modules/sentry-cocoa
Submodule sentry-cocoa updated 74 files
+12 −0 .github/file-filters.yml
+4 −6 .github/workflows/benchmarking.yml
+6 −4 .github/workflows/build.yml
+51 −0 .github/workflows/changes-in-high-risk-code.yml
+0 −9 .github/workflows/lint.yml
+3 −5 .github/workflows/saucelabs-UI-tests.yml
+6 −3 .github/workflows/test.yml
+1 −9 .pre-commit-config.yaml
+29 −1 CHANGELOG.md
+33 −32 Gemfile.lock
+2 −6 Makefile
+4 −14 Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj
+25 −3 Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme
+75 −16 Samples/iOS-Swift/iOS-Swift/AppDelegate.swift
+1 −0 Samples/iOS-Swift/iOS-SwiftUITests/BaseUITest.swift
+0 −6 Samples/iOS-Swift/iOS-SwiftUITests/ClearTestState.swift
+47 −0 Samples/tvOS-Swift/tvOS-Swift.xcodeproj/project.pbxproj
+2 −2 Sentry.podspec
+6 −2 Sentry.xcodeproj/project.pbxproj
+1 −1 SentryPrivate.podspec
+2 −2 SentrySwiftUI.podspec
+0 −3 SentryTestUtils/ClearTestState.swift
+1 −2 SentryTestUtils/SentryProfilerMocks.h
+1 −6 SentryTestUtils/SentryProfilerMocks.mm
+0 −2 SentryTestUtils/SentryProfilerMocksSwiftCompatible.h
+1 −4 SentryTestUtils/SentryProfilerMocksSwiftCompatible.mm
+1 −0 Sources/Configuration/DeploymentTargets.xcconfig
+0 −19 Sources/Configuration/SDK.xcconfig
+1 −1 Sources/Configuration/Sentry.xcconfig
+1 −1 Sources/Configuration/SentryPrivate.xcconfig
+24 −23 Sources/Sentry/Profiling/SentryProfilerState.mm
+1 −32 Sources/Sentry/SentryBacktrace.cpp
+0 −5 Sources/Sentry/SentryBaggage.m
+7 −2 Sources/Sentry/SentryDependencyContainer.m
+47 −20 Sources/Sentry/SentryFileManager.m
+18 −4 Sources/Sentry/SentryFramesTracker.m
+1 −1 Sources/Sentry/SentryMeta.m
+13 −7 Sources/Sentry/SentryNetworkTracker.m
+3 −1 Sources/Sentry/SentryScope.m
+14 −4 Sources/Sentry/SentrySystemEventBreadcrumbs.m
+0 −28 Sources/Sentry/SentryThreadHandle.cpp
+0 −22 Sources/Sentry/SentryThreadMetadataCache.cpp
+6 −0 Sources/Sentry/SentryTracer.m
+0 −1 Sources/Sentry/include/SentryBacktrace.hpp
+0 −1 Sources/Sentry/include/SentryBaggage.h
+6 −3 Sources/Sentry/include/SentryFileManager.h
+2 −0 Sources/Sentry/include/SentryFramesTracker.h
+0 −2 Sources/Sentry/include/SentryProfilerState.h
+0 −11 Sources/Sentry/include/SentryThreadHandle.hpp
+0 −23 Sources/Sentry/include/SentryThreadMetadataCache.hpp
+2 −0 Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_System.m
+6 −1 Sources/SentryCrash/Recording/SentryCrashSystemCapabilities.h
+4 −4 Sources/SentryCrash/Recording/Tools/SentryCrashMachineContext.h
+4 −5 Sources/SentryCrash/Recording/Tools/SentryCrashStackCursor.h
+3 −3 Sources/SentryCrash/Recording/Tools/SentryCrashThread.h
+1 −1 Tests/HybridSDKTest/HybridPod.podspec
+14 −30 Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift
+13 −17 Tests/SentryProfilerTests/SentryProfilerTests.mm
+0 −20 Tests/SentryProfilerTests/SentryThreadMetadataCacheTests.mm
+15 −0 Tests/SentryTests/Helper/SentryDependencyContainerTests.swift
+80 −5 Tests/SentryTests/Helper/SentryFileManagerTests.swift
+11 −1 Tests/SentryTests/Integrations/Breadcrumbs/SentrySystemEventBreadcrumbsTest.swift
+1 −1 Tests/SentryTests/Integrations/Performance/AppStartTracking/SentryAppStartTrackerTests.swift
+55 −5 Tests/SentryTests/Integrations/Performance/FramesTracking/SentryFramesTrackerTests.swift
+1 −1 Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerIntegrationTests.swift
+31 −4 Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift
+1 −1 Tests/SentryTests/Integrations/Performance/UIViewController/SentryTimeToDisplayTrackerTest.swift
+21 −28 Tests/SentryTests/SentryCrash/SentryCrashInstallationReporterTests.swift
+62 −0 Tests/SentryTests/SentryScopeSwiftTests.swift
+1 −7 Tests/SentryTests/Transaction/SentryBaggageTests.swift
+1 −1 Tests/SentryTests/Transaction/SentrySpanTests.swift
+26 −0 Tests/SentryTests/Transaction/SentryTracerTests.swift
+0 −25 scripts/no-changes-in-high-risk-files.sh
+0 −14 scripts/set-device-tests-environment.patch
2 changes: 1 addition & 1 deletion modules/sentry-java
Submodule sentry-java updated 181 files
68 changes: 68 additions & 0 deletions package-dev/Runtime/SentryInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System;
using Sentry.Extensibility;
using AOT;
#if UNITY_2020_3_OR_NEWER
using System.Buffers;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -142,6 +143,7 @@ private Il2CppMethods _il2CppMethods
= new Il2CppMethods(
Il2CppGcHandleGetTargetShim,
Il2CppNativeStackTraceShim,
Il2CppNativeStackTraceCurrentThreadShim,
il2cpp_free);

#pragma warning disable 8632
Expand Down Expand Up @@ -210,6 +212,72 @@ void SwapHexByte(IntPtr buffer, Int32 offset1, Int32 offset2)
[DllImport("__Internal")]
private static extern void il2cpp_free(IntPtr ptr);

[StructLayout(LayoutKind.Sequential)]
private struct Il2CppStackFrameInfo
{
public IntPtr method;
public IntPtr raw_ip;

public int sourceCodeLineNumber;
public int ilOffset;

public IntPtr filePath;
}

private static void Il2CppNativeStackTraceCurrentThreadShim(out IntPtr addresses, out int numFrames, out string? imageUUID, out string? imageName)
{
// Currently there is no obvious way to obtain image UUID and name
var uuidBuffer = IntPtr.Zero;
var imageNameBuffer = IntPtr.Zero;

numFrames = il2cpp_current_thread_get_stack_depth();

var frames = new IntPtr[numFrames];

for(int i = 0; i < numFrames; ++i)
{
IntPtr farameInfoPtr = IntPtr.Zero;
try
{
farameInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf<Il2CppStackFrameInfo>());

// Is it reliable to query current stack trace here?
var res = il2cpp_current_thread_get_frame_at(i, farameInfoPtr);
if(res)
{
Il2CppStackFrameInfo frameInfo = Marshal.PtrToStructure<Il2CppStackFrameInfo>(farameInfoPtr);
frames[i] = frameInfo.raw_ip;
}
}
finally
{
Marshal.FreeHGlobal(farameInfoPtr);
}
}

int size = Marshal.SizeOf(typeof(IntPtr)) * numFrames;
addresses = Marshal.AllocHGlobal(size);

Marshal.Copy(frames, 0, addresses, numFrames);

try
{
imageUUID = SanitizeDebugId(uuidBuffer);
imageName = (imageNameBuffer == IntPtr.Zero) ? null : Marshal.PtrToStringAnsi(imageNameBuffer);
}
finally
{
il2cpp_free(uuidBuffer);
il2cpp_free(imageNameBuffer);
}
}

[DllImport("__Internal")]
private static extern int il2cpp_current_thread_get_stack_depth();

[DllImport("__Internal")]
private static extern bool il2cpp_current_thread_get_frame_at(int offset, IntPtr frame);

#if UNITY_2021_3_OR_NEWER
private static void Il2CppNativeStackTraceShim(IntPtr exc, out IntPtr addresses, out int numFrames, out string? imageUUID, out string? imageName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "il2cpp-api.h"
#include "il2cpp-config.h"
#include "os/Image.h"
#include <exception>
#include <iostream>
#include <string>
Expand Down
9 changes: 9 additions & 0 deletions src/Sentry.Unity/ISentryUnityInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ public class Il2CppMethods
public Il2CppMethods(
Il2CppGcHandleGetTarget il2CppGcHandleGetTarget,
Il2CppNativeStackTrace il2CppNativeStackTrace,
Il2CppNativeStackTraceCurrentThread il2CppNativeStackTraceCurrentThread,
Il2CppFree il2CppFree)
{
Il2CppGcHandleGetTarget = il2CppGcHandleGetTarget;
Il2CppNativeStackTrace = il2CppNativeStackTrace;
Il2CppNativeStackTraceCurrentThread = il2CppNativeStackTraceCurrentThread;
Il2CppFree = il2CppFree;
}

public Il2CppGcHandleGetTarget Il2CppGcHandleGetTarget { get; }
public Il2CppNativeStackTrace Il2CppNativeStackTrace { get; }
public Il2CppNativeStackTraceCurrentThread Il2CppNativeStackTraceCurrentThread { get; }
public Il2CppFree Il2CppFree { get; }
}

Expand All @@ -38,5 +41,11 @@ public delegate void Il2CppNativeStackTrace(
out int numFrames,
out string? imageUUID,
out string? imageName);

public delegate void Il2CppNativeStackTraceCurrentThread(
out IntPtr addresses,
out int numFrames,
out string? imageUUID,
out string? imageName);
public delegate void Il2CppFree(IntPtr ptr);
}
Loading